[evolution-data-server/camel-gobject: 1/4] Replace Camel's homegrown type system with GObject.



commit 65aaee90f5415280ca2eccccb725153f5b57fa4d
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Sep 16 09:44:20 2009 -0400

    Replace Camel's homegrown type system with GObject.
    
    This is a major API and ABI break.
    
    Other global changes:
    
      - Remove <camel/camel-types.h>
      - Require top-level includes only.
      - Add a private <camel/camel-common.h> (TODO).

 addressbook/libebook/e-destination.c               |   10 +-
 camel/Makefile.am                                  |   55 +-
 camel/camel-address.c                              |  134 +-
 camel/camel-address.h                              |   85 +-
 camel/camel-arg.h                                  |    6 +-
 camel/camel-block-file.c                           |  233 +-
 camel/camel-block-file.h                           |   60 +-
 camel/camel-certdb.c                               |  184 +-
 camel/camel-certdb.h                               |   39 +-
 camel/camel-charset-map.h                          |   10 +-
 camel/camel-cipher-context.c                       |  458 ++-
 camel/camel-cipher-context.h                       |  127 +-
 camel/camel-data-cache.c                           |  190 +-
 camel/camel-data-cache.h                           |  111 +-
 camel/camel-data-wrapper.c                         |  200 +-
 camel/camel-data-wrapper.h                         |   48 +-
 camel/camel-db.c                                   |    3 +-
 camel/camel-db.h                                   |    9 +-
 camel/camel-debug.c                                |    5 +-
 camel/camel-debug.h                                |    6 +-
 camel/camel-digest-folder.c                        |  142 +-
 camel/camel-digest-folder.h                        |   40 +-
 camel/camel-digest-store.c                         |   62 +-
 camel/camel-digest-store.h                         |   37 +-
 camel/camel-digest-summary.c                       |   60 +-
 camel/camel-digest-summary.h                       |   39 +-
 camel/camel-disco-diary.c                          |   71 +-
 camel/camel-disco-diary.h                          |   45 +-
 camel/camel-disco-folder.c                         |  135 +-
 camel/camel-disco-folder.h                         |   40 +-
 camel/camel-disco-store.c                          |   99 +-
 camel/camel-disco-store.h                          |   45 +-
 camel/camel-exception.c                            |    1 -
 camel/camel-exception.h                            |   10 +-
 camel/camel-file-utils.c                           |    2 -
 camel/camel-file-utils.h                           |    6 +-
 camel/camel-filter-driver.c                        |  298 +-
 camel/camel-filter-driver.h                        |   45 +-
 camel/camel-filter-search.c                        |   12 +-
 camel/camel-filter-search.h                        |   11 +-
 camel/camel-folder-search.c                        |  254 +-
 camel/camel-folder-search.h                        |   39 +-
 camel/camel-folder-summary.c                       | 1805 ++++++------
 camel/camel-folder-summary.h                       |   47 +-
 camel/camel-folder-thread.c                        |    6 +-
 camel/camel-folder-thread.h                        |   10 +-
 camel/camel-folder.c                               | 1300 +++++----
 camel/camel-folder.h                               |   58 +-
 camel/camel-gpg-context.c                          |  366 ++-
 camel/camel-gpg-context.h                          |   53 +-
 camel/camel-html-parser.c                          |   86 +-
 camel/camel-html-parser.h                          |   39 +-
 camel/camel-http-stream.c                          |  158 +-
 camel/camel-http-stream.h                          |   37 +-
 camel/camel-i18n.h                                 |   10 +-
 camel/camel-iconv.c                                |    8 +-
 camel/camel-iconv.h                                |   10 +-
 camel/camel-index-control.c                        |   36 +-
 camel/camel-index.c                                |  367 ++-
 camel/camel-index.h                                |  103 +-
 camel/camel-internet-address.c                     |  115 +-
 camel/camel-internet-address.h                     |   38 +-
 camel/camel-junk-plugin.c                          |    2 -
 camel/camel-junk-plugin.h                          |    8 +-
 camel/camel-list-utils.h                           |    8 +-
 camel/camel-lock-client.c                          |    6 +-
 camel/camel-lock-client.h                          |   10 +-
 camel/camel-lock-helper.h                          |   10 +-
 camel/camel-lock.c                                 |    1 -
 camel/camel-lock.h                                 |   10 +-
 camel/camel-medium.c                               |  312 ++-
 camel/camel-medium.h                               |   58 +-
 camel/camel-mime-filter-basic.c                    |  336 ++-
 camel/camel-mime-filter-basic.h                    |   48 +-
 camel/camel-mime-filter-bestenc.c                  |  257 +-
 camel/camel-mime-filter-bestenc.h                  |   72 +-
 camel/camel-mime-filter-canon.c                    |  145 +-
 camel/camel-mime-filter-canon.h                    |   42 +-
 camel/camel-mime-filter-charset.c                  |  219 +-
 camel/camel-mime-filter-charset.h                  |   48 +-
 camel/camel-mime-filter-crlf.c                     |  196 +-
 camel/camel-mime-filter-crlf.h                     |   48 +-
 camel/camel-mime-filter-enriched.c                 |  209 +-
 camel/camel-mime-filter-enriched.h                 |   49 +-
 camel/camel-mime-filter-from.c                     |  113 +-
 camel/camel-mime-filter-from.h                     |   42 +-
 camel/camel-mime-filter-gzip.c                     |  240 +-
 camel/camel-mime-filter-gzip.h                     |   51 +-
 camel/camel-mime-filter-html.c                     |  158 +-
 camel/camel-mime-filter-html.h                     |   42 +-
 camel/camel-mime-filter-index.c                    |  189 +-
 camel/camel-mime-filter-index.h                    |   54 +-
 camel/camel-mime-filter-linewrap.c                 |  174 +-
 camel/camel-mime-filter-linewrap.h                 |   50 +-
 camel/camel-mime-filter-pgp.c                      |  167 +-
 camel/camel-mime-filter-pgp.h                      |   54 +-
 camel/camel-mime-filter-progress.c                 |  139 +-
 camel/camel-mime-filter-progress.h                 |   47 +-
 camel/camel-mime-filter-save.c                     |  135 +-
 camel/camel-mime-filter-save.h                     |   44 +-
 camel/camel-mime-filter-tohtml.c                   |  338 ++-
 camel/camel-mime-filter-tohtml.h                   |   54 +-
 camel/camel-mime-filter-windows.c                  |  153 +-
 camel/camel-mime-filter-windows.h                  |   53 +-
 camel/camel-mime-filter-yenc.c                     |  263 +-
 camel/camel-mime-filter-yenc.h                     |   92 +-
 camel/camel-mime-filter.c                          |  163 +-
 camel/camel-mime-filter.h                          |   98 +-
 camel/camel-mime-message.c                         |  253 +-
 camel/camel-mime-message.h                         |   48 +-
 camel/camel-mime-parser.c                          |   78 +-
 camel/camel-mime-parser.h                          |   38 +-
 camel/camel-mime-part-utils.c                      |   14 +-
 camel/camel-mime-part-utils.h                      |    6 +-
 camel/camel-mime-part.c                            |  585 +++-
 camel/camel-mime-part.h                            |   62 +-
 camel/camel-mime-utils.c                           |    2 -
 camel/camel-mime-utils.h                           |   10 +-
 camel/camel-movemail.c                             |   13 +-
 camel/camel-movemail.h                             |    6 +-
 camel/camel-msgport.h                              |    4 +
 camel/camel-multipart-encrypted.c                  |  117 +-
 camel/camel-multipart-encrypted.h                  |   36 +-
 camel/camel-multipart-signed.c                     |  201 +-
 camel/camel-multipart-signed.h                     |   33 +-
 camel/camel-multipart.c                            |  223 +-
 camel/camel-multipart.h                            |   44 +-
 camel/camel-net-utils-win32.h                      |    5 +
 camel/camel-net-utils.c                            |    1 -
 camel/camel-net-utils.h                            |    6 +-
 camel/camel-news-address.c                         |   37 +-
 camel/camel-news-address.h                         |   38 +-
 camel/camel-nntp-address.c                         |  128 +-
 camel/camel-nntp-address.h                         |   37 +-
 camel/camel-object-bag.c                           |  525 ++++
 camel/camel-object-bag.h                           |   61 +
 camel/camel-object.c                               | 1490 ++--------
 camel/camel-object.h                               |  256 +--
 camel/camel-offline-folder.c                       |  143 +-
 camel/camel-offline-folder.h                       |   36 +-
 camel/camel-offline-journal.c                      |   66 +-
 camel/camel-offline-journal.h                      |   40 +-
 camel/camel-offline-store.c                        |   92 +-
 camel/camel-offline-store.h                        |   38 +-
 camel/camel-operation.c                            |    2 -
 camel/camel-operation.h                            |    6 +-
 camel/camel-partition-table.c                      |  501 ++--
 camel/camel-partition-table.h                      |   60 +-
 camel/camel-private.h                              |   17 +-
 camel/camel-process.h                              |   10 +-
 camel/camel-provider.c                             |    7 +-
 camel/camel-provider.h                             |   11 +-
 camel/camel-sasl-anonymous.c                       |  147 +-
 camel/camel-sasl-anonymous.h                       |   43 +-
 camel/camel-sasl-cram-md5.c                        |   96 +-
 camel/camel-sasl-cram-md5.h                        |   44 +-
 camel/camel-sasl-digest-md5.c                      |  209 +-
 camel/camel-sasl-digest-md5.h                      |   45 +-
 camel/camel-sasl-gssapi.c                          |  149 +-
 camel/camel-sasl-gssapi.h                          |   43 +-
 camel/camel-sasl-login.c                           |  109 +-
 camel/camel-sasl-login.h                           |   46 +-
 camel/camel-sasl-ntlm.c                            |  199 +-
 camel/camel-sasl-ntlm.h                            |   44 +-
 camel/camel-sasl-plain.c                           |  101 +-
 camel/camel-sasl-plain.h                           |   44 +-
 camel/camel-sasl-popb4smtp.c                       |  109 +-
 camel/camel-sasl-popb4smtp.h                       |   44 +-
 camel/camel-sasl.c                                 |  348 ++-
 camel/camel-sasl.h                                 |   65 +-
 camel/camel-search-private.c                       |   57 +-
 camel/camel-search-private.h                       |    9 +-
 camel/camel-search-sql-sexp.c                      |    1 -
 camel/camel-search-sql-sexp.h                      |   12 +-
 camel/camel-search-sql.c                           |    1 -
 camel/camel-search-sql.h                           |   12 +-
 camel/camel-seekable-stream.c                      |  156 +-
 camel/camel-seekable-stream.h                      |   40 +-
 camel/camel-seekable-substream.c                   |  222 +-
 camel/camel-seekable-substream.h                   |   41 +-
 camel/camel-service.c                              |  408 ++--
 camel/camel-service.h                              |   54 +-
 camel/camel-session.c                              |  634 +++--
 camel/camel-session.h                              |   54 +-
 camel/camel-smime-context.c                        |  988 +++---
 camel/camel-smime-context.h                        |   46 +-
 camel/camel-store-summary.c                        |  845 +++---
 camel/camel-store-summary.h                        |   40 +-
 camel/camel-store.c                                |  754 ++---
 camel/camel-store.h                                |   63 +-
 camel/camel-stream-buffer.c                        |  561 ++--
 camel/camel-stream-buffer.h                        |   96 +-
 camel/camel-stream-filter.c                        |  460 ++--
 camel/camel-stream-filter.h                        |   51 +-
 camel/camel-stream-fs.c                            |  319 ++-
 camel/camel-stream-fs.h                            |   67 +-
 camel/camel-stream-mem.c                           |  397 ++--
 camel/camel-stream-mem.h                           |   66 +-
 camel/camel-stream-null.c                          |   81 +-
 camel/camel-stream-null.h                          |   34 +-
 camel/camel-stream-process.c                       |  151 +-
 camel/camel-stream-process.h                       |   35 +-
 camel/camel-stream-vfs.c                           |  261 +-
 camel/camel-stream-vfs.h                           |   36 +-
 camel/camel-stream.c                               |  145 +-
 camel/camel-stream.h                               |   44 +-
 camel/camel-string-utils.h                         |   10 +-
 camel/camel-tcp-stream-raw.c                       |  313 +-
 camel/camel-tcp-stream-raw.h                       |   44 +-
 camel/camel-tcp-stream-ssl.c                       |  134 +-
 camel/camel-tcp-stream-ssl.h                       |   45 +-
 camel/camel-tcp-stream.c                           |  136 +-
 camel/camel-tcp-stream.h                           |   41 +-
 camel/camel-text-index.c                           | 1470 +++++-----
 camel/camel-text-index.h                           |  123 +-
 camel/camel-transport.c                            |   95 +-
 camel/camel-transport.h                            |   50 +-
 camel/camel-trie.h                                 |    4 +
 camel/camel-types.h                                |   78 -
 camel/camel-uid-cache.c                            |    1 -
 camel/camel-uid-cache.h                            |    6 +-
 camel/camel-url-scanner.h                          |   10 +-
 camel/camel-url.c                                  |    1 -
 camel/camel-url.h                                  |    9 +-
 camel/camel-utf8.h                                 |   10 +-
 camel/camel-vee-folder.c                           | 3206 ++++++++++----------
 camel/camel-vee-folder.h                           |   41 +-
 camel/camel-vee-store.c                            |  523 ++--
 camel/camel-vee-store.h                            |   36 +-
 camel/camel-vee-summary.c                          |   84 +-
 camel/camel-vee-summary.h                          |   33 +-
 camel/camel-vtrash-folder.c                        |  183 +-
 camel/camel-vtrash-folder.h                        |   41 +-
 camel/camel-win32.c                                |    1 -
 camel/camel.c                                      |    5 +-
 camel/camel.h                                      |   12 +-
 camel/providers/groupwise/camel-groupwise-folder.c |  193 +-
 camel/providers/groupwise/camel-groupwise-folder.h |   50 +-
 .../providers/groupwise/camel-groupwise-journal.c  |   85 +-
 .../providers/groupwise/camel-groupwise-journal.h  |   42 +-
 .../providers/groupwise/camel-groupwise-private.h  |    2 +-
 .../providers/groupwise/camel-groupwise-provider.c |   10 +-
 .../groupwise/camel-groupwise-store-summary.c      |   89 +-
 .../groupwise/camel-groupwise-store-summary.h      |   42 +-
 camel/providers/groupwise/camel-groupwise-store.c  |  220 +-
 camel/providers/groupwise/camel-groupwise-store.h  |   33 +-
 .../providers/groupwise/camel-groupwise-summary.c  |  129 +-
 .../providers/groupwise/camel-groupwise-summary.h  |   37 +-
 .../groupwise/camel-groupwise-transport.c          |  145 +-
 .../groupwise/camel-groupwise-transport.h          |   44 +-
 camel/providers/groupwise/camel-groupwise-utils.c  |   95 +-
 camel/providers/groupwise/camel-groupwise-utils.h  |    8 +-
 camel/providers/hula/camel-hula-provider.c         |    6 -
 camel/providers/imap/Makefile.am                   |    1 -
 camel/providers/imap/camel-imap-command.c          |   14 +-
 camel/providers/imap/camel-imap-command.h          |    7 +-
 camel/providers/imap/camel-imap-folder.c           |  298 +-
 camel/providers/imap/camel-imap-folder.h           |   45 +-
 camel/providers/imap/camel-imap-journal.c          |  109 +-
 camel/providers/imap/camel-imap-journal.h          |   43 +-
 camel/providers/imap/camel-imap-message-cache.c    |   90 +-
 camel/providers/imap/camel-imap-message-cache.h    |   49 +-
 camel/providers/imap/camel-imap-private.h          |    2 +-
 camel/providers/imap/camel-imap-provider.c         |    6 +-
 camel/providers/imap/camel-imap-search.c           |  123 +-
 camel/providers/imap/camel-imap-search.h           |   35 +-
 camel/providers/imap/camel-imap-store-summary.c    |  101 +-
 camel/providers/imap/camel-imap-store-summary.h    |   42 +-
 camel/providers/imap/camel-imap-store.c            |  245 +-
 camel/providers/imap/camel-imap-store.h            |   49 +-
 camel/providers/imap/camel-imap-summary.c          |  129 +-
 camel/providers/imap/camel-imap-summary.h          |   38 +-
 camel/providers/imap/camel-imap-types.h            |    4 +-
 camel/providers/imap/camel-imap-utils.c            |    5 -
 camel/providers/imap/camel-imap-utils.h            |    6 +-
 camel/providers/imap/camel-imap-wrapper.c          |   99 +-
 camel/providers/imap/camel-imap-wrapper.h          |   33 +-
 camel/providers/imap4/camel-imap4-command.c        |   31 +-
 camel/providers/imap4/camel-imap4-command.h        |   14 +-
 camel/providers/imap4/camel-imap4-engine.c         |   75 +-
 camel/providers/imap4/camel-imap4-engine.h         |   44 +-
 camel/providers/imap4/camel-imap4-folder.c         |   93 +-
 camel/providers/imap4/camel-imap4-folder.h         |   44 +-
 camel/providers/imap4/camel-imap4-journal.c        |   63 +-
 camel/providers/imap4/camel-imap4-journal.h        |   42 +-
 camel/providers/imap4/camel-imap4-provider.c       |    3 -
 camel/providers/imap4/camel-imap4-search.c         |   48 +-
 camel/providers/imap4/camel-imap4-search.h         |   40 +-
 camel/providers/imap4/camel-imap4-specials.h       |    6 +-
 camel/providers/imap4/camel-imap4-store-summary.c  |   57 +-
 camel/providers/imap4/camel-imap4-store-summary.h  |   38 +-
 camel/providers/imap4/camel-imap4-store.c          |   66 +-
 camel/providers/imap4/camel-imap4-store.h          |   37 +-
 camel/providers/imap4/camel-imap4-stream.c         |   56 +-
 camel/providers/imap4/camel-imap4-stream.h         |   39 +-
 camel/providers/imap4/camel-imap4-summary.c        |   54 +-
 camel/providers/imap4/camel-imap4-summary.h        |   40 +-
 camel/providers/imap4/camel-imap4-utils.c          |    3 -
 camel/providers/imap4/camel-imap4-utils.h          |   10 +-
 camel/providers/imapx/camel-imapx-exception.h      |    2 +-
 camel/providers/imapx/camel-imapx-server.c         |    2 +-
 camel/providers/imapx/camel-imapx-store-summary.c  |   20 +-
 camel/providers/imapx/camel-imapx-stream.c         |    7 +-
 camel/providers/imapx/camel-imapx-utils.c          |    8 +-
 camel/providers/local/camel-local-folder.c         |  227 +-
 camel/providers/local/camel-local-folder.h         |   37 +-
 camel/providers/local/camel-local-private.h        |    2 +-
 camel/providers/local/camel-local-provider.c       |    9 +-
 camel/providers/local/camel-local-store.c          |  121 +-
 camel/providers/local/camel-local-store.h          |   50 +-
 camel/providers/local/camel-local-summary.c        |  150 +-
 camel/providers/local/camel-local-summary.h        |   38 +-
 camel/providers/local/camel-maildir-folder.c       |   95 +-
 camel/providers/local/camel-maildir-folder.h       |   42 +-
 camel/providers/local/camel-maildir-store.c        |   76 +-
 camel/providers/local/camel-maildir-store.h        |   42 +-
 camel/providers/local/camel-maildir-summary.c      |  131 +-
 camel/providers/local/camel-maildir-summary.h      |   45 +-
 camel/providers/local/camel-mbox-folder.c          |  127 +-
 camel/providers/local/camel-mbox-folder.h          |   43 +-
 camel/providers/local/camel-mbox-store.c           |   93 +-
 camel/providers/local/camel-mbox-store.h           |   42 +-
 camel/providers/local/camel-mbox-summary.c         |  173 +-
 camel/providers/local/camel-mbox-summary.h         |   31 +-
 camel/providers/local/camel-mh-folder.c            |   86 +-
 camel/providers/local/camel-mh-folder.h            |   41 +-
 camel/providers/local/camel-mh-store.c             |   80 +-
 camel/providers/local/camel-mh-store.h             |   43 +-
 camel/providers/local/camel-mh-summary.c           |   86 +-
 camel/providers/local/camel-mh-summary.h           |   43 +-
 camel/providers/local/camel-spool-folder.c         |   74 +-
 camel/providers/local/camel-spool-folder.h         |   49 +-
 camel/providers/local/camel-spool-store.c          |   87 +-
 camel/providers/local/camel-spool-store.h          |   43 +-
 camel/providers/local/camel-spool-summary.c        |   80 +-
 camel/providers/local/camel-spool-summary.h        |   37 +-
 camel/providers/nntp/camel-nntp-auth.c             |    3 -
 camel/providers/nntp/camel-nntp-auth.h             |    4 +-
 camel/providers/nntp/camel-nntp-folder.c           |  195 +-
 camel/providers/nntp/camel-nntp-folder.h           |   38 +-
 camel/providers/nntp/camel-nntp-grouplist.c        |    3 -
 camel/providers/nntp/camel-nntp-grouplist.h        |    2 +-
 camel/providers/nntp/camel-nntp-newsrc.c           |    3 -
 camel/providers/nntp/camel-nntp-newsrc.h           |    6 +-
 camel/providers/nntp/camel-nntp-private.h          |    2 +-
 camel/providers/nntp/camel-nntp-provider.c         |    4 +-
 camel/providers/nntp/camel-nntp-resp-codes.h       |    2 +-
 camel/providers/nntp/camel-nntp-store-summary.c    |  101 +-
 camel/providers/nntp/camel-nntp-store-summary.h    |   41 +-
 camel/providers/nntp/camel-nntp-store.c            |  286 +-
 camel/providers/nntp/camel-nntp-store.h            |   31 +-
 camel/providers/nntp/camel-nntp-stream.c           |  181 +-
 camel/providers/nntp/camel-nntp-stream.h           |   37 +-
 camel/providers/nntp/camel-nntp-summary.c          |  284 +-
 camel/providers/nntp/camel-nntp-summary.h          |   36 +-
 camel/providers/nntp/camel-nntp-types.h            |    2 +-
 camel/providers/nntp/camel-nntp-utils.c            |    4 -
 camel/providers/nntp/camel-nntp-utils.h            |    2 +-
 camel/providers/pop3/camel-pop3-engine.c           |   91 +-
 camel/providers/pop3/camel-pop3-engine.h           |   35 +-
 camel/providers/pop3/camel-pop3-folder.c           |  113 +-
 camel/providers/pop3/camel-pop3-folder.h           |   54 +-
 camel/providers/pop3/camel-pop3-provider.c         |    6 +-
 camel/providers/pop3/camel-pop3-store.c            |  134 +-
 camel/providers/pop3/camel-pop3-store.h            |   47 +-
 camel/providers/pop3/camel-pop3-stream.c           |  182 +-
 camel/providers/pop3/camel-pop3-stream.h           |   37 +-
 camel/providers/sendmail/camel-sendmail-provider.c |    6 +-
 .../providers/sendmail/camel-sendmail-transport.c  |   71 +-
 .../providers/sendmail/camel-sendmail-transport.h  |   42 +-
 camel/providers/smtp/camel-smtp-provider.c         |    5 +-
 camel/providers/smtp/camel-smtp-transport.c        |  145 +-
 camel/providers/smtp/camel-smtp-transport.h        |   48 +-
 camel/tests/folder/test1.c                         |    2 +-
 camel/tests/folder/test10.c                        |   10 +-
 camel/tests/folder/test4.c                         |    2 +-
 camel/tests/folder/test5.c                         |    2 +-
 camel/tests/folder/test8.c                         |    4 +-
 camel/tests/folder/test9.c                         |    2 +-
 camel/tests/lib/camel-test-provider.c              |    2 +-
 camel/tests/lib/camel-test-provider.h              |    4 +-
 camel/tests/lib/camel-test.c                       |    6 +-
 camel/tests/lib/camel-test.h                       |    2 +-
 camel/tests/lib/folders.c                          |    2 +-
 camel/tests/lib/messages.c                         |   22 +-
 camel/tests/lib/session.c                          |   14 +-
 camel/tests/lib/session.h                          |   41 +-
 camel/tests/lib/streams.c                          |    2 +-
 camel/tests/message/test1.c                        |    6 +-
 camel/tests/message/test3.c                        |   26 +-
 camel/tests/message/test4.c                        |    6 +-
 camel/tests/mime-filter/test-charset.c             |   12 +-
 camel/tests/mime-filter/test-crlf.c                |   10 +-
 camel/tests/mime-filter/test-tohtml.c              |    4 +-
 camel/tests/mime-filter/test1.c                    |    2 +-
 camel/tests/misc/split.c                           |    1 -
 camel/tests/misc/utf7.c                            |    1 -
 camel/tests/smime/pgp-mime.c                       |   37 +-
 camel/tests/smime/pgp.c                            |   51 +-
 camel/tests/smime/pkcs7.c                          |   31 +-
 docs/reference/camel/Makefile.am                   |    7 +-
 docs/reference/camel/camel-docs.sgml               |    1 -
 docs/reference/camel/camel-sections.txt            | 1196 +++++---
 docs/reference/camel/camel.types                   |   92 +
 docs/reference/camel/tmpl/camel-address.sgml       |    3 -
 docs/reference/camel/tmpl/camel-block-file.sgml    |   19 -
 docs/reference/camel/tmpl/camel-certdb.sgml        |   10 -
 .../reference/camel/tmpl/camel-cipher-context.sgml |   15 +-
 docs/reference/camel/tmpl/camel-data-cache.sgml    |   30 +-
 docs/reference/camel/tmpl/camel-data-wrapper.sgml  |    6 -
 docs/reference/camel/tmpl/camel-digest-folder.sgml |    2 -
 docs/reference/camel/tmpl/camel-digest-store.sgml  |    1 -
 .../reference/camel/tmpl/camel-digest-summary.sgml |    1 -
 docs/reference/camel/tmpl/camel-disco-diary.sgml   |    5 -
 docs/reference/camel/tmpl/camel-disco-folder.sgml  |    2 -
 docs/reference/camel/tmpl/camel-disco-store.sgml   |    3 -
 docs/reference/camel/tmpl/camel-filter-driver.sgml |    2 -
 docs/reference/camel/tmpl/camel-folder-search.sgml |   10 -
 .../reference/camel/tmpl/camel-folder-summary.sgml |   29 -
 docs/reference/camel/tmpl/camel-folder.sgml        |   10 -
 docs/reference/camel/tmpl/camel-gpg-context.sgml   |   20 +-
 .../camel/tmpl/camel-groupwise-folder.sgml         |    2 +-
 .../camel/tmpl/camel-groupwise-journal.sgml        |    2 +-
 .../camel/tmpl/camel-groupwise-store.sgml          |    2 +-
 .../camel/tmpl/camel-groupwise-transport.sgml      |    2 +-
 docs/reference/camel/tmpl/camel-html-parser.sgml   |    2 -
 docs/reference/camel/tmpl/camel-http-stream.sgml   |   14 -
 docs/reference/camel/tmpl/camel-imap-folder.sgml   |    2 +-
 docs/reference/camel/tmpl/camel-imap-journal.sgml  |    2 +-
 .../camel/tmpl/camel-imap-message-cache.sgml       |    2 +-
 docs/reference/camel/tmpl/camel-imap-store.sgml    |    2 +-
 docs/reference/camel/tmpl/camel-imap-wrapper.sgml  |    2 +-
 docs/reference/camel/tmpl/camel-imap4-engine.sgml  |    2 +-
 docs/reference/camel/tmpl/camel-imap4-folder.sgml  |    2 +-
 docs/reference/camel/tmpl/camel-imap4-journal.sgml |    2 +-
 docs/reference/camel/tmpl/camel-imap4-search.sgml  |    2 +-
 docs/reference/camel/tmpl/camel-imap4-store.sgml   |    2 +-
 docs/reference/camel/tmpl/camel-imap4-stream.sgml  |    2 +-
 docs/reference/camel/tmpl/camel-imap4-summary.sgml |    2 +-
 docs/reference/camel/tmpl/camel-index.sgml         |   17 -
 .../camel/tmpl/camel-internet-address.sgml         |    2 -
 docs/reference/camel/tmpl/camel-local-folder.sgml  |    2 +-
 docs/reference/camel/tmpl/camel-local-store.sgml   |    2 +-
 .../reference/camel/tmpl/camel-maildir-folder.sgml |    2 +-
 docs/reference/camel/tmpl/camel-maildir-store.sgml |    2 +-
 docs/reference/camel/tmpl/camel-mbox-folder.sgml   |    2 +-
 docs/reference/camel/tmpl/camel-mbox-store.sgml    |    2 +-
 docs/reference/camel/tmpl/camel-medium.sgml        |   11 +-
 docs/reference/camel/tmpl/camel-mh-folder.sgml     |    2 +-
 docs/reference/camel/tmpl/camel-mh-store.sgml      |    2 +-
 .../camel/tmpl/camel-mime-filter-basic.sgml        |   14 -
 .../camel/tmpl/camel-mime-filter-bestenc.sgml      |   14 -
 .../camel/tmpl/camel-mime-filter-canon.sgml        |    2 -
 .../camel/tmpl/camel-mime-filter-charset.sgml      |   13 -
 .../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         |    4 -
 .../camel/tmpl/camel-mime-filter-html.sgml         |    2 -
 .../camel/tmpl/camel-mime-filter-index.sgml        |   12 -
 .../camel/tmpl/camel-mime-filter-linewrap.sgml     |    6 -
 .../camel/tmpl/camel-mime-filter-pgp.sgml          |    2 -
 .../camel/tmpl/camel-mime-filter-progress.sgml     |    4 -
 .../camel/tmpl/camel-mime-filter-save.sgml         |   10 -
 .../camel/tmpl/camel-mime-filter-tohtml.sgml       |   10 +-
 .../camel/tmpl/camel-mime-filter-windows.sgml      |    3 -
 .../camel/tmpl/camel-mime-filter-yenc.sgml         |    6 -
 docs/reference/camel/tmpl/camel-mime-filter.sgml   |   10 -
 docs/reference/camel/tmpl/camel-mime-message.sgml  |   10 -
 docs/reference/camel/tmpl/camel-mime-parser.sgml   |    2 -
 docs/reference/camel/tmpl/camel-mime-part.sgml     |   42 +-
 .../camel/tmpl/camel-multipart-encrypted.sgml      |    5 -
 .../camel/tmpl/camel-multipart-signed.sgml         |   10 -
 docs/reference/camel/tmpl/camel-multipart.sgml     |    4 -
 docs/reference/camel/tmpl/camel-nntp-address.sgml  |    2 -
 docs/reference/camel/tmpl/camel-nntp-store.sgml    |    2 +-
 docs/reference/camel/tmpl/camel-object.sgml        |  411 +---
 .../reference/camel/tmpl/camel-offline-folder.sgml |    2 -
 .../camel/tmpl/camel-offline-journal.sgml          |    4 -
 docs/reference/camel/tmpl/camel-offline-store.sgml |    2 -
 .../camel/tmpl/camel-partition-table.sgml          |   13 -
 docs/reference/camel/tmpl/camel-pop3-folder.sgml   |    2 +-
 docs/reference/camel/tmpl/camel-pop3-store.sgml    |    2 +-
 .../reference/camel/tmpl/camel-sasl-anonymous.sgml |    3 -
 docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml |    1 -
 .../camel/tmpl/camel-sasl-digest-md5.sgml          |    2 -
 docs/reference/camel/tmpl/camel-sasl-gssapi.sgml   |    2 -
 docs/reference/camel/tmpl/camel-sasl-login.sgml    |    2 -
 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          |   71 +-
 .../camel/tmpl/camel-seekable-stream.sgml          |    4 -
 .../camel/tmpl/camel-seekable-substream.sgml       |    2 -
 .../camel/tmpl/camel-sendmail-transport.sgml       |    2 +-
 docs/reference/camel/tmpl/camel-service.sgml       |    7 -
 docs/reference/camel/tmpl/camel-session.sgml       |    7 -
 docs/reference/camel/tmpl/camel-smime-context.sgml |    2 -
 .../reference/camel/tmpl/camel-smtp-transport.sgml |    2 +-
 docs/reference/camel/tmpl/camel-spool-store.sgml   |    2 +-
 docs/reference/camel/tmpl/camel-store-summary.sgml |   12 -
 docs/reference/camel/tmpl/camel-store.sgml         |   48 -
 docs/reference/camel/tmpl/camel-stream-buffer.sgml |   10 -
 docs/reference/camel/tmpl/camel-stream-filter.sgml |   16 +-
 docs/reference/camel/tmpl/camel-stream-fs.sgml     |   11 +-
 docs/reference/camel/tmpl/camel-stream-mem.sgml    |    4 -
 docs/reference/camel/tmpl/camel-stream-null.sgml   |    2 -
 .../reference/camel/tmpl/camel-stream-process.sgml |    3 -
 docs/reference/camel/tmpl/camel-stream-vfs.sgml    |    2 -
 docs/reference/camel/tmpl/camel-stream.sgml        |    2 -
 .../reference/camel/tmpl/camel-tcp-stream-raw.sgml |    3 -
 .../reference/camel/tmpl/camel-tcp-stream-ssl.sgml |    2 -
 docs/reference/camel/tmpl/camel-tcp-stream.sgml    |    1 -
 docs/reference/camel/tmpl/camel-text-index.sgml    |    8 -
 docs/reference/camel/tmpl/camel-transport.sgml     |    2 -
 docs/reference/camel/tmpl/camel-unused.sgml        |  563 ++++
 docs/reference/camel/tmpl/camel-vee-folder.sgml    |   10 -
 docs/reference/camel/tmpl/camel-vee-store.sgml     |    3 -
 docs/reference/camel/tmpl/camel-vee-summary.sgml   |    3 -
 docs/reference/camel/tmpl/camel-vtrash-folder.sgml |    3 -
 docs/reference/camel/tmpl/session.sgml             |    2 +-
 521 files changed, 25134 insertions(+), 20919 deletions(-)
---
diff --git a/addressbook/libebook/e-destination.c b/addressbook/libebook/e-destination.c
index ef12067..ee3485a 100644
--- a/addressbook/libebook/e-destination.c
+++ b/addressbook/libebook/e-destination.c
@@ -44,7 +44,7 @@
 #include <glib.h>
 #include <libxml/xmlmemory.h>
 #include <glib/gi18n-lib.h>
-#include <camel/camel-internet-address.h>
+#include <camel/camel.h>
 
 #define d(x)
 
@@ -773,7 +773,7 @@ e_destination_get_name (const EDestination *dest)
 				priv->name = g_strdup (camel_name);
 			}
 
-			camel_object_unref (CAMEL_OBJECT (addr));
+			g_object_unref (addr);
 		}
 	}
 
@@ -848,7 +848,7 @@ e_destination_get_email (const EDestination *dest)
 				priv->email = g_strdup (camel_email);
 			}
 
-			camel_object_unref (CAMEL_OBJECT (addr));
+			g_object_unref (addr);
 		}
 
 		/* Force e-mail to be non-null... */
@@ -925,7 +925,7 @@ e_destination_get_address (const EDestination *dest)
 			priv->addr = camel_address_encode (CAMEL_ADDRESS (addr));
 		}
 
-		camel_object_unref (CAMEL_OBJECT (addr));
+		g_object_unref (addr);
 	}
 
 	return priv->addr;
@@ -987,7 +987,7 @@ e_destination_get_textrep (const EDestination *dest, gboolean include_email)
 		camel_internet_address_add (addr, name, email);
 		g_free (dest->priv->textrep);
 		dest->priv->textrep = camel_address_format (CAMEL_ADDRESS (addr));
-		camel_object_unref (CAMEL_OBJECT (addr));
+		g_object_unref (addr);
 	}
 
 	if (dest->priv->textrep != NULL)
diff --git a/camel/Makefile.am b/camel/Makefile.am
index e696bed..9ff6274 100644
--- a/camel/Makefile.am
+++ b/camel/Makefile.am
@@ -30,15 +30,16 @@ camellibexec_PROGRAMS =	$(LOCK_HELPER) camel-index-control-1.2
 lib_LTLIBRARIES = libcamel-1.2.la libcamel-provider-1.2.la
 
 libcamel_provider_1_2_la_CPPFLAGS = \
-	$(AM_CPPFLAGS)									\
-	-I$(top_srcdir) 								\
-	-I$(top_builddir)								\
-	-I$(srcdir)										\
+	$(AM_CPPFLAGS)						\
+	-I$(top_srcdir) 					\
+	-I$(top_builddir)					\
+	-I$(srcdir)						\
 	-DCAMEL_LIBEXECDIR=\""$(camellibexecdir)"\"		\
-	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\" 	\
-	-DG_LOG_DOMAIN=\"camel\"						\
+	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\"		\
+	-DG_LOG_DOMAIN=\"camel\"				\
 	-DE_DATA_SERVER_PREFIX=\"$(prefix)\"			\
 	-DEVOLUTION_LOCALEDIR=\""$(localedir)"\"		\
+	-DCAMEL_COMPILATION					\
 	$(CAMEL_CFLAGS)
 
 libcamel_provider_1_2_la_SOURCES = 		\
@@ -151,15 +152,16 @@ libcamel_provider_1_2_la_LIBADD =			\
 	$(REGEX_LIBS)
 
 libcamel_1_2_la_CPPFLAGS = \
-	$(AM_CPPFLAGS)									\
-	-I$(top_srcdir) 								\
-	-I$(top_builddir)								\
-	-I$(srcdir)										\
+	$(AM_CPPFLAGS)						\
+	-I$(top_srcdir) 					\
+	-I$(top_builddir)					\
+	-I$(srcdir)						\
 	-DCAMEL_LIBEXECDIR=\""$(camellibexecdir)"\"		\
-	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\" 	\
-	-DG_LOG_DOMAIN=\"camel\"						\
+	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\"		\
+	-DG_LOG_DOMAIN=\"camel\"				\
 	-DE_DATA_SERVER_PREFIX=\"$(prefix)\"			\
 	-DEVOLUTION_LOCALEDIR=\""$(localedir)"\"		\
+	-DCAMEL_COMPILATION					\
 	$(CAMEL_CFLAGS)
 
 libcamel_1_2_la_SOURCES = 			\
@@ -213,6 +215,7 @@ libcamel_1_2_la_SOURCES = 			\
 	camel-net-utils.c			\
 	camel-nntp-address.c			\
 	camel-object.c				\
+	camel-object-bag.c			\
 	camel-operation.c			\
 	camel-partition-table.c			\
 	camel-seekable-stream.c			\
@@ -285,6 +288,7 @@ libcamelinclude_HEADERS =			\
 	camel-net-utils.h			\
 	camel-nntp-address.h			\
 	camel-object.h				\
+	camel-object-bag.h			\
 	camel-operation.h			\
 	camel-partition-table.h			\
 	camel-search-private.h			\
@@ -301,7 +305,6 @@ libcamelinclude_HEADERS =			\
 	camel-string-utils.h			\
 	camel-text-index.h			\
 	camel-trie.h				\
-	camel-types.h				\
 	camel-url-scanner.h			\
 	camel-url.h				\
 	camel-utf8.h				\
@@ -317,15 +320,16 @@ libcamel_1_2_la_LIBADD =				\
 	$(REGEX_LIBS)
 
 camel_lock_helper_1_2_CPPFLAGS = \
-	$(AM_CPPFLAGS)									\
-	-I$(top_srcdir) 								\
-	-I$(top_builddir)								\
-	-I$(srcdir)										\
+	$(AM_CPPFLAGS)						\
+	-I$(top_srcdir) 					\
+	-I$(top_builddir)					\
+	-I$(srcdir)						\
 	-DCAMEL_LIBEXECDIR=\""$(camellibexecdir)"\"		\
-	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\" 	\
-	-DG_LOG_DOMAIN=\"camel\"						\
+	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\"		\
+	-DG_LOG_DOMAIN=\"camel\"				\
 	-DE_DATA_SERVER_PREFIX=\"$(prefix)\"			\
 	-DEVOLUTION_LOCALEDIR=\""$(localedir)"\"		\
+	-DCAMEL_COMPILATION					\
 	$(CAMEL_CFLAGS)
 
 camel_lock_helper_1_2_SOURCES = \
@@ -340,15 +344,16 @@ camel_lock_helper_1_2_LDADD = \
 	$(libcamel_1_2_la_LIBADD)
 
 camel_index_control_1_2_CPPFLAGS = \
-	$(AM_CPPFLAGS)									\
-	-I$(top_srcdir) 								\
-	-I$(top_builddir)								\
-	-I$(srcdir)										\
+	$(AM_CPPFLAGS)						\
+	-I$(top_srcdir) 					\
+	-I$(top_builddir)					\
+	-I$(srcdir)						\
 	-DCAMEL_LIBEXECDIR=\""$(camellibexecdir)"\"		\
-	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\" 	\
-	-DG_LOG_DOMAIN=\"camel\"						\
+	-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\"		\
+	-DG_LOG_DOMAIN=\"camel\"				\
 	-DE_DATA_SERVER_PREFIX=\"$(prefix)\"			\
 	-DEVOLUTION_LOCALEDIR=\""$(localedir)"\"		\
+	-DCAMEL_COMPILATION					\
 	$(CAMEL_CFLAGS)
 
 camel_index_control_1_2_SOURCES = \
diff --git a/camel/camel-address.c b/camel/camel-address.c
index 89b677a..3237c0f 100644
--- a/camel/camel-address.c
+++ b/camel/camel-address.c
@@ -20,45 +20,51 @@
 
 #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 gpointer parent_class;
 
 static void
-camel_address_class_init (CamelAddressClass *klass)
+address_finalize (GObject *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);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_address_init (CamelAddress *obj)
+address_class_init (CamelAddressClass *class)
 {
-	obj->addresses = g_ptr_array_new();
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = address_finalize;
 }
 
 static void
-camel_address_finalize (CamelObject *obj)
+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
+GType
 camel_address_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (), "CamelAddress",
-					    sizeof (CamelAddress),
-					    sizeof (CamelAddressClass),
-					    (CamelObjectClassInitFunc) camel_address_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_address_init,
-					    (CamelObjectFinalizeFunc) camel_address_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelAddress",
+			sizeof (CamelAddressClass),
+			(GClassInitFunc) address_class_init,
+			sizeof (CamelAddress),
+			(GInstanceInitFunc) address_init,
+			0);
 
 	return type;
 }
@@ -73,8 +79,7 @@ camel_address_get_type (void)
 CamelAddress *
 camel_address_new (void)
 {
-	CamelAddress *new = CAMEL_ADDRESS(camel_object_new(camel_address_get_type()));
-	return new;
+	return g_object_new (CAMEL_TYPE_ADDRESS, NULL);
 }
 
 /**
@@ -86,11 +91,13 @@ camel_address_new (void)
  * Returns: the cloned address
  **/
 CamelAddress *
-camel_address_new_clone (const CamelAddress *addr)
+camel_address_new_clone (CamelAddress *addr)
 {
-	CamelAddress *new = CAMEL_ADDRESS(camel_object_new(CAMEL_OBJECT_GET_TYPE(addr)));
+	CamelAddress *new;
+
+	new = g_object_new (CAMEL_TYPE_ADDRESS, NULL);
+	camel_address_cat (new, addr);
 
-	camel_address_cat(new, addr);
 	return new;
 }
 
@@ -120,9 +127,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);
+
+	class = CAMEL_ADDRESS_GET_CLASS (addr);
+	g_return_val_if_fail (class->decode != NULL, -1);
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->decode(addr, raw);
+	return class->decode (addr, raw);
 }
 
 /**
@@ -136,9 +148,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;
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->encode(addr);
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (addr), NULL);
+
+	class = CAMEL_ADDRESS_GET_CLASS (addr);
+	g_return_val_if_fail (class->encode != NULL, NULL);
+
+	return class->encode (addr);
 }
 
 /**
@@ -154,9 +171,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);
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->unformat(addr, raw);
+	class = CAMEL_ADDRESS_GET_CLASS (addr);
+	g_return_val_if_fail (class->unformat != NULL, -1);
+
+	return class->unformat (addr, raw);
 }
 
 /**
@@ -170,9 +192,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);
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->format(addr);
+	class = CAMEL_ADDRESS_GET_CLASS (addr);
+	g_return_val_if_fail (class->format != NULL, NULL);
+
+	return class->format (addr);
 }
 
 /**
@@ -186,12 +213,17 @@ camel_address_format (CamelAddress *addr)
  * Returns: the number of addresses concatenated
  **/
 gint
-camel_address_cat (CamelAddress *dest, const CamelAddress *source)
+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;
+
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (dest), -1);
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (source), -1);
+
+	class = CAMEL_ADDRESS_GET_CLASS (dest);
+	g_return_val_if_fail (class->cat != NULL, -1);
 
-	return CAMEL_ADDRESS_CLASS(CAMEL_OBJECT_GET_CLASS(dest))->cat(dest, source);
+	return class->cat (dest, source);
 }
 
 /**
@@ -204,10 +236,10 @@ camel_address_cat (CamelAddress *dest, const CamelAddress *source)
  * Returns: the number of addresses copied
  **/
 gint
-camel_address_copy (CamelAddress *dest, const CamelAddress *source)
+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 +255,16 @@ camel_address_copy (CamelAddress *dest, const 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_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-address.h b/camel/camel-address.h
index 6bd17b6..cf9ed02 100644
--- a/camel/camel-address.h
+++ b/camel/camel-address.h
@@ -19,57 +19,80 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_ADDRESS_H
-#define _CAMEL_ADDRESS_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_ADDRESS_H
+#define CAMEL_ADDRESS_H
 
-#include <glib.h>
 #include <camel/camel-object.h>
 
-#define CAMEL_ADDRESS(obj)         CAMEL_CHECK_CAST (obj, camel_address_get_type (), CamelAddress)
-#define CAMEL_ADDRESS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_address_get_type (), CamelAddressClass)
-#define CAMEL_IS_ADDRESS(obj)      CAMEL_CHECK_TYPE (obj, camel_address_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_ADDRESS \
+	(camel_address_get_type ())
+#define CAMEL_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_ADDRESS, CamelAddress))
+#define CAMEL_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_ADDRESS, CamelAddressClass))
+#define CAMEL_IS_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_ADDRESS))
+#define CAMEL_IS_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_ADDRESS))
+#define CAMEL_ADDRESS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_ADDRESS, CamelAddressClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelAddress CamelAddress;
 typedef struct _CamelAddressClass CamelAddressClass;
+typedef struct _CamelAddressPrivate CamelAddressPrivate;
 
 struct _CamelAddress {
 	CamelObject parent;
 
 	GPtrArray *addresses;
 
-	struct _CamelAddressPrivate *priv;
+	CamelAddressPrivate *priv;
 };
 
 struct _CamelAddressClass {
 	CamelObjectClass parent_class;
 
-	gint   (*decode)		(CamelAddress *, const gchar *raw);
-	gchar *(*encode)		(CamelAddress *);
-
-	gint   (*unformat)	(CamelAddress *, const gchar *raw);
-	gchar *(*format)		(CamelAddress *);
-
-	gint   (*cat)		(CamelAddress *, const CamelAddress *);
-
-	void  (*remove)		(CamelAddress *, gint index);
+	gint		(*decode)		(CamelAddress *addr,
+						 const gchar *raw);
+	gchar *		(*encode)		(CamelAddress *addr);
+	gint		(*unformat)		(CamelAddress *addr,
+						 const gchar *raw);
+	gchar *		(*format)		(CamelAddress *addr);
+	gint		(*cat)			(CamelAddress *dest,
+						 CamelAddress *source);
+	void		(*remove)		(CamelAddress *addr,
+						 gint index);
 };
 
-CamelType	camel_address_get_type	(void);
-CamelAddress   *camel_address_new	(void);
-CamelAddress   *camel_address_new_clone	(const CamelAddress *addr);
-gint		camel_address_length	(CamelAddress *addr);
-
-gint		camel_address_decode	(CamelAddress *addr, const gchar *raw);
-gchar	       *camel_address_encode	(CamelAddress *addr);
-gint		camel_address_unformat	(CamelAddress *addr, const gchar *raw);
-gchar	       *camel_address_format	(CamelAddress *addr);
-
-gint		camel_address_cat	(CamelAddress *dest, const CamelAddress *source);
-gint		camel_address_copy	(CamelAddress *dest, const CamelAddress *source);
-
-void		camel_address_remove	(CamelAddress *addr, gint index);
+GType		camel_address_get_type		(void);
+CamelAddress *	camel_address_new		(void);
+CamelAddress *	camel_address_new_clone		(CamelAddress *addr);
+gint		camel_address_length		(CamelAddress *addr);
+gint		camel_address_decode		(CamelAddress *addr,
+						 const gchar *raw);
+gchar *		camel_address_encode		(CamelAddress *addr);
+gint		camel_address_unformat		(CamelAddress *addr,
+						 const gchar *raw);
+gchar *		camel_address_format		(CamelAddress *addr);
+gint		camel_address_cat		(CamelAddress *dest,
+						 CamelAddress *source);
+gint		camel_address_copy		(CamelAddress *dest,
+						 CamelAddress *source);
+void		camel_address_remove		(CamelAddress *addr,
+						 gint index);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_ADDRESS_H */
+#endif /* CAMEL_ADDRESS_H */
diff --git a/camel/camel-arg.h b/camel/camel-arg.h
index 0c60f15..079a19c 100644
--- a/camel/camel-arg.h
+++ b/camel/camel-arg.h
@@ -20,8 +20,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_ARG_H
-#define CAMEL_ARG_H 1
+#define CAMEL_ARG_H
 
 #include <glib.h>
 #include <stdarg.h>
diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c
index 673ff80..d940e9f 100644
--- a/camel/camel-block-file.c
+++ b/camel/camel-block-file.c
@@ -32,7 +32,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
 #include "camel-block-file.h"
@@ -42,6 +41,8 @@
 
 #define d(x) /*(printf("%s(%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
 
+static gpointer block_file_parent_class;
+
 /* Locks must be obtained in the order defined */
 
 struct _CamelBlockFilePrivate {
@@ -74,8 +75,6 @@ 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))
-
 static gint sync_nolock(CamelBlockFile *bs);
 static gint sync_block_nolock(CamelBlockFile *bs, CamelBlock *bl);
 
@@ -144,10 +143,64 @@ block_file_init_root(CamelBlockFile *bs)
 }
 
 static void
-camel_block_file_class_init(CamelBlockFileClass *klass)
+block_file_finalize(GObject *object)
 {
-	klass->validate_root = block_file_validate_root;
-	klass->init_root = block_file_init_root;
+	CamelBlockFile *bs = CAMEL_BLOCK_FILE (object);
+	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);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (block_file_parent_class)->finalize (object);
+}
+
+static void
+block_file_class_init(CamelBlockFileClass *class)
+{
+	GObjectClass *object_class;
+
+	block_file_parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = block_file_finalize;
+
+	class->validate_root = block_file_validate_root;
+	class->init_root = block_file_init_root;
 }
 
 static guint
@@ -157,7 +210,7 @@ block_hash_func(gconstpointer v)
 }
 
 static void
-camel_block_file_init(CamelBlockFile *bs)
+block_file_init(CamelBlockFile *bs)
 {
 	struct _CamelBlockFilePrivate *p;
 
@@ -195,63 +248,20 @@ 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
+GType
 camel_block_file_get_type(void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_object_get_type(), "CamelBlockFile",
-					   sizeof (CamelBlockFile),
-					   sizeof (CamelBlockFileClass),
-					   (CamelObjectClassInitFunc) camel_block_file_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_block_file_init,
-					   (CamelObjectFinalizeFunc) camel_block_file_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelBlockFile",
+			sizeof (CamelBlockFileClass),
+			(GClassInitFunc) block_file_class_init,
+			sizeof (CamelBlockFile),
+			(GInstanceInitFunc) block_file_init,
+			0);
 
 	return type;
 }
@@ -364,16 +374,17 @@ camel_cache_remove(c, key);
  **/
 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());
+	bs = g_object_new (CAMEL_TYPE_BLOCK_FILE, NULL);
 	memcpy(bs->version, version, 8);
 	bs->path = g_strdup(path);
 	bs->flags = flags;
 
 	bs->root_block = camel_block_file_get_block(bs, 0);
 	if (bs->root_block == NULL) {
-		camel_object_unref((CamelObject *)bs);
+		g_object_unref (bs);
 		return NULL;
 	}
 	camel_block_file_detach_block(bs, bs->root_block);
@@ -382,20 +393,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);
+			g_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);
+			g_object_unref (bs);
 			return NULL;
 		}
 		block_file_unuse(bs);
@@ -795,6 +808,8 @@ gint camel_block_file_sync(CamelBlockFile *bs)
 
 /* ********************************************************************** */
 
+static gpointer key_file_parent_class;
+
 struct _CamelKeyFilePrivate {
 	struct _CamelKeyFilePrivate *next;
 	struct _CamelKeyFilePrivate *prev;
@@ -817,28 +832,9 @@ 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)
+key_file_finalize(GObject *object)
 {
+	CamelKeyFile *bs = CAMEL_KEY_FILE (object);
 	struct _CamelKeyFilePrivate *p = bs->priv;
 
 	LOCK(key_file_lock);
@@ -856,22 +852,51 @@ camel_key_file_finalise(CamelKeyFile *bs)
 	pthread_mutex_destroy(&p->lock);
 
 	g_free(p);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (key_file_parent_class)->finalize (object);
 }
 
-CamelType
+static void
+key_file_class_init(CamelKeyFileClass *class)
+{
+	GObjectClass *object_class;
+
+	key_file_parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = key_file_finalize;
+}
+
+static void
+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);
+}
+
+GType
 camel_key_file_get_type(void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_object_get_type(), "CamelKeyFile",
-					   sizeof (CamelKeyFile),
-					   sizeof (CamelKeyFileClass),
-					   (CamelObjectClassInitFunc) camel_key_file_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_key_file_init,
-					   (CamelObjectFinalizeFunc) camel_key_file_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelKeyFile",
+			sizeof (CamelKeyFileClass),
+			(GClassInitFunc) key_file_class_init,
+			sizeof (CamelKeyFile),
+			(GInstanceInitFunc) key_file_init,
+			0);
 
 	return type;
 }
@@ -986,14 +1011,14 @@ camel_key_file_new(const gchar *path, gint flags, const gchar version[8])
 
 	d(printf("New key file '%s'\n", path));
 
-	kf = (CamelKeyFile *)camel_object_new(camel_key_file_get_type());
+	kf = g_object_new (CAMEL_TYPE_KEY_FILE, NULL);
 	kf->path = g_strdup(path);
 	kf->fp = NULL;
 	kf->flags = flags;
 	kf->last = 8;
 
 	if (key_file_use(kf) == -1) {
-		camel_object_unref((CamelObject *)kf);
+		g_object_unref (kf);
 		kf = NULL;
 	} else {
 		fseek(kf->fp, 0, SEEK_END);
@@ -1011,7 +1036,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);
+			g_object_unref (kf);
 			kf = NULL;
 		}
 	}
diff --git a/camel/camel-block-file.h b/camel/camel-block-file.h
index 318a028..209be9a 100644
--- a/camel/camel-block-file.h
+++ b/camel/camel-block-file.h
@@ -18,15 +18,55 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_BLOCK_FILE_H
-#define _CAMEL_BLOCK_FILE_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_BLOCK_FILE_H
+#define CAMEL_BLOCK_FILE_H
 
 #include <camel/camel-object.h>
 #include <camel/camel-list-utils.h>
-#include <glib.h>
 #include <stdio.h>
 #include <sys/types.h>
 
+/* Standard GObject macros */
+#define CAMEL_TYPE_BLOCK_FILE \
+	(camel_block_file_get_type ())
+#define CAMEL_BLOCK_FILE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_BLOCK_FILE, CamelBlockFile))
+#define CAMEL_BLOCK_FILE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_BLOCK_FILE, CamelBlockFileClass))
+#define CAMEL_IS_BLOCK_FILE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_BLOCK_FILE))
+#define CAMEL_IS_BLOCK_FILE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_BLOCK_FILE))
+#define CAMEL_BLOCK_FILE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_BLOCK_FILE, CamelBlockFileClass))
+
+#define CAMEL_TYPE_KEY_FILE \
+	(camel_key_file_get_type ())
+#define CAMEL_KEY_FILE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_KEY_FILE, CamelKeyFile))
+#define CAMEL_KEY_FILE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_KEY_FILE, CamelKeyFileClass))
+#define CAMEL_IS_KEY_FILE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_KEY_FILE))
+#define CAMEL_IS_KEY_FILE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_KEY_FILE))
+#define CAMEL_KEY_FILE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_KEY_FILE, CamelKeyFileClass))
+
 G_BEGIN_DECLS
 
 typedef guint32 camel_block_t;	/* block offset, absolute, bottom BLOCK_SIZE_BITS always 0 */
@@ -36,6 +76,7 @@ typedef struct _CamelBlockRoot CamelBlockRoot;
 typedef struct _CamelBlock CamelBlock;
 typedef struct _CamelBlockFile CamelBlockFile;
 typedef struct _CamelBlockFileClass CamelBlockFileClass;
+typedef struct _CamelBlockFilePrivate CamelBlockFilePrivate;
 
 #define CAMEL_BLOCK_FILE_SYNC (1<<0)
 
@@ -71,8 +112,7 @@ struct _CamelBlock {
 
 struct _CamelBlockFile {
 	CamelObject parent;
-
-	struct _CamelBlockFilePrivate *priv;
+	CamelBlockFilePrivate *priv;
 
 	gchar version[8];
 	gchar *path;
@@ -98,7 +138,7 @@ struct _CamelBlockFileClass {
 	gint (*init_root)(CamelBlockFile *);
 };
 
-CamelType camel_block_file_get_type(void);
+GType camel_block_file_get_type(void);
 
 CamelBlockFile *camel_block_file_new(const gchar *path, gint flags, const gchar version[8], gsize block_size);
 gint camel_block_file_rename(CamelBlockFile *bs, const gchar *path);
@@ -118,11 +158,11 @@ gint camel_block_file_sync(CamelBlockFile *bs);
 
 typedef struct _CamelKeyFile CamelKeyFile;
 typedef struct _CamelKeyFileClass CamelKeyFileClass;
+typedef struct _CamelKeyFilePrivate CamelKeyFilePrivate;
 
 struct _CamelKeyFile {
 	CamelObject parent;
-
-	struct _CamelKeyFilePrivate *priv;
+	CamelKeyFilePrivate *priv;
 
 	FILE *fp;
 	gchar *path;
@@ -134,7 +174,7 @@ struct _CamelKeyFileClass {
 	CamelObjectClass parent;
 };
 
-CamelType      camel_key_file_get_type(void);
+GType      camel_key_file_get_type(void);
 
 CamelKeyFile * camel_key_file_new(const gchar *path, gint flags, const gchar version[8]);
 gint	       camel_key_file_rename(CamelKeyFile *kf, const gchar *path);
@@ -145,4 +185,4 @@ gint            camel_key_file_read(CamelKeyFile *kf, camel_block_t *start, gsiz
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_BLOCK_FILE_H */
+#endif /* CAMEL_BLOCK_FILE_H */
diff --git a/camel/camel-certdb.c b/camel/camel-certdb.c
index cce0fd6..3b09706 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,13 +41,11 @@
 #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);
+#define CAMEL_CERTDB_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_CERTDB, CamelCertDBPrivate))
 
 static gint certdb_header_load (CamelCertDB *certdb, FILE *istream);
 static gint certdb_header_save (CamelCertDB *certdb, FILE *ostream);
@@ -60,47 +57,63 @@ static void certdb_cert_free (CamelCertDB *certdb, CamelCert *cert);
 static const gchar *cert_get_string (CamelCertDB *certdb, CamelCert *cert, gint string);
 static void cert_set_string (CamelCertDB *certdb, CamelCert *cert, gint string, const gchar *value);
 
-static CamelObjectClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
-camel_certdb_get_type (void)
+static void
+certdb_finalize (GObject *object)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	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);
-	}
+	CamelCertDB *certdb = CAMEL_CERTDB (object);
+	CamelCertDBPrivate *priv;
 
-	return type;
+	priv = CAMEL_CERTDB_GET_PRIVATE (object);
+
+	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);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_certdb_class_init (CamelCertDBClass *klass)
+certdb_class_init (CamelCertDBClass *class)
 {
-	parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelCertDBPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = certdb_finalize;
 
-	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_init (CamelCertDB *certdb)
 {
-	certdb->priv = g_malloc (sizeof (struct _CamelCertDBPrivate));
+	certdb->priv = CAMEL_CERTDB_GET_PRIVATE (certdb);
 
 	certdb->filename = NULL;
 	certdb->version = CAMEL_CERTDB_VERSION;
@@ -119,38 +132,28 @@ camel_certdb_init (CamelCertDB *certdb)
 	certdb->priv->ref_lock = g_mutex_new ();
 }
 
-static void
-camel_certdb_finalize (CamelObject *obj)
+GType
+camel_certdb_get_type (void)
 {
-	CamelCertDB *certdb = (CamelCertDB *) obj;
-	struct _CamelCertDBPrivate *p;
-
-	p = certdb->priv;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelCertDB",
+			sizeof (CamelCertDBClass),
+			(GClassInitFunc) certdb_class_init,
+			sizeof (CamelCertDB),
+			(GInstanceInitFunc) certdb_init,
+			0);
 
-	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 (p->db_lock);
-	g_mutex_free (p->io_lock);
-	g_mutex_free (p->alloc_lock);
-	g_mutex_free (p->ref_lock);
-
-	g_free (p);
+	return type;
 }
 
 CamelCertDB *
 camel_certdb_new (void)
 {
-	return (CamelCertDB *) camel_object_new (camel_certdb_get_type ());
+	return g_object_new (CAMEL_TYPE_CERTDB, NULL);
 }
 
 static CamelCertDB *default_certdb = NULL;
@@ -162,10 +165,10 @@ camel_certdb_set_default (CamelCertDB *certdb)
 	pthread_mutex_lock (&default_certdb_lock);
 
 	if (default_certdb)
-		camel_object_unref (default_certdb);
+		g_object_unref (default_certdb);
 
 	if (certdb)
-		camel_object_ref (certdb);
+		g_object_ref (certdb);
 
 	default_certdb = certdb;
 
@@ -180,7 +183,7 @@ camel_certdb_get_default (void)
 	pthread_mutex_lock (&default_certdb_lock);
 
 	if (default_certdb)
-		camel_object_ref (default_certdb);
+		g_object_ref (default_certdb);
 
 	certdb = default_certdb;
 
@@ -244,6 +247,7 @@ certdb_cert_load (CamelCertDB *certdb, FILE *istream)
 gint
 camel_certdb_load (CamelCertDB *certdb)
 {
+	CamelCertDBClass *class;
 	CamelCert *cert;
 	FILE *in;
 	gint i;
@@ -255,12 +259,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 +327,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 +356,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 +498,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 +538,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 +611,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 +654,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 21b6168..28c122f 100644
--- a/camel/camel-certdb.h
+++ b/camel/camel-certdb.h
@@ -20,21 +20,40 @@
  *
  */
 
-#ifndef __CAMEL_CERTDB_H__
-#define __CAMEL_CERTDB_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_CERTDB_H
+#define CAMEL_CERTDB_H
 
 #include <stdio.h>
 #include <camel/camel-object.h>
 
-#define CAMEL_CERTDB_TYPE         (camel_certdb_get_type ())
-#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 ()))
+/* Standard GObject macros */
+#define CAMEL_TYPE_CERTDB \
+	(camel_certdb_get_type ())
+#define CAMEL_CERTDB(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_CERTDB, CamelCertDB))
+#define CAMEL_CERTDB_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_CERTDB, CamelCertDBClass))
+#define CAMEL_IS_CERTDB(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_CERTDB))
+#define CAMEL_IS_CERTDB_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_CERTDB))
+#define CAMEL_CERTDB_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_CERTDB, CamelCertDBClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelCertDB CamelCertDB;
 typedef struct _CamelCertDBClass CamelCertDBClass;
+typedef struct _CamelCertDBPrivate CamelCertDBPrivate;
 
 enum {
 	CAMEL_CERTDB_DIRTY  = (1 << 0)
@@ -68,8 +87,8 @@ typedef struct {
 } CamelCert;
 
 struct _CamelCertDB {
-	CamelObject parent_object;
-	struct _CamelCertDBPrivate *priv;
+	CamelObject parent;
+	CamelCertDBPrivate *priv;
 
 	gchar *filename;
 	guint32 version;
@@ -100,7 +119,7 @@ struct _CamelCertDBClass {
 	void (*cert_set_string) (CamelCertDB *certdb, CamelCert *cert, gint string, const gchar *value);
 };
 
-CamelType camel_certdb_get_type (void);
+GType camel_certdb_get_type (void);
 
 CamelCertDB *camel_certdb_new (void);
 
@@ -143,4 +162,4 @@ void camel_cert_set_trust (CamelCertDB *certdb, CamelCert *cert, CamelCertTrust
 
 G_END_DECLS
 
-#endif /* __CAMEL_CERTDB_H__ */
+#endif /* CAMEL_CERTDB_H */
diff --git a/camel/camel-charset-map.h b/camel/camel-charset-map.h
index bdc8084..119117b 100644
--- a/camel/camel-charset-map.h
+++ b/camel/camel-charset-map.h
@@ -19,8 +19,12 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_CHARSET_MAP_H
-#define _CAMEL_CHARSET_MAP_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_CHARSET_MAP_H
+#define CAMEL_CHARSET_MAP_H
 
 #include <glib.h>
 
@@ -45,4 +49,4 @@ const gchar *camel_charset_iso_to_windows (const gchar *isocharset);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_CHARSET_MAP_H */
+#endif /* CAMEL_CHARSET_MAP_H */
diff --git a/camel/camel-cipher-context.c b/camel/camel-cipher-context.c
index 9d5731c..83bbd7e 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,54 +45,21 @@
 
 #define d(x)
 
-#define CCC_CLASS(o) CAMEL_CIPHER_CONTEXT_CLASS(CAMEL_OBJECT_GET_CLASS(o))
+#define CAMEL_CIPHER_CONTEXT_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContextPrivate))
 
 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.
- *
- * Return value: 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));
+enum {
+	PROP_0,
+	PROP_SESSION
+};
 
-	camel_object_ref (session);
-	context->session = session;
-}
+static gpointer parent_class;
 
 static gint
 cipher_sign (CamelCipherContext *ctx, const gchar *userid, CamelCipherHash hash,
@@ -118,22 +85,30 @@ cipher_sign (CamelCipherContext *ctx, const gchar *userid, CamelCipherHash hash,
  * Return value: 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;
 }
@@ -162,21 +137,27 @@ 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);
+
+	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;
 }
@@ -205,28 +186,36 @@ cipher_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *rec
  * Return value: 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);
+
+	camel_operation_start (NULL, _("Encrypting message"));
 
-	CIPHER_LOCK(context);
+	CIPHER_LOCK (context);
 
-	retval = CCC_CLASS (context)->encrypt (context, userid, recipients, ipart, opart, ex);
+	retval = class->encrypt (context, userid, recipients, ipart, opart, ex);
 
-	CIPHER_UNLOCK(context);
+	CIPHER_UNLOCK (context);
 
-	camel_operation_end(NULL);
+	camel_operation_end (NULL);
 
 	return retval;
 }
 
 static CamelCipherValidity *
-cipher_decrypt(CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
+cipher_decrypt (CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
 {
 	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
 			     _("Decryption is not supported by this cipher"));
@@ -245,21 +234,28 @@ cipher_decrypt(CamelCipherContext *context, struct _CamelMimePart *ipart, struct
  * Return value: 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);
 
-	CIPHER_LOCK(context);
+	camel_operation_start (NULL, _("Decrypting message"));
 
-	valid = CCC_CLASS (context)->decrypt (context, ipart, opart, ex);
+	CIPHER_LOCK (context);
 
-	CIPHER_UNLOCK(context);
+	valid = class->decrypt (context, ipart, opart, ex);
 
-	camel_operation_end(NULL);
+	CIPHER_UNLOCK (context);
+
+	camel_operation_end (NULL);
 
 	return valid;
 }
@@ -285,12 +281,19 @@ 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
@@ -316,48 +319,70 @@ 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;
+
+	g_return_val_if_fail (
+		CAMEL_IS_CIPHER_CONTEXT (context),
+		CAMEL_CIPHER_HASH_DEFAULT);
 
-	return CCC_CLASS (context)->id_to_hash (context, id);
+	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);
@@ -373,8 +398,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 +409,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 +444,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 +454,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 +502,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);
 }
@@ -522,7 +547,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;
 
@@ -532,10 +557,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
@@ -544,10 +569,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;
 		}
 	}
@@ -563,101 +588,208 @@ 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 = g_object_ref (session);
+}
+
+static void
+cipher_context_set_property (GObject *object,
+                             guint property_id,
+                             const GValue *value,
+                             GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_SESSION:
+			cipher_context_set_session (
+				CAMEL_CIPHER_CONTEXT (object),
+				g_value_get_object (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
 static void
-camel_cipher_context_finalise (CamelObject *o)
+cipher_context_get_property (GObject *object,
+                             guint property_id,
+                             GValue *value,
+                             GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_SESSION:
+			g_value_set_object (
+				value, camel_cipher_context_get_session (
+				CAMEL_CIPHER_CONTEXT (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+cipher_context_dispose (GObject *object)
 {
-	CamelCipherContext *context = (CamelCipherContext *)o;
+	CamelCipherContextPrivate *priv;
 
-	camel_object_unref (CAMEL_OBJECT (context->session));
+	priv = CAMEL_CIPHER_CONTEXT_GET_PRIVATE (object);
 
-	g_mutex_free (context->priv->lock);
+	if (priv->session != NULL) {
+		g_object_unref (priv->session);
+		priv->session = NULL;
+	}
 
-	g_free (context->priv);
+	/* Chain up to parent's dispose () method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_cipher_context_class_init (CamelCipherContextClass *camel_cipher_context_class)
+cipher_context_finalize (GObject *object)
 {
-	parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
+	CamelCipherContextPrivate *priv;
 
-	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;
+	priv = CAMEL_CIPHER_CONTEXT_GET_PRIVATE (object);
+
+	g_mutex_free (priv->lock);
+
+	/* Chain up to parent's finalize () method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+cipher_context_class_init (CamelCipherContextClass *class)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelCipherContextPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = cipher_context_set_property;
+	object_class->get_property = cipher_context_get_property;
+	object_class->dispose = cipher_context_dispose;
+	object_class->finalize = cipher_context_finalize;
+
+	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;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_SESSION,
+		g_param_spec_object (
+			"session",
+			"Session",
+			NULL,
+			CAMEL_TYPE_SESSION,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT_ONLY));
 }
 
-CamelType
+static void
+cipher_context_init (CamelCipherContext *context)
+{
+	context->priv = CAMEL_CIPHER_CONTEXT_GET_PRIVATE (context);
+	context->priv->lock = g_mutex_new ();
+}
+
+GType
 camel_cipher_context_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (),
-					    "CamelCipherContext",
-					    sizeof (CamelCipherContext),
-					    sizeof (CamelCipherContextClass),
-					    (CamelObjectClassInitFunc) camel_cipher_context_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_cipher_context_init,
-					    (CamelObjectFinalizeFunc) camel_cipher_context_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelCipherContext",
+			sizeof (CamelCipherContextClass),
+			(GClassInitFunc) cipher_context_class_init,
+			sizeof (CamelCipherContext),
+			(GInstanceInitFunc) cipher_context_init,
+			0);
 
 	return type;
 }
 
+/**
+ * camel_cipher_context_new:
+ * @session: CamelSession
+ *
+ * This creates a new CamelCipherContext object which is used to sign,
+ * verify, encrypt and decrypt streams.
+ *
+ * Return value: the new CamelCipherContext
+ **/
+CamelCipherContext *
+camel_cipher_context_new (CamelSession *session)
+{
+	g_return_val_if_fail (session != NULL, NULL);
+
+	return g_object_new (
+		CAMEL_TYPE_CIPHER_CONTEXT,
+		"session", session, NULL);
+}
+
+CamelSession *
+camel_cipher_context_get_session (CamelCipherContext *context)
+{
+	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), NULL);
+
+	return context->priv->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;
 	gint parts, i;
 
-	dw = camel_medium_get_content_object((CamelMedium *)part);
+	dw = camel_medium_get_content ((CamelMedium *)part);
 	if (!dw)
 		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);
 		}
 	}
 }
@@ -675,26 +807,26 @@ cc_prepare_sign(CamelMimePart *part)
  * Return value: -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)
 {
-	CamelStreamFilter *filter;
+	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_with_stream(ostream);
-	canon = camel_mime_filter_canon_new(flags);
-	camel_stream_filter_add(filter, canon);
-	camel_object_unref(canon);
+	filter = camel_stream_filter_new (ostream);
+	canon = camel_mime_filter_canon_new (flags);
+	camel_stream_filter_add (CAMEL_STREAM_FILTER (filter), canon);
+	g_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);
+	g_object_unref (filter);
+	camel_stream_reset (ostream);
 
 	return res;
 }
diff --git a/camel/camel-cipher-context.h b/camel/camel-cipher-context.h
index 7364416..8292fec 100644
--- a/camel/camel-cipher-context.h
+++ b/camel/camel-cipher-context.h
@@ -20,26 +20,47 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_CIPHER_CONTEXT_H
 #define CAMEL_CIPHER_CONTEXT_H
 
+#include <camel/camel-exception.h>
 #include <camel/camel-list-utils.h>
+#include <camel/camel-mime-part.h>
+#include <camel/camel-object.h>
 #include <camel/camel-session.h>
-#include <camel/camel-exception.h>
 
-#define CAMEL_CIPHER_CONTEXT_TYPE     (camel_cipher_context_get_type ())
-#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))
+/* Standard GObject macros */
+#define CAMEL_TYPE_CIPHER_CONTEXT \
+	(camel_cipher_context_get_type ())
+#define CAMEL_CIPHER_CONTEXT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContext))
+#define CAMEL_CIPHER_CONTEXT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContextClass))
+#define CAMEL_IS_CIPHER_CONTEXT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_CIPHER_CONTEXT))
+#define CAMEL_IS_CIPHER_CONTEXT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_CIPHER_CONTEXT))
+#define CAMEL_CIPHER_CONTEXT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContextClass))
 
 G_BEGIN_DECLS
 
-struct _CamelStream;
-struct _CamelMimePart;
-
 typedef struct _CamelCipherValidity CamelCipherValidity;
 typedef struct _CamelCipherCertInfo CamelCipherCertInfo;
 
+typedef struct _CamelCipherContext CamelCipherContext;
+typedef struct _CamelCipherContextClass CamelCipherContextClass;
+typedef struct _CamelCipherContextPrivate CamelCipherContextPrivate;
+
 typedef enum {
 	CAMEL_CIPHER_HASH_DEFAULT,
 	CAMEL_CIPHER_HASH_MD2,
@@ -99,49 +120,57 @@ struct _CamelCipherValidity {
 	} encrypt;
 };
 
-typedef struct _CamelCipherContext {
-	CamelObject parent_object;
-
-	struct _CamelCipherContextPrivate *priv;
+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;
-} CamelCipherContext;
-
-typedef struct _CamelCipherContextClass {
-	CamelObjectClass parent_class;
 
-	CamelCipherHash	      (*id_to_hash)(CamelCipherContext *context, const gchar *id);
-	const gchar *	      (*hash_to_id)(CamelCipherContext *context, CamelCipherHash hash);
-
-	gint                   (*sign)      (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash,
-					    struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex);
-
-	CamelCipherValidity * (*verify)    (CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex);
-
-	gint                   (*encrypt)   (CamelCipherContext *context, const gchar *userid,
-					    GPtrArray *recipients, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
-					    CamelException *ex);
-
-	CamelCipherValidity  *(*decrypt)  (CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
-					   CamelException *ex);
-
-	gint                   (*import_keys) (CamelCipherContext *context, struct _CamelStream *istream,
-					      CamelException *ex);
-
-	gint                   (*export_keys) (CamelCipherContext *context, GPtrArray *keys,
-					      struct _CamelStream *ostream, CamelException *ex);
-} CamelCipherContextClass;
-
-CamelType            camel_cipher_context_get_type (void);
-
-CamelCipherContext  *camel_cipher_context_new (CamelSession *session);
+	CamelCipherHash	(*id_to_hash)		(CamelCipherContext *context,
+						 const gchar *id);
+	const gchar *	(*hash_to_id)		(CamelCipherContext *context,
+						 CamelCipherHash hash);
+	gint		(*sign)			(CamelCipherContext *context,
+						 const gchar *userid,
+						 CamelCipherHash hash,
+						 CamelMimePart *ipart,
+						 CamelMimePart *opart,
+						 CamelException *ex);
+	CamelCipherValidity *
+			(*verify)		(CamelCipherContext *context,
+						 CamelMimePart *ipart,
+						 CamelException *ex);
+	gint		(*encrypt)		(CamelCipherContext *context,
+						 const gchar *userid,
+						 GPtrArray *recipients,
+						 CamelMimePart *ipart,
+						 CamelMimePart *opart,
+						 CamelException *ex);
+	CamelCipherValidity *
+			(*decrypt)		(CamelCipherContext *context,
+						 CamelMimePart *ipart,
+						 CamelMimePart *opart,
+						 CamelException *ex);
+	gint		(*import_keys)		(CamelCipherContext *context,
+						 CamelStream *istream,
+						 CamelException *ex);
+	gint		(*export_keys)		(CamelCipherContext *context,
+						 GPtrArray *keys,
+						 CamelStream *ostream,
+						 CamelException *ex);
+};
 
-void                 camel_cipher_context_construct (CamelCipherContext *context, CamelSession *session);
+GType		camel_cipher_context_get_type	(void);
+CamelCipherContext *
+		camel_cipher_context_new	(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);
@@ -154,19 +183,19 @@ const gchar *	     camel_cipher_hash_to_id (CamelCipherContext *context, CamelCi
 
 /* cipher routines */
 gint                  camel_cipher_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash,
-					struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex);
-CamelCipherValidity *camel_cipher_verify (CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex);
+					CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex);
+CamelCipherValidity *camel_cipher_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *ex);
 gint                  camel_cipher_encrypt (CamelCipherContext *context, const gchar *userid,
-					   GPtrArray *recipients, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
+					   GPtrArray *recipients, CamelMimePart *ipart, CamelMimePart *opart,
 					   CamelException *ex);
-CamelCipherValidity *camel_cipher_decrypt (CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart,
+CamelCipherValidity *camel_cipher_decrypt (CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *opart,
 					   CamelException *ex);
 
 /* key/certificate routines */
-gint                  camel_cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream,
+gint                  camel_cipher_import_keys (CamelCipherContext *context, CamelStream *istream,
 					       CamelException *ex);
 gint                  camel_cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
-					       struct _CamelStream *ostream, CamelException *ex);
+					       CamelStream *ostream, CamelException *ex);
 
 /* CamelCipherValidity utility functions */
 CamelCipherValidity *camel_cipher_validity_new (void);
diff --git a/camel/camel-data-cache.c b/camel/camel-data-cache.c
index 09be951..7d50bcc 100644
--- a/camel/camel-data-cache.c
+++ b/camel/camel-data-cache.c
@@ -33,7 +33,6 @@
 #include <alloca.h>
 #endif
 
-#include <glib.h>
 #include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 
@@ -56,69 +55,137 @@ extern gint camel_verbose_debug;
    once an hour should be enough */
 #define CAMEL_DATA_CACHE_CYCLE_TIME (60*60)
 
+#define CAMEL_DATA_CACHE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_DATA_CACHE, CamelDataCachePrivate))
+
 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;
+enum {
+	PROP_0,
+	PROP_PATH
+};
+
+static gpointer parent_class;
 
-static void data_cache_class_init(CamelDataCacheClass *klass)
+static void
+data_cache_set_property (GObject *object,
+                         guint property_id,
+                         const GValue *value,
+                         GParamSpec *pspec)
 {
-	camel_data_cache_parent = (CamelObject *)camel_object_get_type ();
-
-#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
+	switch (property_id) {
+		case PROP_PATH:
+			camel_data_cache_set_path (
+				CAMEL_DATA_CACHE (object),
+				g_value_get_string (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
-static void data_cache_init(CamelDataCache *cdc, CamelDataCacheClass *klass)
+static void
+data_cache_get_property (GObject *object,
+                         guint property_id,
+                         GValue *value,
+                         GParamSpec *pspec)
 {
-	struct _CamelDataCachePrivate *p;
+	switch (property_id) {
+		case PROP_PATH:
+			g_value_set_string (
+				value, camel_data_cache_get_path (
+				CAMEL_DATA_CACHE (object)));
+			return;
+	}
 
-	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);
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
-static void data_cache_finalise(CamelDataCache *cdc)
+static void
+data_cache_finalize (GObject *object)
 {
-	struct _CamelDataCachePrivate *p;
+	CamelDataCachePrivate *priv;
+
+	priv = CAMEL_DATA_CACHE_GET_PRIVATE (object);
 
-	p = cdc->priv;
-	camel_object_bag_destroy(p->busy_bag);
-	g_free(p);
+	camel_object_bag_destroy (priv->busy_bag);
+	g_free (priv->path);
 
-	g_free (cdc->path);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
-CamelType
-camel_data_cache_get_type(void)
+static void
+data_cache_class_init (CamelDataCacheClass *class)
 {
-	static CamelType camel_data_cache_type = CAMEL_INVALID_TYPE;
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelDataCachePrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = data_cache_set_property;
+	object_class->get_property = data_cache_get_property;
+	object_class->finalize = data_cache_finalize;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_PATH,
+		g_param_spec_string (
+			"path",
+			"Path",
+			NULL,
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT));
+}
 
-	if (camel_data_cache_type == CAMEL_INVALID_TYPE) {
-		camel_data_cache_type = camel_type_register(
-			CAMEL_OBJECT_TYPE, "CamelDataCache",
-			sizeof (CamelDataCache),
+static void
+data_cache_init (CamelDataCache *data_cache)
+{
+	CamelObjectBag *busy_bag;
+
+	busy_bag = camel_object_bag_new (
+		g_str_hash, g_str_equal,
+		(CamelCopyFunc) g_strdup,
+		(GFreeFunc) g_free);
+
+	data_cache->priv = CAMEL_DATA_CACHE_GET_PRIVATE (data_cache);
+	data_cache->priv->busy_bag = busy_bag;
+	data_cache->priv->expire_age = -1;
+	data_cache->priv->expire_access = -1;
+}
+
+GType
+camel_data_cache_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT, "CamelDataCache",
 			sizeof (CamelDataCacheClass),
-			(CamelObjectClassInitFunc) data_cache_class_init,
-			NULL,
-			(CamelObjectInitFunc) data_cache_init,
-			(CamelObjectFinalizeFunc) data_cache_finalise);
-	}
+			(GClassInitFunc) data_cache_class_init,
+			sizeof (CamelDataCache),
+			(GInstanceInitFunc) data_cache_init,
+			0);
 
-	return camel_data_cache_type;
+	return type;
 }
 
 /**
  * camel_data_cache_new:
  * @path: Base path of cache, subdirectories will be created here.
- * @flags: Open flags, none defined.
  * @ex:
  *
  * Create a new data cache.
@@ -127,9 +194,10 @@ camel_data_cache_get_type(void)
  * be written to.
  **/
 CamelDataCache *
-camel_data_cache_new(const gchar *path, guint32 flags, CamelException *ex)
+camel_data_cache_new (const gchar *path,
+                      CamelException *ex)
 {
-	CamelDataCache *cdc;
+	g_return_val_if_fail (path != NULL, NULL);
 
 	if (g_mkdir_with_parents (path, 0700) == -1) {
 		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
@@ -137,14 +205,28 @@ camel_data_cache_new(const gchar *path, guint32 flags, CamelException *ex)
 		return NULL;
 	}
 
-	cdc = (CamelDataCache *)camel_object_new(CAMEL_DATA_CACHE_TYPE);
+	return g_object_new (CAMEL_TYPE_DATA_CACHE, "path", path, NULL);
+}
+
+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);
 
-	cdc->path = g_strdup(path);
-	cdc->flags = flags;
-	cdc->expire_age = -1;
-	cdc->expire_access = -1;
+	g_free (cdc->priv->path);
+	cdc->priv->path = g_strdup (path);
 
-	return cdc;
+	g_object_notify (G_OBJECT (cdc), "path");
 }
 
 /**
@@ -165,7 +247,7 @@ camel_data_cache_new(const gchar *path, guint32 flags, CamelException *ex)
 void
 camel_data_cache_set_expire_age(CamelDataCache *cdc, time_t when)
 {
-	cdc->expire_age = when;
+	cdc->priv->expire_age = when;
 }
 
 /**
@@ -186,7 +268,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
@@ -211,14 +293,14 @@ data_cache_expire(CamelDataCache *cdc, const gchar *path, const gchar *keep, tim
 		dd(printf("Checking '%s' for expiry\n", s->str));
 		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))) {
 			dd(printf("Has expired!  Removing!\n"));
 			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);
+				g_object_unref (stream);
 			}
 		}
 	}
@@ -238,8 +320,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) {
@@ -248,7 +330,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;
 
 		dd(printf("Checking expire cycle time on dir '%s'\n", dir));
@@ -301,7 +383,7 @@ camel_data_cache_add(CamelDataCache *cdc, const gchar *path, const gchar *key, C
 		if (stream) {
 			g_unlink(real);
 			camel_object_bag_remove(cdc->priv->busy_bag, stream);
-			camel_object_unref(stream);
+			g_object_unref (stream);
 		}
 	} while (stream != NULL);
 
@@ -393,7 +475,7 @@ 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);
+		g_object_unref (stream);
 	}
 
 	/* maybe we were a mem stream */
diff --git a/camel/camel-data-cache.h b/camel/camel-data-cache.h
index e4c0688..cc10b1d 100644
--- a/camel/camel-data-cache.h
+++ b/camel/camel-data-cache.h
@@ -20,75 +20,84 @@
  * USA
  */
 
-#ifndef CAMEL_DATA_CACHE_H
-#define CAMEL_DATA_CACHE_H 1
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
 
-#include <glib.h>
+#ifndef CAMEL_DATA_CACHE_H
+#define CAMEL_DATA_CACHE_H
 
 #include <camel/camel-stream.h>
 #include <camel/camel-exception.h>
 
-#define CAMEL_DATA_CACHE_TYPE     (camel_data_cache_get_type ())
-#define CAMEL_DATA_CACHE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_DATA_CACHE_TYPE, CamelFolder))
-#define CAMEL_DATA_CACHE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_DATA_CACHE_TYPE, CamelFolderClass))
-#define CAMEL_IS_DATA_CACHE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_DATA_CACHE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_DATA_CACHE \
+	(camel_data_cache_get_type ())
+#define CAMEL_DATA_CACHE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DATA_CACHE, CamelDataCache))
+#define CAMEL_DATA_CACHE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DATA_CACHE, CamelDataCacheClass))
+#define CAMEL_IS_DATA_CACHE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DATA_CACHE))
+#define CAMEL_IS_DATA_CACHE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DATA_CACHE))
+#define CAMEL_DATA_CACHE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DATA_CACHE, CamelDataCacheClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelDataCache CamelDataCache;
 typedef struct _CamelDataCacheClass CamelDataCacheClass;
+typedef struct _CamelDataCachePrivate CamelDataCachePrivate;
 
 struct _CamelDataCache {
-	CamelObject parent_object;
-
-	struct _CamelDataCachePrivate *priv;
-
-	gchar *path;
-	guint32 flags;
-
-	time_t expire_age;
-	time_t expire_access;
+	CamelObject parent;
+	CamelDataCachePrivate *priv;
 };
 
 struct _CamelDataCacheClass {
 	CamelObjectClass parent_class;
-
-	/* None are virtual yet */
-#if 0
-	/* Virtual methods */
-	CamelStream *(*add)(CamelDataCache *cmc, const gchar *path, const gchar *key, CamelException *ex);
-	CamelStream *(*get)(CamelDataCache *cmc, const gchar *path, const gchar *key, CamelException *ex);
-	gint (*close)(CamelDataCache *cmc, CamelStream *stream, CamelException *ex);
-	gint (*remove)(CamelDataCache *cmc, const gchar *path, const gchar *key, CamelException *ex);
-
-	gint (*clear)(CamelDataCache *cmc, const gchar *path, CamelException *ex);
-#endif
 };
 
-/* public methods */
-CamelDataCache *camel_data_cache_new(const gchar *path, guint32 flags, CamelException *ex);
-
-void camel_data_cache_set_expire_age(CamelDataCache *cdc, time_t when);
-void camel_data_cache_set_expire_access(CamelDataCache *cdc, time_t when);
-
-gint             camel_data_cache_rename(CamelDataCache *cache,
-					const gchar *old, const gchar *new, CamelException *ex);
-
-CamelStream    *camel_data_cache_add(CamelDataCache *cdc,
-				     const gchar *path, const gchar *key, CamelException *ex);
-CamelStream    *camel_data_cache_get(CamelDataCache *cdc,
-				     const gchar *path, const gchar *key, CamelException *ex);
-gint             camel_data_cache_remove(CamelDataCache *cdc,
-					const gchar *path, const gchar *key, CamelException *ex);
-
-gint             camel_data_cache_clear(CamelDataCache *cache,
-				       const gchar *path, CamelException *ex);
-
-gchar *         camel_data_cache_get_filename(CamelDataCache *cdc,
-					      const gchar *path, const gchar *key, CamelException *ex);
-
-/* Standard Camel function */
-CamelType camel_data_cache_get_type (void);
+GType		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
+						(CamelDataCache *cdc,
+						 time_t when);
+gint		camel_data_cache_rename		(CamelDataCache *cache,
+						 const gchar *old,
+						 const gchar *new,
+						 CamelException *ex);
+CamelStream *	camel_data_cache_add		(CamelDataCache *cdc,
+						 const gchar *path,
+						 const gchar *key,
+						 CamelException *ex);
+CamelStream *	camel_data_cache_get		(CamelDataCache *cdc,
+						 const gchar *path,
+						 const gchar *key,
+						 CamelException *ex);
+gint		camel_data_cache_remove		(CamelDataCache *cdc,
+						 const gchar *path,
+						 const gchar *key,
+						 CamelException *ex);
+gint		camel_data_cache_clear		(CamelDataCache *cache,
+						 const gchar *path,
+						 CamelException *ex);
+gchar *		camel_data_cache_get_filename	(CamelDataCache *cdc,
+						 const gchar *path,
+						 const gchar *key,
+						 CamelException *ex);
 
 G_END_DECLS
 
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c
index 252dc14..af28b2a 100644
--- a/camel/camel-data-wrapper.c
+++ b/camel/camel-data-wrapper.c
@@ -36,10 +36,11 @@
 
 #define d(x)
 
-static CamelObjectClass *parent_class = NULL;
+#define CAMEL_DATA_WRAPPER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_DATA_WRAPPER, CamelDataWrapperPrivate))
 
-/* Returns the class for a CamelDataWrapper */
-#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static gint construct_from_stream(CamelDataWrapper *, CamelStream *);
 static gssize write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
@@ -51,65 +52,84 @@ static void set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentTyp
 static gboolean is_offline (CamelDataWrapper *data_wrapper);
 
 static void
-camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class)
+data_wrapper_dispose (GObject *object)
 {
-	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;
+	CamelDataWrapper *data_wrapper = CAMEL_DATA_WRAPPER (object);
+
+	if (data_wrapper->mime_type != NULL) {
+		camel_content_type_unref (data_wrapper->mime_type);
+		data_wrapper->mime_type = NULL;
+	}
+
+	if (data_wrapper->stream != NULL) {
+		g_object_unref (data_wrapper->stream);
+		data_wrapper->stream = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_data_wrapper_init (gpointer object, gpointer klass)
+data_wrapper_finalize (GObject *object)
 {
-	CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
+	CamelDataWrapper *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);
+	pthread_mutex_destroy (&data_wrapper->priv->stream_lock);
 
-	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;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_data_wrapper_finalize (CamelObject *object)
+data_wrapper_class_init (CamelDataWrapperClass *class)
 {
-	CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
-
-	pthread_mutex_destroy (&camel_data_wrapper->priv->stream_lock);
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelDataWrapperPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = data_wrapper_dispose;
+	object_class->finalize = data_wrapper_finalize;
+
+	class->write_to_stream = write_to_stream;
+	class->decode_to_stream = decode_to_stream;
+	class->set_mime_type = set_mime_type;
+	class->get_mime_type = get_mime_type;
+	class->get_mime_type_field = get_mime_type_field;
+	class->set_mime_type_field = set_mime_type_field;
+	class->construct_from_stream = construct_from_stream;
+	class->is_offline = is_offline;
+}
 
-	g_free (camel_data_wrapper->priv);
+static void
+data_wrapper_init (CamelDataWrapper *data_wrapper)
+{
+	data_wrapper->priv = CAMEL_DATA_WRAPPER_GET_PRIVATE (data_wrapper);
 
-	if (camel_data_wrapper->mime_type)
-		camel_content_type_unref (camel_data_wrapper->mime_type);
+	pthread_mutex_init (&data_wrapper->priv->stream_lock, NULL);
 
-	if (camel_data_wrapper->stream)
-		camel_object_unref (camel_data_wrapper->stream);
+	data_wrapper->mime_type = camel_content_type_new (
+		"application", "octet-stream");
+	data_wrapper->encoding = CAMEL_TRANSFER_ENCODING_DEFAULT;
+	data_wrapper->offline = FALSE;
 }
 
-CamelType
+GType
 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);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelDataWrapper",
+			sizeof (CamelDataWrapperClass),
+			(GClassInitFunc) data_wrapper_class_init,
+			sizeof (CamelDataWrapper),
+			(GInstanceInitFunc) data_wrapper_init,
+			0);
 
 	return type;
 }
@@ -124,7 +144,7 @@ camel_data_wrapper_get_type (void)
 CamelDataWrapper *
 camel_data_wrapper_new (void)
 {
-	return (CamelDataWrapper *) camel_object_new (CAMEL_DATA_WRAPPER_TYPE);
+	return g_object_new (CAMEL_TYPE_DATA_WRAPPER, NULL);
 }
 
 static gssize
@@ -163,12 +183,17 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
  **/
 gssize
 camel_data_wrapper_write_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)->write_to_stream (data_wrapper, stream);
+	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);
 }
 
 static gssize
@@ -178,23 +203,23 @@ decode_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
 	CamelStream *fstream;
 	gssize ret;
 
-	fstream = (CamelStream *) camel_stream_filter_new_with_stream (stream);
+	fstream = camel_stream_filter_new (stream);
 
 	switch (data_wrapper->encoding) {
 	case CAMEL_TRANSFER_ENCODING_BASE64:
-		filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (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);
+		g_object_unref (filter);
 		break;
 	case CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE:
-		filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (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);
+		g_object_unref (filter);
 		break;
 	case CAMEL_TRANSFER_ENCODING_UUENCODE:
-		filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (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);
+		g_object_unref (filter);
 		break;
 	default:
 		break;
@@ -204,12 +229,12 @@ decode_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
 		filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_DECODE,
 						     CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
 		camel_stream_filter_add (CAMEL_STREAM_FILTER (fstream), filter);
-		camel_object_unref (filter);
+		g_object_unref (filter);
 	}
 
 	ret = camel_data_wrapper_write_to_stream (data_wrapper, fstream);
 	camel_stream_flush (fstream);
-	camel_object_unref (fstream);
+	g_object_unref (fstream);
 
 	return ret;
 }
@@ -225,22 +250,27 @@ 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);
+
+	return class->decode_to_stream (data_wrapper, stream);
 }
 
 static gint
 construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
 {
 	if (data_wrapper->stream)
-		camel_object_unref (data_wrapper->stream);
+		g_object_unref (data_wrapper->stream);
 
 	data_wrapper->stream = stream;
-	camel_object_ref (stream);
+	g_object_ref (stream);
 	return 0;
 }
 
@@ -255,12 +285,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);
+
+	return class->construct_from_stream (data_wrapper, stream);
 }
 
 static void
@@ -286,12 +321,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);
+
+	class->set_mime_type (data_wrapper, mime_type);
 }
 
 static gchar *
@@ -309,9 +349,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);
+
+	return class->get_mime_type (data_wrapper);
 }
 
 static CamelContentType *
@@ -329,9 +374,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);
+
+	return class->get_mime_type_field (data_wrapper);
 }
 
 static void
@@ -355,12 +405,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);
+
+	class->set_mime_type_field (data_wrapper, mime_type);
 }
 
 static gboolean
@@ -380,5 +435,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 c1a33a7..5ed47eb 100644
--- a/camel/camel-data-wrapper.h
+++ b/camel/camel-data-wrapper.h
@@ -22,24 +22,47 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DATA_WRAPPER_H
-#define CAMEL_DATA_WRAPPER_H 1
+#define CAMEL_DATA_WRAPPER_H
 
-#include <glib.h>
 #include <sys/types.h>
+
 #include <camel/camel-object.h>
 #include <camel/camel-mime-utils.h>
-
-#define CAMEL_DATA_WRAPPER_TYPE     (camel_data_wrapper_get_type ())
-#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))
+#include <camel/camel-stream.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_DATA_WRAPPER \
+	(camel_data_wrapper_get_type ())
+#define CAMEL_DATA_WRAPPER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DATA_WRAPPER, CamelDataWrapper))
+#define CAMEL_DATA_WRAPPER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DATA_WRAPPER, CamelDataWrapperClass))
+#define CAMEL_IS_DATA_WRAPPER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DATA_WRAPPER))
+#define CAMEL_IS_DATA_WRAPPER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DATA_WRAPPER))
+#define CAMEL_DATA_WRAPPER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DATA_WRAPPER, CamelDataWrapperClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelDataWrapper CamelDataWrapper;
+typedef struct _CamelDataWrapperClass CamelDataWrapperClass;
+typedef struct _CamelDataWrapperPrivate CamelDataWrapperPrivate;
+
 struct _CamelDataWrapper {
-	CamelObject parent_object;
-	struct _CamelDataWrapperPrivate *priv;
+	CamelObject parent;
+	CamelDataWrapperPrivate *priv;
 
 	CamelTransferEncoding encoding;
 
@@ -49,7 +72,7 @@ struct _CamelDataWrapper {
 	guint offline:1;
 };
 
-typedef struct {
+struct _CamelDataWrapperClass {
 	CamelObjectClass parent_class;
 
 	/* Virtual methods */
@@ -70,10 +93,9 @@ typedef struct {
 						       CamelStream *);
 
 	gboolean            (*is_offline)             (CamelDataWrapper *data_wrapper);
-} CamelDataWrapperClass;
+};
 
-/* Standard Camel function */
-CamelType camel_data_wrapper_get_type (void);
+GType camel_data_wrapper_get_type (void);
 
 /* public methods */
 CamelDataWrapper *camel_data_wrapper_new(void);
diff --git a/camel/camel-db.c b/camel/camel-db.c
index 53dba96..87aeced 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -31,7 +31,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-debug.h"
@@ -402,6 +401,8 @@ camel_db_open (const gchar *path, CamelException *ex)
 
 	g_once (&vfs_once, (GThreadFunc) init_sqlite_vfs, NULL);
 
+	g_once (&vfs_once, (GThreadFunc) init_sqlite_vfs, NULL);
+
 	CAMEL_DB_USE_SHARED_CACHE;
 
 	ret = sqlite3_open(path, &db);
diff --git a/camel/camel-db.h b/camel/camel-db.h
index dfd3a73..885cff7 100644
--- a/camel/camel-db.h
+++ b/camel/camel-db.h
@@ -1,7 +1,12 @@
 /* Srinivasa Ragavan - <sragavan novell com> - GPL v2 or later */
 
-#ifndef __CAMEL_DB_H
-#define __CAMEL_DB_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_DB_H
+#define CAMEL_DB_H
+
 #include <sqlite3.h>
 #include <glib.h>
 
diff --git a/camel/camel-debug.c b/camel/camel-debug.c
index 91cf5cf..e75a59f 100644
--- a/camel/camel-debug.c
+++ b/camel/camel-debug.c
@@ -33,7 +33,7 @@ gint camel_verbose_debug;
 static GHashTable *debug_table = NULL;
 
 /**
- * camel_debug_init:
+ * debug_init:
  * @void:
  *
  * Init camel debug.  Maintain legacy CAMEL_VERBOSE_DEBUG as well as the
@@ -47,7 +47,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-debug.h b/camel/camel-debug.h
index ef1c202..a1fb7ba 100644
--- a/camel/camel-debug.h
+++ b/camel/camel-debug.h
@@ -19,8 +19,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DEBUG_H
-#define CAMEL_DEBUG_H 1
+#define CAMEL_DEBUG_H
 
 #include <glib.h>
 
diff --git a/camel/camel-digest-folder.c b/camel/camel-digest-folder.c
index 6886312..158f8b9 100644
--- a/camel/camel-digest-folder.c
+++ b/camel/camel-digest-folder.c
@@ -34,7 +34,9 @@
 
 #define d(x)
 
-#define _PRIVATE(o) (((CamelDigestFolder *)(o))->priv)
+#define CAMEL_DIGEST_FOLDER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_DIGEST_FOLDER, CamelDigestFolderPrivate))
 
 struct _CamelDigestFolderPrivate {
 	CamelMimeMessage *message;
@@ -45,7 +47,7 @@ struct _CamelDigestFolderPrivate {
 #define CAMEL_DIGEST_FOLDER_LOCK(f, l) (g_mutex_lock(((CamelDigestFolder *)f)->priv->l))
 #define CAMEL_DIGEST_FOLDER_UNLOCK(f, l) (g_mutex_unlock(((CamelDigestFolder *)f)->priv->l))
 
-static CamelFolderClass *parent_class = NULL;
+static gpointer parent_class;
 
 static void digest_refresh_info (CamelFolder *folder, CamelException *ex);
 static void digest_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
@@ -70,81 +72,101 @@ static GPtrArray *digest_search_by_uids (CamelFolder *folder, const gchar *expre
 static void digest_search_free (CamelFolder *folder, GPtrArray *result);
 
 static void
-camel_digest_folder_class_init (CamelDigestFolderClass *camel_digest_folder_class)
+digest_dispose (GObject *object)
 {
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_digest_folder_class);
+	CamelDigestFolderPrivate *priv;
+	CamelFolder *folder;
 
-	parent_class = CAMEL_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_folder_get_type ()));
+	folder = CAMEL_FOLDER (object);
+	priv = CAMEL_DIGEST_FOLDER_GET_PRIVATE (object);
 
-	/* virtual method definition */
+	if (folder->summary != NULL) {
+		g_object_unref (folder->summary);
+		folder->summary = NULL;
+	}
 
-	/* virtual method overload */
-	camel_folder_class->refresh_info = digest_refresh_info;
-	camel_folder_class->sync = digest_sync;
-	camel_folder_class->expunge = digest_expunge;
-	camel_folder_class->get_full_name = digest_get_full_name;
+	if (priv->message != NULL) {
+		g_object_unref (priv->message);
+		priv->message = NULL;
+	}
 
-	camel_folder_class->get_message = digest_get_message;
-	camel_folder_class->append_message = digest_append_message;
-	camel_folder_class->transfer_messages_to = digest_transfer_messages_to;
+	if (priv->search != NULL) {
+		g_object_unref (priv->search);
+		priv->search = NULL;
+	}
 
-	camel_folder_class->search_by_expression = digest_search_by_expression;
-	camel_folder_class->search_by_uids = digest_search_by_uids;
-	camel_folder_class->search_free = digest_search_free;
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_digest_folder_init (gpointer object, gpointer klass)
+digest_finalize (GObject *object)
 {
-	CamelDigestFolder *digest_folder = CAMEL_DIGEST_FOLDER (object);
-	CamelFolder *folder = CAMEL_FOLDER (object);
+	CamelDigestFolderPrivate *priv;
 
-	folder->folder_flags |= CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
+	priv = CAMEL_DIGEST_FOLDER_GET_PRIVATE (object);
 
-	folder->summary = camel_digest_summary_new ();
+	g_mutex_free (priv->search_lock);
 
-	digest_folder->priv = g_new (struct _CamelDigestFolderPrivate, 1);
-	digest_folder->priv->message = NULL;
-	digest_folder->priv->search = NULL;
-	digest_folder->priv->search_lock = g_mutex_new ();
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-digest_finalize (CamelObject *object)
+digest_folder_class_init (CamelDigestFolderClass *class)
 {
-	CamelDigestFolder *digest_folder = CAMEL_DIGEST_FOLDER (object);
-	CamelFolder *folder = CAMEL_FOLDER (object);
-
-	if (folder->summary) {
-		camel_object_unref (folder->summary);
-		folder->summary = NULL;
-	}
+	GObjectClass *object_class;
+	CamelFolderClass *folder_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelDigestFolderPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = digest_dispose;
+	object_class->finalize = digest_finalize;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->refresh_info = digest_refresh_info;
+	folder_class->sync = digest_sync;
+	folder_class->expunge = digest_expunge;
+	folder_class->get_full_name = digest_get_full_name;
+	folder_class->get_message = digest_get_message;
+	folder_class->append_message = digest_append_message;
+	folder_class->transfer_messages_to = digest_transfer_messages_to;
+	folder_class->search_by_expression = digest_search_by_expression;
+	folder_class->search_by_uids = digest_search_by_uids;
+	folder_class->search_free = digest_search_free;
+}
 
-	camel_object_unref (digest_folder->priv->message);
+static void
+digest_folder_init (CamelDigestFolder *digest_folder)
+{
+	CamelFolder *folder = CAMEL_FOLDER (digest_folder);
 
-	if (digest_folder->priv->search)
-		camel_object_unref (digest_folder->priv->search);
+	folder->folder_flags |= CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
 
-	g_mutex_free (digest_folder->priv->search_lock);
+	folder->summary = camel_digest_summary_new ();
 
-	g_free (digest_folder->priv);
+	digest_folder->priv = CAMEL_DIGEST_FOLDER_GET_PRIVATE (digest_folder);
+	digest_folder->priv->message = NULL;
+	digest_folder->priv->search = NULL;
+	digest_folder->priv->search_lock = g_mutex_new ();
 }
 
-CamelType
+GType
 camel_digest_folder_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_FOLDER_TYPE,
-					    "CamelDigestFolder",
-					    sizeof (CamelDigestFolder),
-					    sizeof (CamelDigestFolderClass),
-					    (CamelObjectClassInitFunc) camel_digest_folder_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_digest_folder_init,
-					    (CamelObjectFinalizeFunc) digest_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER,
+			"CamelDigestFolder",
+			sizeof (CamelDigestFolderClass),
+			(GClassInitFunc) digest_folder_class_init,
+			sizeof (CamelDigestFolder),
+			(GInstanceInitFunc) digest_folder_init,
+			0);
 
 	return type;
 }
@@ -160,7 +182,7 @@ multipart_contains_message_parts (CamelMultipart *multipart)
 	parts = camel_multipart_get_number (multipart);
 	for (i = 0; i < parts && !has_message_parts; i++) {
 		part = camel_multipart_get_part (multipart, i);
-		wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+		wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
 		if (CAMEL_IS_MULTIPART (wrapper)) {
 			has_message_parts = multipart_contains_message_parts (CAMEL_MULTIPART (wrapper));
 		} else if (CAMEL_IS_MIME_MESSAGE (wrapper)) {
@@ -185,7 +207,7 @@ digest_add_multipart (CamelFolder *folder, CamelMultipart *multipart, const gcha
 		gchar *tmp;
 		part = camel_multipart_get_part (multipart, i);
 
-		wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+		wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
 
 		if (CAMEL_IS_MULTIPART (wrapper)) {
 			uid = g_strdup_printf ("%s%d.", preuid, i);
@@ -218,7 +240,7 @@ camel_digest_folder_new (CamelStore *parent_store, CamelMimeMessage *message)
 	CamelDataWrapper *wrapper;
 	CamelFolder *folder;
 
-	wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (message));
+	wrapper = camel_medium_get_content (CAMEL_MEDIUM (message));
 	if (!wrapper || !CAMEL_IS_MULTIPART (wrapper))
 		return NULL;
 
@@ -228,12 +250,12 @@ camel_digest_folder_new (CamelStore *parent_store, CamelMimeMessage *message)
 			return NULL;
 	}
 
-	folder = CAMEL_FOLDER (camel_object_new (camel_digest_folder_get_type ()));
+	folder = g_object_new (CAMEL_TYPE_DIGEST_FOLDER, NULL);
 	digest_folder = CAMEL_DIGEST_FOLDER (folder);
 
 	camel_folder_construct (folder, parent_store, "folder_name", "short_name");
 
-	camel_object_ref (message);
+	g_object_ref (message);
 	digest_folder->priv->message = message;
 
 	construct_summary (folder, CAMEL_MULTIPART (wrapper));
@@ -296,7 +318,7 @@ digest_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 	gint id;
 
 	part = CAMEL_MIME_PART (digest->priv->message);
-	wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+	wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
 
 	do {
 		id = strtoul (uid, &subuid, 10);
@@ -304,7 +326,7 @@ digest_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 			return NULL;
 
 		part = camel_multipart_get_part (CAMEL_MULTIPART (wrapper), id);
-		wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+		wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
 		uid = subuid + 1;
 	} while (*subuid == '.');
 
@@ -312,7 +334,7 @@ digest_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 		return NULL;
 
 	message = CAMEL_MIME_MESSAGE (wrapper);
-	camel_object_ref (message);
+	g_object_ref (message);
 
 	return message;
 }
diff --git a/camel/camel-digest-folder.h b/camel/camel-digest-folder.h
index 8fb310d..5ad36bb 100644
--- a/camel/camel-digest-folder.h
+++ b/camel/camel-digest-folder.h
@@ -20,41 +20,59 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
-#ifndef _CAMEL_DIGEST_FOLDER_H
-#define _CAMEL_DIGEST_FOLDER_H
+#ifndef CAMEL_DIGEST_FOLDER_H
+#define CAMEL_DIGEST_FOLDER_H
 
-#include <glib.h>
 #include <camel/camel-store.h>
 #include <camel/camel-folder.h>
 #include <camel/camel-mime-message.h>
 
-#define CAMEL_DIGEST_FOLDER(obj)         CAMEL_CHECK_CAST (obj, camel_digest_folder_get_type (), CamelDigestFolder)
-#define CAMEL_DIGEST_FOLDER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_digest_folder_get_type (), CamelDigestFolderClass)
-#define CAMEL_IS_DIGEST_FOLDER(obj)      CAMEL_CHECK_TYPE (obj, camel_digest_folder_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_DIGEST_FOLDER \
+	(camel_digest_folder_get_type ())
+#define CAMEL_DIGEST_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DIGEST_FOLDER, CamelDigestFolder))
+#define CAMEL_DIGEST_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DIGEST_FOLDER, CamelDigestFolderClass))
+#define CAMEL_IS_DIGEST_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DIGEST_FOLDER))
+#define CAMEL_IS_DIGEST_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DIGEST_FOLDER))
+#define CAMEL_DIGEST_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DIGEST_FOLDER, CamelDigestFolderClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelDigestFolder CamelDigestFolder;
 typedef struct _CamelDigestFolderClass CamelDigestFolderClass;
+typedef struct _CamelDigestFolderPrivate CamelDigestFolderPrivate;
 
 struct _CamelDigestFolder {
 	CamelFolder parent;
-
-	struct _CamelDigestFolderPrivate *priv;
+	CamelDigestFolderPrivate *priv;
 };
 
 struct _CamelDigestFolderClass {
 	CamelFolderClass parent_class;
-
 };
 
-CamelType    camel_digest_folder_get_type (void);
+GType    camel_digest_folder_get_type (void);
 
 CamelFolder *camel_digest_folder_new      (CamelStore *parent_store, CamelMimeMessage *message);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_DIGEST_FOLDER_H */
+#endif /* CAMEL_DIGEST_FOLDER_H */
 
 #endif /* CAMEL_DISABLE_DEPRECATED */
diff --git a/camel/camel-digest-store.c b/camel/camel-digest-store.c
index 925095c..b39092c 100644
--- a/camel/camel-digest-store.c
+++ b/camel/camel-digest-store.c
@@ -41,46 +41,24 @@ static CamelFolder *digest_get_junk  (CamelStore *store, CamelException *ex);
 
 static CamelFolderInfo *digest_get_folder_info (CamelStore *store, const gchar *top, guint32 flags, CamelException *ex);
 
-static void camel_digest_store_class_init (CamelDigestStoreClass *klass);
-static void camel_digest_store_init       (CamelDigestStore *obj);
-static void camel_digest_store_finalise   (CamelObject *obj);
-
 static gint digest_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
 static gint digest_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
 
-static CamelStoreClass *parent_class = NULL;
-
-CamelType
-camel_digest_store_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_store_get_type (),
-					    "CamelDigestStore",
-					    sizeof (CamelDigestStore),
-					    sizeof (CamelDigestStoreClass),
-					    (CamelObjectClassInitFunc) camel_digest_store_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_digest_store_init,
-					    (CamelObjectFinalizeFunc) camel_digest_store_finalise);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static void
-camel_digest_store_class_init (CamelDigestStoreClass *klass)
+digest_store_class_init (CamelDigestStoreClass *class)
 {
-	CamelObjectClass *object_class = (CamelObjectClass *) klass;
-	CamelStoreClass *store_class = (CamelStoreClass *) klass;
+	CamelObjectClass *camel_object_class;
+	CamelStoreClass *store_class;
 
-	parent_class = CAMEL_STORE_CLASS(camel_type_get_global_classfuncs (camel_store_get_type ()));
+	parent_class = g_type_class_peek_parent (class);
 
-	/* virtual method overload */
-	object_class->setv = digest_setv;
-	object_class->getv = digest_getv;
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->setv = digest_setv;
+	camel_object_class->getv = digest_getv;
 
+	store_class = CAMEL_STORE_CLASS (class);
 	store_class->get_folder = digest_get_folder;
 	store_class->rename_folder = digest_rename_folder;
 	store_class->delete_folder = digest_delete_folder;
@@ -92,18 +70,30 @@ camel_digest_store_class_init (CamelDigestStoreClass *klass)
 }
 
 static void
-camel_digest_store_init (CamelDigestStore *obj)
+digest_store_init (CamelDigestStore *digest_store)
 {
-	CamelStore *store = (CamelStore *) obj;
+	CamelStore *store = CAMEL_STORE (digest_store);
 
 	/* we dont want a vtrash and vjunk on this one */
 	store->flags &= ~(CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK);
 }
 
-static void
-camel_digest_store_finalise (CamelObject *obj)
+GType
+camel_digest_store_get_type (void)
 {
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE,
+			"CamelDigestStore",
+			sizeof (CamelDigestStoreClass),
+			(GClassInitFunc) digest_store_class_init,
+			sizeof (CamelDigestStore),
+			(GInstanceInitFunc) digest_store_init,
+			0);
 
+	return type;
 }
 
 static gint
@@ -138,7 +128,7 @@ camel_digest_store_new (const gchar *url)
 	if (!uri)
 		return NULL;
 
-	store = CAMEL_STORE (camel_object_new (camel_digest_store_get_type ()));
+	store = g_object_new (CAMEL_TYPE_DIGEST_STORE, NULL);
 	CAMEL_SERVICE (store)->url = uri;
 
 	return store;
diff --git a/camel/camel-digest-store.h b/camel/camel-digest-store.h
index 562c8ef..ea333e0 100644
--- a/camel/camel-digest-store.h
+++ b/camel/camel-digest-store.h
@@ -20,38 +20,55 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
-#ifndef __CAMEL_DIGEST_STORE_H__
-#define __CAMEL_DIGEST_STORE_H__
+#ifndef CAMEL_DIGEST_STORE_H
+#define CAMEL_DIGEST_STORE_H
 
-#include <glib.h>
 #include <camel/camel-store.h>
 
-#define CAMEL_DIGEST_STORE(obj)         CAMEL_CHECK_CAST (obj, camel_digest_store_get_type (), CamelDigestStore)
-#define CAMEL_DIGEST_STORE_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_digest_store_get_type (), CamelDigestStoreClass)
-#define CAMEL_IS_DIGEST_STORE(obj)      CAMEL_CHECK_TYPE (obj, camel_digest_store_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_DIGEST_STORE \
+	(camel_digest_store_get_type ())
+#define CAMEL_DIGEST_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DIGEST_STORE, CamelDigestStore))
+#define CAMEL_DIGEST_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DIGEST_STORE, CamelDigestStoreClass))
+#define CAMEL_IS_DIGEST_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DIGEST_STORE))
+#define CAMEL_IS_DIGEST_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DIGEST_STORE))
+#define CAMEL_DIGEST_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DIGEST_STORE, CamelDigestStoreClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelDigestStore CamelDigestStore;
 typedef struct _CamelDigestStoreClass CamelDigestStoreClass;
 
 struct _CamelDigestStore {
 	CamelStore parent;
-
 };
 
 struct _CamelDigestStoreClass {
 	CamelStoreClass parent_class;
-
 };
 
-CamelType camel_digest_store_get_type (void);
+GType camel_digest_store_get_type (void);
 
 CamelStore *camel_digest_store_new (const gchar *url);
 
 G_END_DECLS
 
-#endif /* __CAMEL_DIGEST_STORE_H__ */
+#endif /* CAMEL_DIGEST_STORE_H */
 
 #endif /* CAMEL_DISABLE_DEPRECATED */
diff --git a/camel/camel-digest-summary.c b/camel/camel-digest-summary.c
index 8d6731b..5be8335 100644
--- a/camel/camel-digest-summary.c
+++ b/camel/camel-digest-summary.c
@@ -28,59 +28,49 @@
 
 #define CAMEL_DIGEST_SUMMARY_VERSION 0
 
-static void camel_digest_summary_class_init (CamelDigestSummaryClass *klass);
-static void camel_digest_summary_init       (CamelDigestSummary *obj);
-static void camel_digest_summary_finalise   (CamelObject *obj);
-
-static CamelFolderSummaryClass *parent_class = NULL;
-
-CamelType
-camel_digest_summary_get_type(void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (
-			camel_folder_summary_get_type (),
-			"CamelDigestSummary",
-			sizeof (CamelDigestSummary),
-			sizeof (CamelDigestSummaryClass),
-			(CamelObjectClassInitFunc) camel_digest_summary_class_init,
-			NULL,
-			(CamelObjectInitFunc) camel_digest_summary_init,
-			(CamelObjectFinalizeFunc) camel_digest_summary_finalise);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static void
-camel_digest_summary_class_init (CamelDigestSummaryClass *klass)
+digest_summary_class_init (CamelDigestSummaryClass *class)
 {
-	parent_class = CAMEL_FOLDER_SUMMARY_CLASS (camel_type_get_global_classfuncs (camel_folder_summary_get_type ()));
+	parent_class = g_type_class_peek_parent (class);
 }
 
 static void
-camel_digest_summary_init (CamelDigestSummary *summary)
+digest_summary_init (CamelDigestSummary *digest_summary)
 {
-	CamelFolderSummary *s = (CamelFolderSummary *) summary;
+	CamelFolderSummary *summary;
+
+	summary = CAMEL_FOLDER_SUMMARY (digest_summary);
 
 	/* subclasses need to set the right instance data sizes */
-	s->message_info_size = sizeof (CamelMessageInfo);
-	s->content_info_size = sizeof (CamelMessageContentInfo);
+	summary->message_info_size = sizeof (CamelMessageInfo);
+	summary->content_info_size = sizeof (CamelMessageContentInfo);
 
 	/* and a unique file version */
-	s->version += CAMEL_DIGEST_SUMMARY_VERSION;
+	summary->version += CAMEL_DIGEST_SUMMARY_VERSION;
 }
 
-static void
-camel_digest_summary_finalise (CamelObject *object)
+GType
+camel_digest_summary_get_type(void)
 {
+	static GType type = G_TYPE_INVALID;
 
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER_SUMMARY,
+			"CamelDigestSummary",
+			sizeof (CamelDigestSummaryClass),
+			(GClassInitFunc) digest_summary_class_init,
+			sizeof (CamelDigestSummary),
+			(GInstanceInitFunc) digest_summary_init,
+			0);
+
+	return type;
 }
 
 CamelFolderSummary *
 camel_digest_summary_new (void)
 {
-	return (CamelFolderSummary *) camel_object_new (camel_digest_summary_get_type ());
+	return g_object_new (CAMEL_TYPE_DIGEST_SUMMARY, NULL);
 }
diff --git a/camel/camel-digest-summary.h b/camel/camel-digest-summary.h
index e2105cb..1b45bd4 100644
--- a/camel/camel-digest-summary.h
+++ b/camel/camel-digest-summary.h
@@ -20,40 +20,57 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
-#ifndef __CAMEL_DIGEST_SUMMARY_H__
-#define __CAMEL_DIGEST_SUMMARY_H__
+#ifndef CAMEL_DIGEST_SUMMARY_H
+#define CAMEL_DIGEST_SUMMARY_H
 
 #include <camel/camel-folder-summary.h>
 #include <camel/camel-folder.h>
 #include <camel/camel-exception.h>
 
-#define CAMEL_DIGEST_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_digest_summary_get_type (), CamelDigestSummary)
-#define CAMEL_DIGEST_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_digest_summary_get_type (), CamelDigestSummaryClass)
-#define CAMEL_IS_DIGEST_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_digest_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_DIGEST_SUMMARY \
+	(camel_digest_summary_get_type ())
+#define CAMEL_DIGEST_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DIGEST_SUMMARY, CamelDigestSummary))
+#define CAMEL_DIGEST_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DIGEST_SUMMARY, CamelDigestSummaryClass))
+#define CAMEL_IS_DIGEST_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DIGEST_SUMMARY))
+#define CAMEL_IS_DIGEST_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DIGEST_SUMMARY))
+#define CAMEL_DIGEST_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DIGEST_SUMMARY, CamelDigestSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelDigestSummary      CamelDigestSummary;
+typedef struct _CamelDigestSummary CamelDigestSummary;
 typedef struct _CamelDigestSummaryClass CamelDigestSummaryClass;
 
 struct _CamelDigestSummary {
-	CamelFolderSummary parent_object;
-
+	CamelFolderSummary parent;
 };
 
 struct _CamelDigestSummaryClass {
 	CamelFolderSummaryClass parent_class;
-
 };
 
-CamelType camel_digest_summary_get_type (void);
+GType camel_digest_summary_get_type (void);
 
 CamelFolderSummary *camel_digest_summary_new (void);
 
 G_END_DECLS
 
-#endif /* __CAMEL_DIGEST_SUMMARY_H__ */
+#endif /* CAMEL_DIGEST_SUMMARY_H */
 
 #endif /* CAMEL_DISABLE_DEPRECATED */
diff --git a/camel/camel-disco-diary.c b/camel/camel-disco-diary.c
index 19e1489..1ddffa9 100644
--- a/camel/camel-disco-diary.c
+++ b/camel/camel-disco-diary.c
@@ -29,7 +29,6 @@
 #include <stdio.h>
 #include <errno.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 
@@ -45,23 +44,12 @@
 
 #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 gpointer parent_class;
 
 static void
 unref_folder (gpointer key, gpointer value, gpointer data)
 {
-	camel_object_unref (value);
+	g_object_unref (value);
 }
 
 static void
@@ -72,37 +60,60 @@ free_uid (gpointer key, gpointer value, gpointer data)
 }
 
 static void
-camel_disco_diary_finalize (CamelDiscoDiary *diary)
+disco_diary_finalize (GObject *object)
 {
+	CamelDiscoDiary *diary = CAMEL_DISCO_DIARY (object);
+
 	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);
 	}
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+disco_diary_class_init (CamelDiscoDiaryClass *class)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = disco_diary_finalize;
+}
+
+static void
+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
+GType
 camel_disco_diary_get_type (void)
 {
-	static CamelType camel_disco_diary_type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (camel_disco_diary_type == CAMEL_INVALID_TYPE) {
-		camel_disco_diary_type = camel_type_register (
-			CAMEL_OBJECT_TYPE, "CamelDiscoDiary",
-			sizeof (CamelDiscoDiary),
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT, "CamelDiscoDiary",
 			sizeof (CamelDiscoDiaryClass),
-			(CamelObjectClassInitFunc) camel_disco_diary_class_init,
-			NULL,
-			(CamelObjectInitFunc) camel_disco_diary_init,
-			(CamelObjectFinalizeFunc) camel_disco_diary_finalize);
-	}
+			(GClassInitFunc) disco_diary_class_init,
+			sizeof (CamelDiscoDiary),
+			(GInstanceInitFunc) disco_diary_init,
+			0);
 
-	return camel_disco_diary_type;
+	return type;
 }
 
 static gint
@@ -276,7 +287,7 @@ close_folder (gpointer name, gpointer folder, gpointer data)
 {
 	g_free (name);
 	camel_folder_sync (folder, FALSE, NULL);
-	camel_object_unref (folder);
+	g_object_unref (folder);
 }
 
 void
@@ -414,7 +425,7 @@ camel_disco_diary_new (CamelDiscoStore *store, const gchar *filename, CamelExcep
 	g_return_val_if_fail (CAMEL_IS_DISCO_STORE (store), NULL);
 	g_return_val_if_fail (filename != NULL, NULL);
 
-	diary = CAMEL_DISCO_DIARY (camel_object_new (CAMEL_DISCO_DIARY_TYPE));
+	diary = g_object_new (CAMEL_TYPE_DISCO_DIARY, NULL);
 	diary->store = store;
 
 	d(printf("diary log file '%s'\n", filename));
@@ -433,7 +444,7 @@ camel_disco_diary_new (CamelDiscoStore *store, const gchar *filename, CamelExcep
 
 	diary->file = g_fopen (filename, "a+b");
 	if (!diary->file) {
-		camel_object_unref (diary);
+		g_object_unref (diary);
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      "Could not open journal file: %s",
 				      g_strerror (errno));
diff --git a/camel/camel-disco-diary.h b/camel/camel-disco-diary.h
index 4fff9ea..f32f120 100644
--- a/camel/camel-disco-diary.h
+++ b/camel/camel-disco-diary.h
@@ -21,22 +21,45 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
 #ifndef CAMEL_DISCO_DIARY_H
-#define CAMEL_DISCO_DIARY_H 1
+#define CAMEL_DISCO_DIARY_H
 
-#include "camel-object.h"
 #include <stdarg.h>
 #include <stdio.h>
 
-#define CAMEL_DISCO_DIARY_TYPE     (camel_disco_diary_get_type ())
-#define CAMEL_DISCO_DIARY(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_DISCO_DIARY_TYPE, CamelDiscoDiary))
-#define CAMEL_DISCO_DIARY_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_DISCO_DIARY_TYPE, CamelDiscoDiaryClass))
-#define CAMEL_IS_DISCO_DIARY(o)    (CAMEL_CHECK_TYPE((o), CAMEL_DISCO_DIARY_TYPE))
+#include <camel/camel-object.h>
+#include <camel/camel-disco-store.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_DISCO_DIARY \
+	(camel_disco_diary_get_type ())
+#define CAMEL_DISCO_DIARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DISCO_DIARY, CamelDiscoDiary))
+#define CAMEL_DISCO_DIARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DISCO_DIARY, CamelDiscoDiaryClass))
+#define CAMEL_IS_DISCO_DIARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DISCO_DIARY))
+#define CAMEL_IS_DISCO_DIARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DISCO_DIARY))
+#define CAMEL_DISCO_DIARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DISCO_DIARY, CamelDiscoDiaryClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelDiscoDiary CamelDiscoDiary;
+typedef struct _CamelDiscoDiaryClass CamelDiscoDiaryClass;
+
 typedef enum {
 	CAMEL_DISCO_DIARY_END = 0,
 
@@ -54,17 +77,16 @@ typedef enum {
 } CamelDiscoDiaryArgType;
 
 struct _CamelDiscoDiary {
-	CamelObject parent_object;
+	CamelObject parent;
 
 	CamelDiscoStore *store;
 	FILE *file;
 	GHashTable *folders, *uidmap;
 };
 
-typedef struct {
+struct _CamelDiscoDiaryClass {
 	CamelObjectClass parent_class;
-
-} CamelDiscoDiaryClass;
+};
 
 /* public methods */
 CamelDiscoDiary *camel_disco_diary_new    (CamelDiscoStore *store,
@@ -86,8 +108,7 @@ void        camel_disco_diary_uidmap_add    (CamelDiscoDiary *diary,
 const gchar *camel_disco_diary_uidmap_lookup (CamelDiscoDiary *diary,
 					     const gchar *uid);
 
-/* Standard Camel function */
-CamelType camel_disco_diary_get_type (void);
+GType camel_disco_diary_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/camel-disco-folder.c b/camel/camel-disco-folder.c
index b734115..4d40bb9 100644
--- a/camel/camel-disco-folder.c
+++ b/camel/camel-disco-folder.c
@@ -25,7 +25,6 @@
 #include <config.h>
 #endif
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-disco-folder.h"
@@ -33,10 +32,7 @@
 #include "camel-exception.h"
 #include "camel-session.h"
 
-#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (o)))
-#define CDF_CLASS(o) (CAMEL_DISCO_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (o)))
-
-static CamelFolderClass *parent_class = NULL;
+static gpointer parent_class;
 static GSList *disco_folder_properties;
 
 static CamelProperty disco_property_list[] = {
@@ -65,30 +61,6 @@ static void disco_prepare_for_offline (CamelDiscoFolder *disco_folder,
 				       const gchar *expression,
 				       CamelException *ex);
 
-static void
-camel_disco_folder_class_init (CamelDiscoFolderClass *camel_disco_folder_class)
-{
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_disco_folder_class);
-
-	parent_class = CAMEL_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_folder_get_type ()));
-
-	((CamelObjectClass *)camel_folder_class)->getv = disco_getv;
-	((CamelObjectClass *)camel_folder_class)->setv = disco_setv;
-
-	/* virtual method definition */
-	camel_disco_folder_class->cache_message = disco_cache_message;
-	camel_disco_folder_class->prepare_for_offline = disco_prepare_for_offline;
-	camel_disco_folder_class->refresh_info_online = disco_refresh_info_online;
-
-	/* virtual method overload */
-	camel_folder_class->refresh_info = disco_refresh_info;
-	camel_folder_class->sync = disco_sync;
-	camel_folder_class->expunge = disco_expunge;
-
-	camel_folder_class->append_message = disco_append_message;
-	camel_folder_class->transfer_messages_to = disco_transfer_messages_to;
-}
-
 struct _cdf_sync_msg {
 	CamelSessionThreadMsg msg;
 
@@ -129,7 +101,7 @@ cdf_sync_free(CamelSession *session, CamelSessionThreadMsg *mm)
 
 	if (m->changes)
 		camel_folder_change_info_free(m->changes);
-	camel_object_unref(m->folder);
+	g_object_unref (m->folder);
 }
 
 static CamelSessionThreadOps cdf_sync_ops = {
@@ -150,38 +122,67 @@ cdf_folder_changed(CamelFolder *folder, CamelFolderChangeInfo *changes, gpointer
 		m->changes = camel_folder_change_info_new();
 		camel_folder_change_info_cat(m->changes, changes);
 		m->folder = folder;
-		camel_object_ref(folder);
+		g_object_ref (folder);
 		camel_session_thread_queue(session, &m->msg, 0);
 	}
 }
 
 static void
-camel_disco_folder_init(CamelDiscoFolder *folder)
+disco_folder_class_init (CamelDiscoFolderClass *class)
 {
-	camel_object_hook_event(folder, "folder_changed", (CamelObjectEventHookFunc)cdf_folder_changed, NULL);
+	CamelObjectClass *camel_object_class;
+	CamelFolderClass *folder_class;
+	gint ii;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = disco_getv;
+	camel_object_class->setv = disco_setv;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->refresh_info = disco_refresh_info;
+	folder_class->sync = disco_sync;
+	folder_class->expunge = disco_expunge;
+	folder_class->append_message = disco_append_message;
+	folder_class->transfer_messages_to = disco_transfer_messages_to;
+
+	class->cache_message = disco_cache_message;
+	class->prepare_for_offline = disco_prepare_for_offline;
+	class->refresh_info_online = disco_refresh_info_online;
+
+	for (ii = 0; ii < G_N_ELEMENTS (disco_property_list); ii++) {
+		disco_property_list[ii].description =
+			_(disco_property_list[ii].description);
+		disco_folder_properties = g_slist_prepend (
+			disco_folder_properties, &disco_property_list[ii]);
+	}
 }
 
-CamelType
+static void
+disco_folder_init (CamelDiscoFolder *disco_folder)
+{
+	camel_object_hook_event (
+		disco_folder, "folder_changed",
+		(CamelObjectEventHookFunc) cdf_folder_changed, NULL);
+}
+
+GType
 camel_disco_folder_get_type (void)
 {
-	static CamelType camel_disco_folder_type = CAMEL_INVALID_TYPE;
-	gint i;
+	static GType type = G_TYPE_INVALID;
 
-	if (camel_disco_folder_type == CAMEL_INVALID_TYPE) {
-		camel_disco_folder_type = camel_type_register (
-			CAMEL_FOLDER_TYPE, "CamelDiscoFolder",
-			sizeof (CamelDiscoFolder),
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER,
+			"CamelDiscoFolder",
 			sizeof (CamelDiscoFolderClass),
-			(CamelObjectClassInitFunc)camel_disco_folder_class_init, NULL,
-			(CamelObjectInitFunc)camel_disco_folder_init, NULL);
-
-		for (i = 0; i < G_N_ELEMENTS (disco_property_list); i++) {
-			disco_property_list[i].description = _(disco_property_list[i].description);
-			disco_folder_properties = g_slist_prepend(disco_folder_properties, &disco_property_list[i]);
-		}
-	}
+			(GClassInitFunc) disco_folder_class_init,
+			sizeof (CamelDiscoFolder),
+			(GInstanceInitFunc) disco_folder_init,
+			0);
 
-	return camel_disco_folder_type;
+	return type;
 }
 
 static gint
@@ -266,7 +267,7 @@ disco_refresh_info (CamelFolder *folder, CamelException *ex)
 {
 	if (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store)) != CAMEL_DISCO_STORE_ONLINE)
 		return;
-	CDF_CLASS (folder)->refresh_info_online (folder, ex);
+	CAMEL_DISCO_FOLDER_GET_CLASS (folder)->refresh_info_online (folder, ex);
 }
 
 static void
@@ -284,15 +285,15 @@ disco_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 
 	switch (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store))) {
 	case CAMEL_DISCO_STORE_ONLINE:
-		sync = CDF_CLASS (folder)->sync_online;
+		sync = CAMEL_DISCO_FOLDER_GET_CLASS (folder)->sync_online;
 		break;
 
 	case CAMEL_DISCO_STORE_OFFLINE:
-		sync = CDF_CLASS (folder)->sync_offline;
+		sync = CAMEL_DISCO_FOLDER_GET_CLASS (folder)->sync_offline;
 		break;
 
 	case CAMEL_DISCO_STORE_RESYNCING:
-		sync = CDF_CLASS (folder)->sync_resyncing;
+		sync = CAMEL_DISCO_FOLDER_GET_CLASS (folder)->sync_resyncing;
 		break;
 	}
 
@@ -300,7 +301,7 @@ disco_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 		sync(folder, ex);
 	} else {
 		g_warning("Class '%s' doesn't implement CamelDiscoFolder:sync methods",
-			  ((CamelObject *)folder)->klass->name);
+			  G_OBJECT_TYPE_NAME (folder));
 	}
 }
 
@@ -315,15 +316,15 @@ disco_expunge_uids (CamelFolder *folder, GPtrArray *uids, CamelException *ex)
 
 	switch (camel_disco_store_status (disco)) {
 	case CAMEL_DISCO_STORE_ONLINE:
-		expunge_uids = CDF_CLASS (folder)->expunge_uids_online;
+		expunge_uids = CAMEL_DISCO_FOLDER_GET_CLASS (folder)->expunge_uids_online;
 		break;
 
 	case CAMEL_DISCO_STORE_OFFLINE:
-		expunge_uids = CDF_CLASS (folder)->expunge_uids_offline;
+		expunge_uids = CAMEL_DISCO_FOLDER_GET_CLASS (folder)->expunge_uids_offline;
 		break;
 
 	case CAMEL_DISCO_STORE_RESYNCING:
-		expunge_uids = CDF_CLASS (folder)->expunge_uids_resyncing;
+		expunge_uids = CAMEL_DISCO_FOLDER_GET_CLASS (folder)->expunge_uids_resyncing;
 		break;
 	}
 
@@ -331,7 +332,7 @@ disco_expunge_uids (CamelFolder *folder, GPtrArray *uids, CamelException *ex)
 		expunge_uids(folder, uids, ex);
 	} else {
 		g_warning("Class '%s' doesn't implement CamelDiscoFolder:expunge_uids methods",
-			  ((CamelObject *)folder)->klass->name);
+			  G_OBJECT_TYPE_NAME (folder));
 	}
 }
 
@@ -368,17 +369,17 @@ disco_append_message (CamelFolder *folder, CamelMimeMessage *message,
 
 	switch (camel_disco_store_status (disco)) {
 	case CAMEL_DISCO_STORE_ONLINE:
-		CDF_CLASS (folder)->append_online (folder, message, info,
+		CAMEL_DISCO_FOLDER_GET_CLASS (folder)->append_online (folder, message, info,
 						   appended_uid, ex);
 		break;
 
 	case CAMEL_DISCO_STORE_OFFLINE:
-		CDF_CLASS (folder)->append_offline (folder, message, info,
+		CAMEL_DISCO_FOLDER_GET_CLASS (folder)->append_offline (folder, message, info,
 						    appended_uid, ex);
 		break;
 
 	case CAMEL_DISCO_STORE_RESYNCING:
-		CDF_CLASS (folder)->append_resyncing (folder, message, info,
+		CAMEL_DISCO_FOLDER_GET_CLASS (folder)->append_resyncing (folder, message, info,
 						      appended_uid, ex);
 		break;
 	}
@@ -393,19 +394,19 @@ disco_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 
 	switch (camel_disco_store_status (disco)) {
 	case CAMEL_DISCO_STORE_ONLINE:
-		CDF_CLASS (source)->transfer_online (source, uids,
+		CAMEL_DISCO_FOLDER_GET_CLASS (source)->transfer_online (source, uids,
 						     dest, transferred_uids,
 						     delete_originals, ex);
 		break;
 
 	case CAMEL_DISCO_STORE_OFFLINE:
-		CDF_CLASS (source)->transfer_offline (source, uids,
+		CAMEL_DISCO_FOLDER_GET_CLASS (source)->transfer_offline (source, uids,
 						      dest, transferred_uids,
 						      delete_originals, ex);
 		break;
 
 	case CAMEL_DISCO_STORE_RESYNCING:
-		CDF_CLASS (source)->transfer_resyncing (source, uids,
+		CAMEL_DISCO_FOLDER_GET_CLASS (source)->transfer_resyncing (source, uids,
 							dest, transferred_uids,
 							delete_originals, ex);
 		break;
@@ -436,7 +437,7 @@ disco_cache_message (CamelDiscoFolder *disco_folder, const gchar *uid,
 		     CamelException *ex)
 {
 	g_warning ("CamelDiscoFolder::cache_message not implemented for '%s'",
-		   camel_type_to_name (CAMEL_OBJECT_GET_TYPE (disco_folder)));
+		   G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (disco_folder)));
 }
 
 /**
@@ -451,7 +452,7 @@ void
 camel_disco_folder_cache_message (CamelDiscoFolder *disco_folder,
 				  const gchar *uid, CamelException *ex)
 {
-	CDF_CLASS (disco_folder)->cache_message (disco_folder, uid, ex);
+	CAMEL_DISCO_FOLDER_GET_CLASS (disco_folder)->cache_message (disco_folder, uid, ex);
 }
 
 static void
@@ -510,5 +511,5 @@ camel_disco_folder_prepare_for_offline (CamelDiscoFolder *disco_folder,
 {
 	g_return_if_fail (CAMEL_IS_DISCO_FOLDER (disco_folder));
 
-	CDF_CLASS (disco_folder)->prepare_for_offline (disco_folder, expression, ex);
+	CAMEL_DISCO_FOLDER_GET_CLASS (disco_folder)->prepare_for_offline (disco_folder, expression, ex);
 }
diff --git a/camel/camel-disco-folder.h b/camel/camel-disco-folder.h
index 5279bf3..edea120 100644
--- a/camel/camel-disco-folder.h
+++ b/camel/camel-disco-folder.h
@@ -21,20 +21,41 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
 #ifndef CAMEL_DISCO_FOLDER_H
-#define CAMEL_DISCO_FOLDER_H 1
+#define CAMEL_DISCO_FOLDER_H
 
 #include "camel-folder.h"
 
-#define CAMEL_DISCO_FOLDER_TYPE     (camel_disco_folder_get_type ())
-#define CAMEL_DISCO_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_DISCO_FOLDER_TYPE, CamelDiscoFolder))
-#define CAMEL_DISCO_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_DISCO_FOLDER_TYPE, CamelDiscoFolderClass))
-#define CAMEL_IS_DISCO_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_DISCO_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_DISCO_FOLDER \
+	(camel_disco_folder_get_type ())
+#define CAMEL_DISCO_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DISCO_FOLDER, CamelDiscoFolder))
+#define CAMEL_DISCO_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DISCO_FOLDER, CamelDiscoFolderClass))
+#define CAMEL_IS_DISCO_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DISCO_FOLDER))
+#define CAMEL_IS_DISCO_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DISCO_FOLDER))
+#define CAMEL_DISCO_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DISCO_FOLDER, CamelDiscoFolderClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelDiscoFolder CamelDiscoFolder;
+typedef struct _CamelDiscoFolderClass CamelDiscoFolderClass;
+
 enum {
 	CAMEL_DISCO_FOLDER_ARG_OFFLINE_SYNC = CAMEL_FOLDER_ARG_LAST,
 	CAMEL_DISCO_FOLDER_ARG_LAST = CAMEL_FOLDER_ARG_LAST + 0x100
@@ -45,12 +66,12 @@ enum {
 };
 
 struct _CamelDiscoFolder {
-	CamelFolder parent_object;
+	CamelFolder parent;
 
 	guint offline_sync:1;
 };
 
-typedef struct {
+struct _CamelDiscoFolderClass {
 	CamelFolderClass parent_class;
 
 	void (*refresh_info_online) (CamelFolder *folder, CamelException *ex);
@@ -106,7 +127,7 @@ typedef struct {
 
 	void (*update_uid) (CamelFolder *folder, const gchar *old_uid,
 			    const gchar *new_uid);
-} CamelDiscoFolderClass;
+};
 
 /* public methods */
 void camel_disco_folder_expunge_uids (CamelFolder *folder, GPtrArray *uids,
@@ -119,8 +140,7 @@ void camel_disco_folder_prepare_for_offline (CamelDiscoFolder *disco_folder,
 					     const gchar *expression,
 					     CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_disco_folder_get_type (void);
+GType camel_disco_folder_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/camel-disco-store.c b/camel/camel-disco-store.c
index 3148d9c..eafefcb 100644
--- a/camel/camel-disco-store.c
+++ b/camel/camel-disco-store.c
@@ -26,7 +26,6 @@
 #include <config.h>
 #endif
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-disco-diary.h"
@@ -37,9 +36,7 @@
 
 #define d(x)
 
-#define CDS_CLASS(o) (CAMEL_DISCO_STORE_CLASS (CAMEL_OBJECT_GET_CLASS (o)))
-
-static CamelStoreClass *parent_class = NULL;
+static gpointer parent_class;
 
 static void disco_construct (CamelService *service, CamelSession *session,
 			     CamelProvider *provider, CamelURL *url,
@@ -61,52 +58,48 @@ static gint disco_setv (CamelObject *object, CamelException *ex, CamelArgV *args
 static gint disco_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
 
 static void
-camel_disco_store_class_init (CamelDiscoStoreClass *camel_disco_store_class)
+disco_store_class_init (CamelDiscoStoreClass *class)
 {
-	CamelObjectClass *camel_object_class =
-		CAMEL_OBJECT_CLASS (camel_disco_store_class);
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_disco_store_class);
-	CamelStoreClass *camel_store_class =
-		CAMEL_STORE_CLASS (camel_disco_store_class);
-
-	parent_class = CAMEL_STORE_CLASS (camel_type_get_global_classfuncs (camel_store_get_type ()));
+	CamelObjectClass *camel_object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
 
-	/* virtual method definition */
-	camel_disco_store_class->set_status = set_status;
-	camel_disco_store_class->can_work_offline = can_work_offline;
+	parent_class = g_type_class_peek_parent (class);
 
-	/* virtual method overload */
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
 	camel_object_class->setv = disco_setv;
 	camel_object_class->getv = disco_getv;
 
-	camel_service_class->construct = disco_construct;
-	camel_service_class->connect = disco_connect;
-	camel_service_class->disconnect = disco_disconnect;
-	camel_service_class->cancel_connect = disco_cancel_connect;
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = disco_construct;
+	service_class->connect = disco_connect;
+	service_class->disconnect = disco_disconnect;
+	service_class->cancel_connect = disco_cancel_connect;
 
-	camel_store_class->get_folder = disco_get_folder;
-	camel_store_class->get_folder_info = disco_get_folder_info;
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_folder = disco_get_folder;
+	store_class->get_folder_info = disco_get_folder_info;
+
+	class->set_status = set_status;
+	class->can_work_offline = can_work_offline;
 }
 
-CamelType
+GType
 camel_disco_store_get_type (void)
 {
-	static CamelType camel_disco_store_type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (camel_disco_store_type == CAMEL_INVALID_TYPE) {
-		camel_disco_store_type = camel_type_register (
-			CAMEL_STORE_TYPE,
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE,
 			"CamelDiscoStore",
-			sizeof (CamelDiscoStore),
 			sizeof (CamelDiscoStoreClass),
-			(CamelObjectClassInitFunc) camel_disco_store_class_init,
-			NULL,
+			(GClassInitFunc) disco_store_class_init,
+			sizeof (CamelDiscoStore),
 			NULL,
-			NULL);
-	}
+			0);
 
-	return camel_disco_store_type;
+	return type;
 }
 
 static gint
@@ -158,7 +151,7 @@ disco_connect (CamelService *service, CamelException *ex)
 	switch (status) {
 	case CAMEL_DISCO_STORE_ONLINE:
 	case CAMEL_DISCO_STORE_RESYNCING:
-		if (!CDS_CLASS (service)->connect_online (service, ex))
+		if (!CAMEL_DISCO_STORE_GET_CLASS (service)->connect_online (service, ex))
 			return FALSE;
 
 		if (!store->diary)
@@ -172,9 +165,9 @@ disco_connect (CamelService *service, CamelException *ex)
 		   disconnect could be called, which will remove store->diary and unref it */
 		store->status = CAMEL_DISCO_STORE_RESYNCING;
 		diary = store->diary;
-		camel_object_ref(diary);
+		g_object_ref (diary);
 		camel_disco_diary_replay(diary, ex);
-		camel_object_unref(diary);
+		g_object_unref (diary);
 		store->status = CAMEL_DISCO_STORE_ONLINE;
 		if (camel_exception_is_set (ex))
 			return FALSE;
@@ -184,7 +177,7 @@ disco_connect (CamelService *service, CamelException *ex)
 		return camel_service_connect (service, ex);
 
 	case CAMEL_DISCO_STORE_OFFLINE:
-		return CDS_CLASS (service)->connect_offline (service, ex);
+		return CAMEL_DISCO_STORE_GET_CLASS (service)->connect_offline (service, ex);
 	}
 
 	g_assert_not_reached ();
@@ -209,12 +202,12 @@ disco_disconnect (CamelService *service, gboolean clean, CamelException *ex)
 	switch (camel_disco_store_status (store)) {
 	case CAMEL_DISCO_STORE_ONLINE:
 	case CAMEL_DISCO_STORE_RESYNCING:
-		if (!CDS_CLASS (service)->disconnect_online (service, clean, ex))
+		if (!CAMEL_DISCO_STORE_GET_CLASS (service)->disconnect_online (service, clean, ex))
 			return FALSE;
 		break;
 
 	case CAMEL_DISCO_STORE_OFFLINE:
-		if (!CDS_CLASS (service)->disconnect_offline (service, clean, ex))
+		if (!CAMEL_DISCO_STORE_GET_CLASS (service)->disconnect_offline (service, clean, ex))
 			return FALSE;
 		break;
 
@@ -231,13 +224,13 @@ disco_get_folder (CamelStore *store, const gchar *name,
 
 	switch (camel_disco_store_status (disco_store)) {
 	case CAMEL_DISCO_STORE_ONLINE:
-		return CDS_CLASS (store)->get_folder_online (store, name, flags, ex);
+		return CAMEL_DISCO_STORE_GET_CLASS (store)->get_folder_online (store, name, flags, ex);
 
 	case CAMEL_DISCO_STORE_OFFLINE:
-		return CDS_CLASS (store)->get_folder_offline (store, name, flags, ex);
+		return CAMEL_DISCO_STORE_GET_CLASS (store)->get_folder_offline (store, name, flags, ex);
 
 	case CAMEL_DISCO_STORE_RESYNCING:
-		return CDS_CLASS (store)->get_folder_resyncing (store, name, flags, ex);
+		return CAMEL_DISCO_STORE_GET_CLASS (store)->get_folder_resyncing (store, name, flags, ex);
 	}
 
 	g_assert_not_reached ();
@@ -252,7 +245,7 @@ disco_get_folder_info (CamelStore *store, const gchar *top,
 
 	switch (camel_disco_store_status (disco_store)) {
 	case CAMEL_DISCO_STORE_ONLINE:
-		return CDS_CLASS (store)->get_folder_info_online (store, top, flags, ex);
+		return CAMEL_DISCO_STORE_GET_CLASS (store)->get_folder_info_online (store, top, flags, ex);
 
 	case CAMEL_DISCO_STORE_OFFLINE:
 		/* Can't edit subscriptions while offline */
@@ -262,10 +255,10 @@ disco_get_folder_info (CamelStore *store, const gchar *top,
 			return NULL;
 		}
 
-		return CDS_CLASS (store)->get_folder_info_offline (store, top, flags, ex);
+		return CAMEL_DISCO_STORE_GET_CLASS (store)->get_folder_info_offline (store, top, flags, ex);
 
 	case CAMEL_DISCO_STORE_RESYNCING:
-		return CDS_CLASS (store)->get_folder_info_resyncing (store, top, flags, ex);
+		return CAMEL_DISCO_STORE_GET_CLASS (store)->get_folder_info_resyncing (store, top, flags, ex);
 	}
 
 	g_assert_not_reached ();
@@ -319,12 +312,12 @@ set_status(CamelDiscoStore *disco_store, CamelDiscoStoreStatus status, CamelExce
 				folders = camel_object_bag_list(((CamelStore *)disco_store)->folders);
 				for (i=0;i<folders->len;i++) {
 					folder = folders->pdata[i];
-					if (CAMEL_CHECK_TYPE(folder, CAMEL_DISCO_FOLDER_TYPE)
+					if (G_TYPE_CHECK_INSTANCE_TYPE(folder, CAMEL_TYPE_DISCO_FOLDER)
 					    && (sync || ((CamelDiscoFolder *)folder)->offline_sync)) {
 						camel_disco_folder_prepare_for_offline((CamelDiscoFolder *)folder, "", &x);
 						camel_exception_clear(&x);
 					}
-					camel_object_unref(folder);
+					g_object_unref (folder);
 				}
 				g_ptr_array_free(folders, TRUE);
 			}
@@ -357,14 +350,14 @@ camel_disco_store_set_status (CamelDiscoStore *store,
 {
 	d(printf("disco store set status: %s\n", status == CAMEL_DISCO_STORE_ONLINE?"online":"offline"));
 
-	CDS_CLASS (store)->set_status (store, status, ex);
+	CAMEL_DISCO_STORE_GET_CLASS (store)->set_status (store, status, ex);
 }
 
 static gboolean
 can_work_offline (CamelDiscoStore *disco_store)
 {
 	g_warning ("CamelDiscoStore::can_work_offline not implemented for '%s'",
-		   camel_type_to_name (CAMEL_OBJECT_GET_TYPE (disco_store)));
+		   G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (disco_store)));
 	return FALSE;
 }
 
@@ -378,7 +371,7 @@ can_work_offline (CamelDiscoStore *disco_store)
 gboolean
 camel_disco_store_can_work_offline (CamelDiscoStore *store)
 {
-	return CDS_CLASS (store)->can_work_offline (store);
+	return CAMEL_DISCO_STORE_GET_CLASS (store)->can_work_offline (store);
 }
 
 /**
@@ -427,12 +420,12 @@ camel_disco_store_prepare_for_offline(CamelDiscoStore *disco_store, CamelExcepti
 				folders = camel_object_bag_list(((CamelStore *)disco_store)->folders);
 				for (i=0;i<folders->len;i++) {
 					folder = folders->pdata[i];
-					if (CAMEL_CHECK_TYPE(folder, CAMEL_DISCO_FOLDER_TYPE)
+					if (G_TYPE_CHECK_INSTANCE_TYPE(folder, CAMEL_TYPE_DISCO_FOLDER)
 					    && (sync || ((CamelDiscoFolder *)folder)->offline_sync)) {
 						camel_disco_folder_prepare_for_offline((CamelDiscoFolder *)folder, "(match-all)", &x);
 						camel_exception_clear(&x);
 					}
-					camel_object_unref(folder);
+					g_object_unref (folder);
 				}
 				g_ptr_array_free(folders, TRUE);
 			}
diff --git a/camel/camel-disco-store.h b/camel/camel-disco-store.h
index b1477cf..66ebc2a 100644
--- a/camel/camel-disco-store.h
+++ b/camel/camel-disco-store.h
@@ -21,20 +21,43 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
 #ifndef CAMEL_DISCO_STORE_H
-#define CAMEL_DISCO_STORE_H 1
+#define CAMEL_DISCO_STORE_H
 
 #include <camel/camel-store.h>
 
-#define CAMEL_DISCO_STORE_TYPE     (camel_disco_store_get_type ())
-#define CAMEL_DISCO_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_DISCO_STORE_TYPE, CamelDiscoStore))
-#define CAMEL_DISCO_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_DISCO_STORE_TYPE, CamelDiscoStoreClass))
-#define CAMEL_IS_DISCO_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_DISCO_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_DISCO_STORE \
+	(camel_disco_store_get_type ())
+#define CAMEL_DISCO_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_DISCO_STORE, CamelDiscoStore))
+#define CAMEL_DISCO_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_DISCO_STORE, CamelDiscoStoreClass))
+#define CAMEL_IS_DISCO_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_DISCO_STORE))
+#define CAMEL_IS_DISCO_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_DISCO_STORE))
+#define CAMEL_DISCO_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_DISCO_STORE, CamelDiscoStoreClass))
 
 G_BEGIN_DECLS
 
+struct _CamelDiscoDiary;
+
+typedef struct _CamelDiscoStore CamelDiscoStore;
+typedef struct _CamelDiscoStoreClass CamelDiscoStoreClass;
+
 enum {
 	CAMEL_DISCO_STORE_ARG_FIRST  = CAMEL_STORE_ARG_FIRST + 100
 };
@@ -46,13 +69,13 @@ typedef enum {
 } CamelDiscoStoreStatus;
 
 struct _CamelDiscoStore {
-	CamelStore parent_object;
+	CamelStore parent;
 
 	CamelDiscoStoreStatus status;
-	CamelDiscoDiary *diary;
+	struct _CamelDiscoDiary *diary;
 };
 
-typedef struct {
+struct _CamelDiscoStoreClass {
 	CamelStoreClass parent_class;
 
 	void              (*set_status)              (CamelDiscoStore *,
@@ -95,11 +118,9 @@ typedef struct {
 							const gchar *top,
 							guint32 flags,
 							CamelException *ex);
+};
 
-} CamelDiscoStoreClass;
-
-/* Standard Camel function */
-CamelType camel_disco_store_get_type (void);
+GType camel_disco_store_get_type (void);
 
 /* Public methods */
 CamelDiscoStoreStatus camel_disco_store_status           (CamelDiscoStore *store);
diff --git a/camel/camel-exception.c b/camel/camel-exception.c
index d8c2980..cb99502 100644
--- a/camel/camel-exception.c
+++ b/camel/camel-exception.c
@@ -28,7 +28,6 @@
 #include <stdio.h>
 #include <pthread.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-debug.h"
diff --git a/camel/camel-exception.h b/camel/camel-exception.h
index 5f41d66..ccd8fe8 100644
--- a/camel/camel-exception.h
+++ b/camel/camel-exception.h
@@ -23,10 +23,14 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_EXCEPTION_H
-#define CAMEL_EXCEPTION_H 1
+#define CAMEL_EXCEPTION_H
 
-#include <camel/camel-types.h>
+#include <glib.h>
 
 G_BEGIN_DECLS
 
@@ -35,6 +39,8 @@ typedef enum {
 
 } ExceptionId;
 
+typedef struct _CamelException CamelException;
+
 struct _CamelException {
 	/* do not access the fields directly */
 	ExceptionId id;
diff --git a/camel/camel-file-utils.c b/camel/camel-file-utils.c
index be9c4fe..f266e0f 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
diff --git a/camel/camel-file-utils.h b/camel/camel-file-utils.h
index a53c711..7f031d9 100644
--- a/camel/camel-file-utils.h
+++ b/camel/camel-file-utils.h
@@ -23,8 +23,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_FILE_UTILS_H
-#define CAMEL_FILE_UTILS_H 1
+#define CAMEL_FILE_UTILS_H
 
 #include <glib.h>
 #include <stdio.h>
diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c
index cdfe7cc..b06081f 100644
--- a/camel/camel-filter-driver.c
+++ b/camel/camel-filter-driver.c
@@ -31,7 +31,6 @@
 #include <sys/types.h>
 #include <time.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 
@@ -49,6 +48,7 @@
 #include "camel-mime-message.h"
 #include "camel-private.h"
 #include "camel-service.h"
+#include "camel-session.h"
 #include "camel-stream-fs.h"
 #include "camel-stream-mem.h"
 
@@ -57,6 +57,10 @@
 /* an invalid pointer */
 #define FOLDER_INVALID ((gpointer)~0)
 
+#define CAMEL_FILTER_DRIVER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_FILTER_DRIVER, CamelFilterDriverPrivate))
+
 /* type of status for a log report */
 enum filter_log_t {
 	FILTER_LOG_NONE,
@@ -124,12 +128,6 @@ struct _CamelFilterDriverPrivate {
 	ESExp *eval;
 };
 
-#define _PRIVATE(o) (((CamelFilterDriver *)(o))->priv)
-
-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_log (CamelFilterDriver *driver, enum filter_log_t status, const gchar *desc, ...);
 
 static CamelFolder *open_folder (CamelFilterDriver *d, const gchar *folder_url);
@@ -177,103 +175,133 @@ static struct {
 	{ "only-once",         (ESExpFunc *) do_only_once, 0 }
 };
 
-static CamelObjectClass *camel_filter_driver_parent;
+static gpointer parent_class;
 
-CamelType
-camel_filter_driver_get_type (void)
+static void
+free_hash_strings (gpointer key, gpointer value, gpointer data)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE)	{
-		type = camel_type_register (CAMEL_OBJECT_TYPE,
-					    "CamelFilterDriver",
-					    sizeof (CamelFilterDriver),
-					    sizeof (CamelFilterDriverClass),
-					    (CamelObjectClassInitFunc) camel_filter_driver_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_filter_driver_init,
-					    (CamelObjectFinalizeFunc) camel_filter_driver_finalise);
-	}
-
-	return type;
+	g_free (key);
+	g_free (value);
 }
 
 static void
-camel_filter_driver_class_init (CamelFilterDriverClass *klass)
+filter_driver_dispose (GObject *object)
 {
-	/*CamelObjectClass *object_class = (CamelObjectClass *) klass;*/
+	CamelFilterDriverPrivate *priv;
+
+	priv = CAMEL_FILTER_DRIVER_GET_PRIVATE (object);
 
-	camel_filter_driver_parent = camel_type_get_global_classfuncs(camel_object_get_type());
+	if (priv->defaultfolder != NULL) {
+		camel_folder_thaw (priv->defaultfolder);
+		g_object_unref (priv->defaultfolder);
+		priv->defaultfolder = NULL;
+	}
+
+	if (priv->session != NULL) {
+		g_object_unref (priv->session);
+		priv->session = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_filter_driver_init (CamelFilterDriver *obj)
+filter_driver_finalize (GObject *object)
 {
-	struct _CamelFilterDriverPrivate *p;
-	gint i;
+	CamelFilterDriverPrivate *priv;
+	struct _filter_rule *node;
 
-	p = _PRIVATE (obj) = g_malloc0 (sizeof (*p));
+	priv = CAMEL_FILTER_DRIVER_GET_PRIVATE (object);
 
-	camel_dlist_init(&p->rules);
+	/* close all folders that were opened for appending */
+	close_folders (CAMEL_FILTER_DRIVER (object));
+	g_hash_table_destroy (priv->folders);
 
-	p->eval = e_sexp_new ();
-	/* Load in builtin symbols */
-	for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
-		if (symbols[i].type == 1) {
-			e_sexp_add_ifunction (p->eval, 0, symbols[i].name, (ESExpIFunc *)symbols[i].func, obj);
-		} else {
-			e_sexp_add_function (p->eval, 0, symbols[i].name, symbols[i].func, obj);
-		}
-	}
+	g_hash_table_foreach (priv->globals, free_hash_strings, object);
+	g_hash_table_destroy (priv->globals);
 
-	p->globals = g_hash_table_new (g_str_hash, g_str_equal);
+	g_hash_table_foreach (priv->only_once, free_hash_strings, object);
+	g_hash_table_destroy (priv->only_once);
 
-	p->folders = g_hash_table_new (g_str_hash, g_str_equal);
+	e_sexp_unref (priv->eval);
+
+	while ((node = (struct _filter_rule *) camel_dlist_remhead (&priv->rules))) {
+		g_free (node->match);
+		g_free (node->action);
+		g_free (node->name);
+		g_free (node);
+	}
 
-	p->only_once = g_hash_table_new (g_str_hash, g_str_equal);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-free_hash_strings (gpointer key, gpointer value, gpointer data)
+filter_driver_class_init (CamelFilterDriverClass *class)
 {
-	g_free (key);
-	g_free (value);
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelFilterDriverPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = filter_driver_dispose;
+	object_class->finalize = filter_driver_finalize;
 }
 
 static void
-camel_filter_driver_finalise (CamelObject *obj)
+filter_driver_init (CamelFilterDriver *filter_driver)
 {
-	CamelFilterDriver *driver = (CamelFilterDriver *) obj;
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
-	struct _filter_rule *node;
-
-	/* close all folders that were opened for appending */
-	close_folders (driver);
-	g_hash_table_destroy (p->folders);
+	gint ii;
 
-	g_hash_table_foreach (p->globals, free_hash_strings, driver);
-	g_hash_table_destroy (p->globals);
+	filter_driver->priv = CAMEL_FILTER_DRIVER_GET_PRIVATE (filter_driver);
 
-	g_hash_table_foreach (p->only_once, free_hash_strings, driver);
-	g_hash_table_destroy (p->only_once);
+	camel_dlist_init (&filter_driver->priv->rules);
 
-	e_sexp_unref(p->eval);
+	filter_driver->priv->eval = e_sexp_new ();
 
-	if (p->defaultfolder) {
-		camel_folder_thaw (p->defaultfolder);
-		camel_object_unref (p->defaultfolder);
+	/* Load in builtin symbols */
+	for (ii = 0; ii < G_N_ELEMENTS (symbols); ii++) {
+		if (symbols[ii].type == 1) {
+			e_sexp_add_ifunction (
+				filter_driver->priv->eval, 0,
+				symbols[ii].name, (ESExpIFunc *)
+				symbols[ii].func, filter_driver);
+		} else {
+			e_sexp_add_function (
+				filter_driver->priv->eval, 0,
+				symbols[ii].name, symbols[ii].func,
+				filter_driver);
+		}
 	}
 
-	while ((node = (struct _filter_rule *)camel_dlist_remhead(&p->rules))) {
-		g_free(node->match);
-		g_free(node->action);
-		g_free(node->name);
-		g_free(node);
-	}
+	filter_driver->priv->globals =
+		g_hash_table_new (g_str_hash, g_str_equal);
 
-	camel_object_unref(p->session);
+	filter_driver->priv->folders =
+		g_hash_table_new (g_str_hash, g_str_equal);
 
-	g_free (p);
+	filter_driver->priv->only_once =
+		g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+GType
+camel_filter_driver_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelFilterDriver",
+			sizeof (CamelFilterDriverClass),
+			(GClassInitFunc) filter_driver_class_init,
+			sizeof (CamelFilterDriver),
+			(GInstanceInitFunc) filter_driver_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -284,10 +312,10 @@ camel_filter_driver_finalise (CamelObject *obj)
 CamelFilterDriver *
 camel_filter_driver_new (CamelSession *session)
 {
-	CamelFilterDriver *d = (CamelFilterDriver *)camel_object_new(camel_filter_driver_get_type());
+	CamelFilterDriver *d;
 
-	d->priv->session = session;
-	camel_object_ref((CamelObject *)session);
+	d = g_object_new (CAMEL_TYPE_FILTER_DRIVER, NULL);
+	d->priv->session = g_object_ref (session);
 
 	return d;
 }
@@ -295,7 +323,7 @@ camel_filter_driver_new (CamelSession *session)
 void
 camel_filter_driver_set_folder_func (CamelFilterDriver *d, CamelFilterGetFolderFunc get_folder, gpointer data)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 
 	p->get_folder = get_folder;
 	p->data = data;
@@ -304,7 +332,7 @@ camel_filter_driver_set_folder_func (CamelFilterDriver *d, CamelFilterGetFolderF
 void
 camel_filter_driver_set_logfile (CamelFilterDriver *d, FILE *logfile)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 
 	p->logfile = logfile;
 }
@@ -312,7 +340,7 @@ camel_filter_driver_set_logfile (CamelFilterDriver *d, FILE *logfile)
 void
 camel_filter_driver_set_status_func (CamelFilterDriver *d, CamelFilterStatusFunc *func, gpointer data)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 
 	p->statusfunc = func;
 	p->statusdata = data;
@@ -321,7 +349,7 @@ camel_filter_driver_set_status_func (CamelFilterDriver *d, CamelFilterStatusFunc
 void
 camel_filter_driver_set_shell_func (CamelFilterDriver *d, CamelFilterShellFunc *func, gpointer data)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 
 	p->shellfunc = func;
 	p->shelldata = data;
@@ -330,7 +358,7 @@ camel_filter_driver_set_shell_func (CamelFilterDriver *d, CamelFilterShellFunc *
 void
 camel_filter_driver_set_play_sound_func (CamelFilterDriver *d, CamelFilterPlaySoundFunc *func, gpointer data)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 
 	p->playfunc = func;
 	p->playdata = data;
@@ -339,7 +367,7 @@ camel_filter_driver_set_play_sound_func (CamelFilterDriver *d, CamelFilterPlaySo
 void
 camel_filter_driver_set_system_beep_func (CamelFilterDriver *d, CamelFilterSystemBeepFunc *func, gpointer data)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 
 	p->beep = func;
 	p->beepdata = data;
@@ -348,25 +376,25 @@ camel_filter_driver_set_system_beep_func (CamelFilterDriver *d, CamelFilterSyste
 void
 camel_filter_driver_set_default_folder (CamelFilterDriver *d, CamelFolder *def)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 
 	if (p->defaultfolder) {
 		camel_folder_thaw (p->defaultfolder);
-		camel_object_unref (p->defaultfolder);
+		g_object_unref (p->defaultfolder);
 	}
 
 	p->defaultfolder = def;
 
 	if (p->defaultfolder) {
 		camel_folder_freeze (p->defaultfolder);
-		camel_object_ref (p->defaultfolder);
+		g_object_ref (p->defaultfolder);
 	}
 }
 
 void
 camel_filter_driver_add_rule(CamelFilterDriver *d, const gchar *name, const gchar *match, const gchar *action)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 	struct _filter_rule *node;
 
 	node = g_malloc(sizeof(*node));
@@ -379,7 +407,7 @@ camel_filter_driver_add_rule(CamelFilterDriver *d, const gchar *name, const gcha
 gint
 camel_filter_driver_remove_rule_by_name (CamelFilterDriver *d, const gchar *name)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 	struct _filter_rule *node;
 
 	node = (struct _filter_rule *) p->rules.head;
@@ -404,7 +432,7 @@ static void
 report_status (CamelFilterDriver *driver, enum camel_filter_status_t status, gint pc, const gchar *desc, ...)
 {
 	/* call user-defined status report function */
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	va_list ap;
 	gchar *str;
 
@@ -420,7 +448,7 @@ report_status (CamelFilterDriver *driver, enum camel_filter_status_t status, gin
 void
 camel_filter_driver_set_global (CamelFilterDriver *d, const gchar *name, const gchar *value)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (d);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (d);
 	gchar *oldkey, *oldvalue;
 
 	if (g_hash_table_lookup_extended (p->globals, name, (gpointer)&oldkey, (gpointer)&oldvalue)) {
@@ -435,7 +463,7 @@ camel_filter_driver_set_global (CamelFilterDriver *d, const gchar *name, const g
 static ESExpResult *
 do_delete (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "doing delete\n"));
 	p->deleted = TRUE;
@@ -447,7 +475,7 @@ do_delete (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterD
 static ESExpResult *
 do_forward_to (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "marking message for forwarding\n"));
 
@@ -470,7 +498,7 @@ do_forward_to (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFil
 static ESExpResult *
 do_copy (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	gint i;
 
 	d(fprintf (stderr, "copying message...\n"));
@@ -519,7 +547,7 @@ do_copy (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDri
 static ESExpResult *
 do_move (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	gint i;
 
 	d(fprintf (stderr, "moving message...\n"));
@@ -582,7 +610,7 @@ do_move (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDri
 static ESExpResult *
 do_stop (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	camel_filter_driver_log (driver, FILTER_LOG_ACTION, "Stopped processing");
 	d(fprintf (stderr, "terminating message processing\n"));
@@ -594,7 +622,7 @@ do_stop (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDri
 static ESExpResult *
 do_label (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "setting label tag\n"));
 	if (argc > 0 && argv[0]->type == ESEXP_RES_STRING) {
@@ -626,7 +654,7 @@ do_label (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDr
 static ESExpResult *
 do_colour (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "setting colour tag\n"));
 	if (argc > 0 && argv[0]->type == ESEXP_RES_STRING) {
@@ -643,7 +671,7 @@ do_colour (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterD
 static ESExpResult *
 do_score (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "setting score tag\n"));
 	if (argc > 0 && argv[0]->type == ESEXP_RES_INT) {
@@ -661,7 +689,7 @@ do_score (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDr
 static ESExpResult *
 do_adjust_score(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE(driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE(driver);
 
 	d(fprintf (stderr, "adjusting score tag\n"));
 	if (argc > 0 && argv[0]->type == ESEXP_RES_INT) {
@@ -682,7 +710,7 @@ do_adjust_score(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFi
 static ESExpResult *
 set_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	guint32 flags;
 
 	d(fprintf (stderr, "setting flag\n"));
@@ -701,7 +729,7 @@ set_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDr
 static ESExpResult *
 unset_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	guint32 flags;
 
 	d(fprintf (stderr, "unsetting flag\n"));
@@ -749,7 +777,7 @@ child_watch (GPid     pid,
 static gint
 pipe_to_system (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	gint i, pipe_to_child, pipe_from_child;
 	CamelMimeMessage *message = NULL;
 	CamelMimeParser *parser;
@@ -801,34 +829,34 @@ pipe_to_system (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFi
 
 	stream = camel_stream_fs_new_with_fd (pipe_to_child);
 	if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (p->message), stream) == -1) {
-		camel_object_unref (stream);
+		g_object_unref (stream);
 		close (pipe_from_child);
 		goto wait;
 	}
 
 	if (camel_stream_flush (stream) == -1) {
-		camel_object_unref (stream);
+		g_object_unref (stream);
 		close (pipe_from_child);
 		goto wait;
 	}
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	stream = camel_stream_fs_new_with_fd (pipe_from_child);
 	mem = camel_stream_mem_new ();
 	if (camel_stream_write_to_stream (stream, mem) == -1) {
-		camel_object_unref (stream);
-		camel_object_unref (mem);
+		g_object_unref (stream);
+		g_object_unref (mem);
 		goto wait;
 	}
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 	camel_stream_reset (mem);
 
 	parser = camel_mime_parser_new ();
 	camel_mime_parser_init_with_stream (parser, mem);
 	camel_mime_parser_scan_from (parser, FALSE);
-	camel_object_unref (mem);
+	g_object_unref (mem);
 
 	message = camel_mime_message_new ();
 	if (camel_mime_part_construct_from_parser ((CamelMimePart *) message, parser) == -1) {
@@ -836,15 +864,15 @@ pipe_to_system (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFi
 				     _("Invalid message stream received from %s: %s"),
 				      argv[0]->value.string,
 				      g_strerror (camel_mime_parser_errno (parser)));
-		camel_object_unref (message);
+		g_object_unref (message);
 		message = NULL;
 	} else {
-		camel_object_unref (p->message);
+		g_object_unref (p->message);
 		p->message = message;
 		p->modified = TRUE;
 	}
 
-	camel_object_unref (parser);
+	g_object_unref (parser);
 
  wait:
 	context = g_main_context_new ();
@@ -889,7 +917,7 @@ pipe_message (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilt
 static ESExpResult *
 do_shell (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	GString *command;
 	GPtrArray *args;
 	gint i;
@@ -930,7 +958,7 @@ do_shell (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDr
 static ESExpResult *
 do_beep (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "beep\n"));
 
@@ -945,7 +973,7 @@ do_beep (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDri
 static ESExpResult *
 play_sound (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "play sound\n"));
 
@@ -960,7 +988,7 @@ play_sound (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilter
 static ESExpResult *
 do_only_once (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	d(fprintf (stderr, "only once\n"));
 
@@ -974,7 +1002,7 @@ do_only_once (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilt
 static CamelFolder *
 open_folder (CamelFilterDriver *driver, const gchar *folder_url)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	CamelFolder *camelfolder;
 
 	/* we have a lookup table of currently open folders */
@@ -1011,7 +1039,7 @@ close_folder (gpointer key, gpointer value, gpointer data)
 {
 	CamelFolder *folder = value;
 	CamelFilterDriver *driver = data;
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	p->closed++;
 	g_free (key);
@@ -1019,7 +1047,7 @@ close_folder (gpointer key, gpointer value, gpointer data)
 	if (folder != FOLDER_INVALID) {
 		camel_folder_sync (folder, FALSE, camel_exception_is_set(p->ex)?NULL : p->ex);
 		camel_folder_thaw (folder);
-		camel_object_unref (folder);
+		g_object_unref (folder);
 	}
 
 	report_status(driver, CAMEL_FILTER_STATUS_PROGRESS, g_hash_table_size(p->folders)* 100 / p->closed, _("Syncing folders"));
@@ -1029,7 +1057,7 @@ close_folder (gpointer key, gpointer value, gpointer data)
 static gint
 close_folders (CamelFilterDriver *driver)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	report_status(driver, CAMEL_FILTER_STATUS_PROGRESS, 0, _("Syncing folders"));
 
@@ -1053,7 +1081,7 @@ free_key (gpointer key, gpointer value, gpointer user_data)
 static void
 camel_filter_driver_log (CamelFilterDriver *driver, enum filter_log_t status, const gchar *desc, ...)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 
 	if (p->logfile) {
 		gchar *str = NULL;
@@ -1108,7 +1136,7 @@ struct _run_only_once {
 static gboolean
 run_only_once (gpointer key, gchar *action, struct _run_only_once *data)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (data->driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (data->driver);
 	CamelException *ex = data->ex;
 	ESExpResult *r;
 
@@ -1152,7 +1180,7 @@ run_only_once (gpointer key, gchar *action, struct _run_only_once *data)
 void
 camel_filter_driver_flush (CamelFilterDriver *driver, CamelException *ex)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	struct _run_only_once data;
 
 	if (!p->only_once)
@@ -1201,7 +1229,7 @@ decode_flags_from_xev(const gchar *xev, CamelMessageInfoBase *mi)
 gint
 camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const gchar *mbox, const gchar *original_source_url, CamelException *ex)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	CamelMimeParser *mp = NULL;
 	gchar *source_url = NULL;
 	gint fd = -1;
@@ -1230,6 +1258,7 @@ camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const gchar *mbox, c
 	source_url = g_filename_to_uri (mbox, NULL, NULL);
 
 	while (camel_mime_parser_step (mp, 0, 0) == CAMEL_MIME_PARSER_STATE_FROM) {
+		struct _camel_header_raw *headers;
 		CamelMessageInfo *info;
 		CamelMimeMessage *msg;
 		gint pc = 0;
@@ -1244,13 +1273,14 @@ camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const gchar *mbox, c
 		if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (msg), mp) == -1) {
 			camel_exception_set (ex, (errno==EINTR)?CAMEL_EXCEPTION_USER_CANCEL:CAMEL_EXCEPTION_SYSTEM, _("Cannot open message"));
 			report_status (driver, CAMEL_FILTER_STATUS_END, 100, _("Failed on message %d"), i);
-			camel_object_unref (msg);
+			g_object_unref (msg);
 			goto fail;
 		}
 
-		info = camel_message_info_new_from_header(NULL, ((CamelMimePart *)msg)->headers);
+		headers = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (msg));
+		info = camel_message_info_new_from_header(NULL, headers);
 		/* Try and see if it has X-Evolution headers */
-		xev = camel_header_raw_find(&((CamelMimePart *)msg)->headers, "X-Evolution", NULL);
+		xev = camel_header_raw_find(&headers, "X-Evolution", NULL);
 		if (xev)
 			decode_flags_from_xev (xev, (CamelMessageInfoBase *)info);
 
@@ -1259,7 +1289,7 @@ camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const gchar *mbox, c
 		last = camel_mime_parser_tell(mp);
 		status = camel_filter_driver_filter_message (driver, msg, info, NULL, NULL, source_url,
 							     original_source_url ? original_source_url : source_url, ex);
-		camel_object_unref (msg);
+		g_object_unref (msg);
 		if (camel_exception_is_set (ex) || status == -1) {
 			report_status (driver, CAMEL_FILTER_STATUS_END, 100, _("Failed on message %d"), i);
 			camel_message_info_free (info);
@@ -1287,7 +1317,7 @@ fail:
 	if (fd != -1)
 		close (fd);
 	if (mp)
-		camel_object_unref (mp);
+		g_object_unref (mp);
 
 	return ret;
 }
@@ -1312,7 +1342,7 @@ gint
 camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folder, CamelUIDCache *cache,
 				   GPtrArray *uids, gboolean remove, CamelException *ex)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	gboolean freeuids = FALSE;
 	CamelMessageInfo *info;
 	gchar *source_url, *service_url;
@@ -1395,7 +1425,7 @@ get_message_cb (gpointer data, CamelException *ex)
 
 	if (p->message) {
 		message = p->message;
-		camel_object_ref (message);
+		g_object_ref (message);
 	} else {
 		const gchar *uid;
 
@@ -1441,7 +1471,7 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage
 				    const gchar *original_source_url,
 				    CamelException *ex)
 {
-	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
+	struct _CamelFilterDriverPrivate *p = CAMEL_FILTER_DRIVER_GET_PRIVATE (driver);
 	struct _filter_rule *node;
 	gboolean freeinfo = FALSE;
 	gboolean filtered = FALSE;
@@ -1458,14 +1488,14 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage
 		struct _camel_header_raw *h;
 
 		if (message) {
-			camel_object_ref (message);
+			g_object_ref (message);
 		} else {
 			message = camel_folder_get_message (source, uid, ex);
 			if (!message)
 				return -1;
 		}
 
-		h = CAMEL_MIME_PART (message)->headers;
+		h = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (message));
 		info = camel_message_info_new_from_header (NULL, h);
 		freeinfo = TRUE;
 	} else {
@@ -1475,7 +1505,7 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage
 		uid = camel_message_info_uid (info);
 
 		if (message)
-			camel_object_ref (message);
+			g_object_ref (message);
 	}
 
 	p->ex = ex;
@@ -1578,7 +1608,7 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage
 	}
 
 	if (p->message)
-		camel_object_unref (p->message);
+		g_object_unref (p->message);
 
 	if (freeinfo)
 		camel_message_info_free (info);
@@ -1590,7 +1620,7 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage
 		camel_filter_driver_log (driver, FILTER_LOG_END, NULL);
 
 	if (p->message)
-		camel_object_unref (p->message);
+		g_object_unref (p->message);
 
 	if (freeinfo)
 		camel_message_info_free (info);
diff --git a/camel/camel-filter-driver.h b/camel/camel-filter-driver.h
index c361f9c..a5a5dcc 100644
--- a/camel/camel-filter-driver.h
+++ b/camel/camel-filter-driver.h
@@ -19,28 +19,47 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_FILTER_DRIVER_H
-#define _CAMEL_FILTER_DRIVER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_FILTER_DRIVER_H
+#define CAMEL_FILTER_DRIVER_H
 
-#include <glib.h>
 #include <camel/camel-object.h>
-#include <camel/camel-session.h>
 #include <camel/camel-folder.h>
 #include <camel/camel-uid-cache.h>
 
-#define CAMEL_FILTER_DRIVER_TYPE         (camel_filter_driver_get_type ())
-#define CAMEL_FILTER_DRIVER(obj)         CAMEL_CHECK_CAST (obj, CAMEL_FILTER_DRIVER_TYPE, CamelFilterDriver)
-#define CAMEL_FILTER_DRIVER_CLASS(klass) CAMEL__CHECK_CLASS_CAST (klass, CAMEL_FILTER_DRIVER_TYPE, CamelFilterDriverClass)
-#define CAMEL_IS_FILTER_DRIVER(obj)      CAMEL_CHECK_TYPE (obj, CAMEL_FILTER_DRIVER_TYPE)
+/* Standard GObject macros */
+#define CAMEL_TYPE_FILTER_DRIVER \
+	(camel_filter_driver_get_type ())
+#define CAMEL_FILTER_DRIVER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_FILTER_DRIVER, CamelFilterDriver))
+#define CAMEL_FILTER_DRIVER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_FILTER_DRIVER, CamelFilterDriverClass)
+#define CAMEL_IS_FILTER_DRIVER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_FILTER_DRIVER))
+#define CAMEL_IS_FILTER_DRIVER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_FILTER_DRIVER))
+#define CAMEL_FILTER_DRIVER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_FILTER_DRIVER, CamelFilterDriverClass))
 
 G_BEGIN_DECLS
 
+struct _CamelSession;
+
+typedef struct _CamelFilterDriver CamelFilterDriver;
 typedef struct _CamelFilterDriverClass CamelFilterDriverClass;
+typedef struct _CamelFilterDriverPrivate CamelFilterDriverPrivate;
 
 struct _CamelFilterDriver {
 	CamelObject parent;
-
-	struct _CamelFilterDriverPrivate *priv;
+	CamelFilterDriverPrivate *priv;
 };
 
 struct _CamelFilterDriverClass {
@@ -67,8 +86,8 @@ typedef void (CamelFilterShellFunc)      (CamelFilterDriver *driver, gint argc,
 typedef void (CamelFilterPlaySoundFunc)  (CamelFilterDriver *driver, const gchar *filename, gpointer data);
 typedef void (CamelFilterSystemBeepFunc) (CamelFilterDriver *driver, gpointer data);
 
-CamelType          camel_filter_driver_get_type (void);
-CamelFilterDriver  *camel_filter_driver_new     (CamelSession *);
+GType          camel_filter_driver_get_type (void);
+CamelFilterDriver  *camel_filter_driver_new     (struct _CamelSession *);
 
 /* modifiers */
 void camel_filter_driver_set_logfile          (CamelFilterDriver *d, FILE *logfile);
@@ -111,4 +130,4 @@ struct filter_option *camel_filter_driver_rule_get (CamelFilterDriver *d, gint n
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_FILTER_DRIVER_H */
+#endif /* CAMEL_FILTER_DRIVER_H */
diff --git a/camel/camel-filter-search.c b/camel/camel-filter-search.c
index 01afb29..d078bf2 100644
--- a/camel/camel-filter-search.c
+++ b/camel/camel-filter-search.c
@@ -37,7 +37,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #ifndef G_OS_WIN32
@@ -182,7 +181,8 @@ check_header (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMes
 				}
 			}
 
-			for (header = ((CamelMimePart *)message)->headers; header && !matched; header = header->next) {
+			header = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (message));
+			for (; header && !matched; header = header->next) {
 				if (!g_ascii_strcasecmp(header->name, name)) {
 					for (i=1; i<argc && !matched; i++) {
 						if (argv[i]->type == ESEXP_RES_STRING)
@@ -279,7 +279,7 @@ get_full_header (CamelMimeMessage *message)
 	gchar   *ret;
 	struct _camel_header_raw *h;
 
-	for (h = mp->headers; h; h = h->next) {
+	for (h = camel_mime_part_get_raw_headers (mp); h; h = h->next) {
 		if (h->value != NULL) {
 			g_string_append (str, h->name);
 			if (isspace (h->value[0]))
@@ -589,7 +589,7 @@ run_command (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMess
 	stream = camel_stream_fs_new_with_fd (pipe_to_child);
 	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream);
 	camel_stream_flush (stream);
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	context = g_main_context_new ();
 	child_watch_data.loop = g_main_loop_new (context, FALSE);
@@ -754,13 +754,13 @@ camel_filter_search_match (CamelSession *session,
 	e_sexp_unref (sexp);
 
 	if (fms.message)
-		camel_object_unref (fms.message);
+		g_object_unref (fms.message);
 
 	return retval;
 
  error:
 	if (fms.message)
-		camel_object_unref (fms.message);
+		g_object_unref (fms.message);
 
 	e_sexp_unref (sexp);
 
diff --git a/camel/camel-filter-search.h b/camel/camel-filter-search.h
index c786d0a..a14cd1f 100644
--- a/camel/camel-filter-search.h
+++ b/camel/camel-filter-search.h
@@ -21,15 +21,20 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_FILTER_SEARCH_H
 #define CAMEL_FILTER_SEARCH_H
 
-#include <glib.h>
 #include <camel/camel-mime-message.h>
 #include <camel/camel-folder-summary.h>
 
 G_BEGIN_DECLS
 
+struct _CamelSession;
+
 enum {
 	CAMEL_SEARCH_ERROR    = -1,
 	CAMEL_SEARCH_NOMATCH  =  0,
@@ -38,11 +43,11 @@ enum {
 
 typedef CamelMimeMessage * (*CamelFilterSearchGetMessageFunc) (gpointer data, CamelException *ex);
 
-gint camel_filter_search_match (CamelSession *session,
+gint camel_filter_search_match (struct _CamelSession *session,
 			       CamelFilterSearchGetMessageFunc get_message, gpointer data,
 			       CamelMessageInfo *info, const gchar *source,
 			       const gchar *expression, CamelException *ex);
 
 G_END_DECLS
 
-#endif /* ! CAMEL_FILTER_SEARCH_H */
+#endif /* CAMEL_FILTER_SEARCH_H */
diff --git a/camel/camel-folder-search.c b/camel/camel-folder-search.c
index 24292fa..7069445 100644
--- a/camel/camel-folder-search.c
+++ b/camel/camel-folder-search.c
@@ -35,7 +35,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
@@ -59,6 +58,10 @@
 #define r(x)
 #define dd(x) if (camel_debug("search")) x
 
+#define CAMEL_FOLDER_SEARCH_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearchPrivate))
+
 struct _CamelFolderSearchPrivate {
 	CamelException *ex;
 
@@ -66,8 +69,6 @@ struct _CamelFolderSearchPrivate {
 	GHashTable *threads_hash;
 };
 
-#define _PRIVATE(o) (((CamelFolderSearch *)(o))->priv)
-
 static ESExpResult *search_not(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
 
 static ESExpResult *search_header_contains(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
@@ -94,142 +95,149 @@ static ESExpResult *search_message_location(struct _ESExp *f, gint argc, struct
 
 static ESExpResult *search_dummy(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
 
-static void camel_folder_search_class_init (CamelFolderSearchClass *klass);
-static void camel_folder_search_init       (CamelFolderSearch *obj);
-static void camel_folder_search_finalize   (CamelObject *obj);
-
 static gint read_uid_callback (gpointer  ref, gint ncol, gchar ** cols, gchar **name);
 
-static CamelObjectClass *camel_folder_search_parent;
+static gpointer parent_class;
 
 static void
-camel_folder_search_class_init (CamelFolderSearchClass *klass)
+folder_search_dispose (GObject *object)
 {
-	camel_folder_search_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
-
-	klass->not = search_not;
-
-	klass->match_all = search_match_all;
-	klass->match_threads = search_match_threads;
-	klass->body_contains = search_body_contains;
-	klass->body_regex = search_body_regex;
-	klass->header_contains = search_header_contains;
-	klass->header_matches = search_header_matches;
-	klass->header_starts_with = search_header_starts_with;
-	klass->header_ends_with = search_header_ends_with;
-	klass->header_exists = search_header_exists;
-	klass->header_soundex = search_header_soundex;
-	klass->header_regex = search_header_regex;
-	klass->header_full_regex = search_header_full_regex;
-	klass->user_tag = search_user_tag;
-	klass->user_flag = search_user_flag;
-	klass->system_flag = search_system_flag;
-	klass->get_sent_date = search_get_sent_date;
-	klass->get_received_date = search_get_received_date;
-	klass->get_current_date = search_get_current_date;
-	klass->get_size = search_get_size;
-	klass->uid = search_uid;
-	klass->message_location = search_message_location;
+	CamelFolderSearch *search = CAMEL_FOLDER_SEARCH (object);
+
+	if (search->sexp != NULL) {
+		e_sexp_unref (search->sexp);
+		search->sexp = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_folder_search_init (CamelFolderSearch *obj)
+folder_search_finalize (GObject *object)
 {
-	struct _CamelFolderSearchPrivate *p;
+	CamelFolderSearch *search = CAMEL_FOLDER_SEARCH (object);
 
-	p = _PRIVATE(obj) = g_malloc0(sizeof(*p));
+	g_free (search->last_search);
 
-	obj->sexp = e_sexp_new();
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_folder_search_finalize (CamelObject *obj)
+folder_search_class_init (CamelFolderSearchClass *class)
 {
-	CamelFolderSearch *search = (CamelFolderSearch *)obj;
-	struct _CamelFolderSearchPrivate *p = _PRIVATE(obj);
-
-	if (search->sexp)
-		e_sexp_unref(search->sexp);
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelFolderSearchPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = folder_search_dispose;
+	object_class->finalize = folder_search_finalize;
+
+	class->not = search_not;
+	class->match_all = search_match_all;
+	class->match_threads = search_match_threads;
+	class->body_contains = search_body_contains;
+	class->body_regex = search_body_regex;
+	class->header_contains = search_header_contains;
+	class->header_matches = search_header_matches;
+	class->header_starts_with = search_header_starts_with;
+	class->header_ends_with = search_header_ends_with;
+	class->header_exists = search_header_exists;
+	class->header_soundex = search_header_soundex;
+	class->header_regex = search_header_regex;
+	class->header_full_regex = search_header_full_regex;
+	class->user_tag = search_user_tag;
+	class->user_flag = search_user_flag;
+	class->system_flag = search_system_flag;
+	class->get_sent_date = search_get_sent_date;
+	class->get_received_date = search_get_received_date;
+	class->get_current_date = search_get_current_date;
+	class->get_size = search_get_size;
+	class->uid = search_uid;
+	class->message_location = search_message_location;
+}
 
-	g_free(search->last_search);
-	g_free(p);
+static void
+folder_search_init (CamelFolderSearch *search)
+{
+	search->priv = CAMEL_FOLDER_SEARCH_GET_PRIVATE (search);
+	search->sexp = e_sexp_new();
 }
 
-CamelType
+GType
 camel_folder_search_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (), "CamelFolderSearch",
-					    sizeof (CamelFolderSearch),
-					    sizeof (CamelFolderSearchClass),
-					    (CamelObjectClassInitFunc) camel_folder_search_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_folder_search_init,
-					    (CamelObjectFinalizeFunc) camel_folder_search_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelFolderSearch",
+			sizeof (CamelFolderSearchClass),
+			(GClassInitFunc) folder_search_class_init,
+			sizeof (CamelFolderSearch),
+			(GInstanceInitFunc) folder_search_init,
+			0);
 
 	return type;
 }
 
-#ifdef offsetof
-#define CAMEL_STRUCT_OFFSET(type, field)        ((gint) offsetof (type, field))
-#else
-#define CAMEL_STRUCT_OFFSET(type, field)        ((gint) ((gchar *) &((type *) 0)->field))
-#endif
-
 static struct {
 	const gchar *name;
 	gint offset;
 	gint flags;		/* 0x02 = immediate, 0x01 = always enter */
 } builtins[] = {
 	/* these have default implementations in e-sexp */
-	{ "and", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, and), 2 },
-	{ "or", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, or), 2 },
+	{ "and", G_STRUCT_OFFSET(CamelFolderSearchClass, and), 2 },
+	{ "or", G_STRUCT_OFFSET(CamelFolderSearchClass, or), 2 },
 	/* we need to override this one though to implement an 'array not' */
-	{ "not", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, not), 0 },
-	{ "<", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, lt), 2 },
-	{ ">", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, gt), 2 },
-	{ "=", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, eq), 2 },
+	{ "not", G_STRUCT_OFFSET(CamelFolderSearchClass, not), 0 },
+	{ "<", G_STRUCT_OFFSET(CamelFolderSearchClass, lt), 2 },
+	{ ">", G_STRUCT_OFFSET(CamelFolderSearchClass, gt), 2 },
+	{ "=", G_STRUCT_OFFSET(CamelFolderSearchClass, eq), 2 },
 
 	/* these we have to use our own default if there is none */
 	/* they should all be defined in the language? so it parses, or should they not?? */
-	{ "match-all", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, match_all), 3 },
-	{ "match-threads", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, match_threads), 3 },
-	{ "body-contains", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, body_contains), 1 },
-	{ "body-regex",  CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, body_regex), 1  },
-	{ "header-contains", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_contains), 1 },
-	{ "header-matches", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_matches), 1 },
-	{ "header-starts-with", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_starts_with), 1 },
-	{ "header-ends-with", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_ends_with), 1 },
-	{ "header-exists", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_exists), 1 },
-	{ "header-soundex", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_soundex), 1 },
-	{ "header-regex", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_regex), 1 },
-	{ "header-full-regex", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, header_full_regex), 1 },
-	{ "user-tag", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, user_tag), 1 },
-	{ "user-flag", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, user_flag), 1 },
-	{ "system-flag", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, system_flag), 1 },
-	{ "get-sent-date", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, get_sent_date), 1 },
-	{ "get-received-date", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, get_received_date), 1 },
-	{ "get-current-date", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, get_current_date), 1 },
-	{ "get-size", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, get_size), 1 },
-	{ "uid", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, uid), 1 },
-	{ "message-location", CAMEL_STRUCT_OFFSET(CamelFolderSearchClass, message_location), 1 },
+	{ "match-all", G_STRUCT_OFFSET(CamelFolderSearchClass, match_all), 3 },
+	{ "match-threads", G_STRUCT_OFFSET(CamelFolderSearchClass, match_threads), 3 },
+	{ "body-contains", G_STRUCT_OFFSET(CamelFolderSearchClass, body_contains), 1 },
+	{ "body-regex",  G_STRUCT_OFFSET(CamelFolderSearchClass, body_regex), 1  },
+	{ "header-contains", G_STRUCT_OFFSET(CamelFolderSearchClass, header_contains), 1 },
+	{ "header-matches", G_STRUCT_OFFSET(CamelFolderSearchClass, header_matches), 1 },
+	{ "header-starts-with", G_STRUCT_OFFSET(CamelFolderSearchClass, header_starts_with), 1 },
+	{ "header-ends-with", G_STRUCT_OFFSET(CamelFolderSearchClass, header_ends_with), 1 },
+	{ "header-exists", G_STRUCT_OFFSET(CamelFolderSearchClass, header_exists), 1 },
+	{ "header-soundex", G_STRUCT_OFFSET(CamelFolderSearchClass, header_soundex), 1 },
+	{ "header-regex", G_STRUCT_OFFSET(CamelFolderSearchClass, header_regex), 1 },
+	{ "header-full-regex", G_STRUCT_OFFSET(CamelFolderSearchClass, header_full_regex), 1 },
+	{ "user-tag", G_STRUCT_OFFSET(CamelFolderSearchClass, user_tag), 1 },
+	{ "user-flag", G_STRUCT_OFFSET(CamelFolderSearchClass, user_flag), 1 },
+	{ "system-flag", G_STRUCT_OFFSET(CamelFolderSearchClass, system_flag), 1 },
+	{ "get-sent-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_sent_date), 1 },
+	{ "get-received-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_received_date), 1 },
+	{ "get-current-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_current_date), 1 },
+	{ "get-size", G_STRUCT_OFFSET(CamelFolderSearchClass, get_size), 1 },
+	{ "uid", G_STRUCT_OFFSET(CamelFolderSearchClass, uid), 1 },
+	{ "message-location", G_STRUCT_OFFSET(CamelFolderSearchClass, message_location), 1 },
 };
 
 void
 camel_folder_search_construct (CamelFolderSearch *search)
 {
 	gint i;
-	CamelFolderSearchClass *klass = (CamelFolderSearchClass *)CAMEL_OBJECT_GET_CLASS(search);
+	CamelFolderSearchClass *class;
+
+	class = CAMEL_FOLDER_SEARCH_GET_CLASS (search);
 
 	for (i = 0; i < G_N_ELEMENTS (builtins); i++) {
 		gpointer func;
 		/* c is sure messy sometimes */
-		func = *((gpointer *)(((gchar *)klass)+builtins[i].offset));
+		func = *((gpointer *)(((gchar *)class)+builtins[i].offset));
 		if (func == NULL && builtins[i].flags&1) {
-			g_warning("Search class doesn't implement '%s' method: %s", builtins[i].name, camel_type_to_name(CAMEL_OBJECT_GET_CLASS(search)));
+			g_warning("Search class doesn't implement '%s' method: %s", builtins[i].name, G_OBJECT_TYPE_NAME (search));
 			func = (gpointer)search_dummy;
 		}
 		if (func != NULL) {
@@ -257,9 +265,11 @@ camel_folder_search_construct (CamelFolderSearch *search)
 CamelFolderSearch *
 camel_folder_search_new (void)
 {
-	CamelFolderSearch *new = CAMEL_FOLDER_SEARCH (camel_object_new (camel_folder_search_get_type ()));
+	CamelFolderSearch *new;
 
+	new = g_object_new (CAMEL_TYPE_FOLDER_SEARCH, NULL);
 	camel_folder_search_construct(new);
+
 	return new;
 }
 
@@ -308,10 +318,10 @@ void
 camel_folder_search_set_body_index(CamelFolderSearch *search, CamelIndex *index)
 {
 	if (search->body_index)
-		camel_object_unref((CamelObject *)search->body_index);
+		g_object_unref (search->body_index);
 	search->body_index = index;
 	if (index)
-		camel_object_ref((CamelObject *)index);
+		g_object_ref (index);
 }
 
 /**
@@ -339,7 +349,7 @@ camel_folder_search_execute_expression(CamelFolderSearch *search, const gchar *e
 	GPtrArray *matches;
 	gint i;
 	GHashTable *results;
-	struct _CamelFolderSearchPrivate *p = _PRIVATE(search);
+	CamelFolderSearchPrivate *p = search->priv;
 
 	p->ex = ex;
 
@@ -432,7 +442,7 @@ camel_folder_search_count(CamelFolderSearch *search, const gchar *expr, CamelExc
 	GHashTable *results;
 	guint32 count = 0;
 
-	struct _CamelFolderSearchPrivate *p = _PRIVATE(search);
+	CamelFolderSearchPrivate *p = search->priv;
 
 	g_assert(search->folder);
 
@@ -575,7 +585,7 @@ camel_folder_search_search(CamelFolderSearch *search, const gchar *expr, GPtrArr
 	gchar *sql_query, *tmp, *tmp1;
 	GHashTable *results;
 
-	struct _CamelFolderSearchPrivate *p = _PRIVATE(search);
+	CamelFolderSearchPrivate *p = search->priv;
 
 	g_assert(search->folder);
 
@@ -895,7 +905,7 @@ static ESExpResult *
 search_match_threads(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *search)
 {
 	ESExpResult *r;
-	struct _CamelFolderSearchPrivate *p = search->priv;
+	CamelFolderSearchPrivate *p = search->priv;
 	gint i, type;
 	GHashTable *results;
 	gchar *error_msg;
@@ -1089,7 +1099,7 @@ check_header (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFold
 					truth = TRUE;
 					for (j=0;j<words->len && truth;j++) {
 						if (message) {
-							for (raw_header = ((CamelMimePart *)message)->headers; raw_header; raw_header = raw_header->next) {
+							for (raw_header = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (message)); raw_header; raw_header = raw_header->next) {
 								if (!g_ascii_strcasecmp (raw_header->name, headername)) {
 									if (camel_search_header_match (raw_header->value, words->words[j]->word, how, type, charset))
 										break;;
@@ -1103,7 +1113,7 @@ check_header (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFold
 					camel_search_words_free(words);
 				} else {
 					if (message) {
-						for (raw_header = ((CamelMimePart *)message)->headers; raw_header && !truth; raw_header = raw_header->next) {
+						for (raw_header = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (message)); raw_header && !truth; raw_header = raw_header->next) {
 							if (!g_ascii_strcasecmp (raw_header->name, headername)) {
 								truth = camel_search_header_match(raw_header->value, argv[i]->value.string, how, type, charset);
 							}
@@ -1115,7 +1125,7 @@ check_header (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFold
 		}
 
 		if (message)
-			camel_object_unref (message);
+			g_object_unref (message);
 	}
 	/* TODO: else, find all matches */
 
@@ -1205,7 +1215,7 @@ search_header_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, Ca
 		} else
 			r->value.bool = FALSE;
 
-		camel_object_unref (msg);
+		g_object_unref (msg);
 	} else {
 		r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
 		r->value.ptrarray = g_ptr_array_new();
@@ -1221,7 +1231,7 @@ get_full_header (CamelMimeMessage *message)
 	GString *str = g_string_new ("");
 	struct _camel_header_raw *h;
 
-	for (h = mp->headers; h; h = h->next) {
+	for (h = camel_mime_part_get_raw_headers (mp); h; h = h->next) {
 		if (h->value != NULL) {
 			g_string_append (str, h->name);
 			if (isspace (h->value[0]))
@@ -1260,7 +1270,7 @@ search_header_full_regex (struct _ESExp *f, gint argc, struct _ESExpResult **arg
 		} else
 			r->value.bool = FALSE;
 
-		camel_object_unref (msg);
+		g_object_unref (msg);
 	} else {
 		r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
 		r->value.ptrarray = g_ptr_array_new();
@@ -1306,11 +1316,11 @@ match_message_index(CamelIndex *idx, const gchar *uid, const gchar *match, Camel
 				if (nc) {
 					while (!truth && (name = camel_index_cursor_next(nc)))
 						truth = strcmp(name, uid) == 0;
-					camel_object_unref((CamelObject *)nc);
+					g_object_unref (nc);
 				}
 			}
 		}
-		camel_object_unref((CamelObject *)wc);
+		g_object_unref (wc);
 	}
 
 	return truth;
@@ -1353,12 +1363,12 @@ match_words_index(CamelFolderSearch *search, struct _camel_search_words *words,
 								mask = (GPOINTER_TO_INT(g_hash_table_lookup(ht, name))) | (1<<i);
 								g_hash_table_insert(ht, (gchar *) camel_pstring_peek(name), GINT_TO_POINTER(mask));
 						}
-						camel_object_unref((CamelObject *)nc);
+						g_object_unref (nc);
 					}
 				}
 			}
 		}
-		camel_object_unref((CamelObject *)wc);
+		g_object_unref (wc);
 
 		lambdafoo.uids = result;
 		lambdafoo.count = (1<<words->len) - 1;
@@ -1376,7 +1386,7 @@ match_words_1message (CamelDataWrapper *object, struct _camel_search_words *word
 	gint truth = FALSE;
 	gint parts, i;
 
-	containee = camel_medium_get_content_object (CAMEL_MEDIUM (object));
+	containee = camel_medium_get_content (CAMEL_MEDIUM (object));
 
 	if (containee == NULL)
 		return FALSE;
@@ -1394,14 +1404,18 @@ match_words_1message (CamelDataWrapper *object, struct _camel_search_words *word
 		truth = match_words_1message((CamelDataWrapper *)containee, words, mask);
 	} else if (camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")) {
 		/* for all other text parts, we look inside, otherwise we dont care */
-		CamelStreamMem *mem = (CamelStreamMem *)camel_stream_mem_new ();
+		CamelStream *stream;
+		GByteArray *byte_array;
+
+		byte_array = g_byte_array_new ();
+		stream = camel_stream_mem_new_with_byte_array (byte_array);
 
 		/* FIXME: The match should be part of a stream op */
-		camel_data_wrapper_decode_to_stream (containee, CAMEL_STREAM (mem));
-		camel_stream_write (CAMEL_STREAM (mem), "", 1);
+		camel_data_wrapper_decode_to_stream (containee, stream);
+		camel_stream_write (stream, "", 1);
 		for (i=0;i<words->len;i++) {
 			/* FIXME: This is horridly slow, and should use a real search algorithm */
-			if (camel_ustrstrcase((const gchar *) mem->buffer->data, words->words[i]->word) != NULL) {
+			if (camel_ustrstrcase((const gchar *) byte_array->data, words->words[i]->word) != NULL) {
 				*mask |= (1<<i);
 				/* shortcut a match */
 				if (*mask == (1<<(words->len))-1)
@@ -1409,7 +1423,7 @@ match_words_1message (CamelDataWrapper *object, struct _camel_search_words *word
 			}
 		}
 
-		camel_object_unref (mem);
+		g_object_unref (stream);
 	}
 
 	return truth;
@@ -1427,7 +1441,7 @@ match_words_message(CamelFolder *folder, const gchar *uid, struct _camel_search_
 	if (msg) {
 		mask = 0;
 		truth = match_words_1message((CamelDataWrapper *)msg, words, &mask);
-		camel_object_unref((CamelObject *)msg);
+		g_object_unref (msg);
 	} else {
 		camel_exception_clear(&x);
 		truth = FALSE;
@@ -1561,7 +1575,7 @@ search_body_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, Came
 		} else
 			r->value.bool = FALSE;
 
-		camel_object_unref (msg);
+		g_object_unref (msg);
 	} else {
 		regex_t pattern;
 
@@ -1583,7 +1597,7 @@ search_body_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, Came
 						g_ptr_array_add (r->value.ptrarray, uid);
 					}
 
-					camel_object_unref ((CamelObject *)message);
+					g_object_unref (message);
 				} else {
 					camel_exception_clear (&x);
 				}
diff --git a/camel/camel-folder-search.h b/camel/camel-folder-search.h
index 18f6c25..d8d5c7d 100644
--- a/camel/camel-folder-search.h
+++ b/camel/camel-folder-search.h
@@ -19,27 +19,46 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_FOLDER_SEARCH_H
-#define _CAMEL_FOLDER_SEARCH_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_FOLDER_SEARCH_H
+#define CAMEL_FOLDER_SEARCH_H
 
 #include <libedataserver/e-sexp.h>
 #include <camel/camel-folder.h>
 #include <camel/camel-object.h>
 #include <camel/camel-index.h>
 
-#define CAMEL_FOLDER_SEARCH_TYPE         (camel_folder_search_get_type ())
-#define CAMEL_FOLDER_SEARCH(obj)         CAMEL_CHECK_CAST (obj, camel_folder_search_get_type (), CamelFolderSearch)
-#define CAMEL_FOLDER_SEARCH_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_folder_search_get_type (), CamelFolderSearchClass)
-#define CAMEL_IS_FOLDER_SEARCH(obj)      CAMEL_CHECK_TYPE (obj, camel_folder_search_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_FOLDER_SEARCH \
+	(camel_folder_search_get_type ())
+#define CAMEL_FOLDER_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearch))
+#define CAMEL_FOLDER_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearchClass))
+#define CAMEL_IS_FOLDER_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_FOLDER_SEARCH))
+#define CAMEL_IS_FOLDER_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_FOLDER_SEARCH))
+#define CAMEL_FOLDER_SEARCH_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearchClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelFolderSearch CamelFolderSearch;
 typedef struct _CamelFolderSearchClass CamelFolderSearchClass;
+typedef struct _CamelFolderSearchPrivate CamelFolderSearchPrivate;
 
 struct _CamelFolderSearch {
 	CamelObject parent;
-
-	struct _CamelFolderSearchPrivate *priv;
+	CamelFolderSearchPrivate *priv;
 
 	ESExp *sexp;		/* s-exp evaluator */
 	gchar *last_search;	/* last searched expression */
@@ -130,7 +149,7 @@ struct _CamelFolderSearchClass {
 
 };
 
-CamelType		camel_folder_search_get_type	(void);
+GType		camel_folder_search_get_type	(void);
 CamelFolderSearch      *camel_folder_search_new	(void);
 void camel_folder_search_construct (CamelFolderSearch *search);
 
@@ -147,4 +166,4 @@ void camel_folder_search_free_result(CamelFolderSearch *search, GPtrArray *);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_FOLDER_SEARCH_H */
+#endif /* CAMEL_FOLDER_SEARCH_H */
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 060c3a3..3229017 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -33,7 +33,6 @@
 #include <fcntl.h>
 #include <errno.h>
 
-#include <glib.h>
 #include <glib-object.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
@@ -63,6 +62,10 @@
 #include "camel-vee-folder.h"
 #include "camel-mime-part-utils.h"
 
+#define CAMEL_FOLDER_SUMMARY_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_FOLDER_SUMMARY, CamelFolderSummaryPrivate))
+
 /* To switch between e-memchunk and g-alloc */
 #define ALWAYS_ALLOC 1
 #define USE_GSLICE 1
@@ -90,8 +93,6 @@ extern gint strdup_count, malloc_count, free_count;
 
 #define CAMEL_FOLDER_SUMMARY_VERSION (14)
 
-#define _PRIVATE(o) (((CamelFolderSummary *)(o))->priv)
-
 #define META_SUMMARY_SUFFIX_LEN 5 /* strlen("-meta") */
 
 #define EXTRACT_FIRST_STRING(val) len=strtoul (part, &part, 10); if (*part) part++; val=g_strndup (part, len); part+=len;
@@ -137,134 +138,846 @@ static gchar *next_uid_string(CamelFolderSummary *s);
 static CamelMessageContentInfo * summary_build_content_info(CamelFolderSummary *s, CamelMessageInfo *msginfo, CamelMimeParser *mp);
 static CamelMessageContentInfo * summary_build_content_info_message(CamelFolderSummary *s, CamelMessageInfo *msginfo, CamelMimePart *object);
 
-static void camel_folder_summary_class_init (CamelFolderSummaryClass *klass);
-static void camel_folder_summary_init       (CamelFolderSummary *obj);
-static void camel_folder_summary_finalize   (CamelObject *obj);
-
-static CamelObjectClass *camel_folder_summary_parent;
 static CamelMessageInfo * message_info_from_uid (CamelFolderSummary *s, const gchar *uid);
 
+static gpointer parent_class;
+
 static void
-camel_folder_summary_init (CamelFolderSummary *s)
+free_o_name(gpointer key, gpointer value, gpointer data)
 {
-	struct _CamelFolderSummaryPrivate *p;
+	g_object_unref (value);
+	g_free(key);
+}
 
-	p = _PRIVATE(s) = g_malloc0(sizeof(*p));
+static void
+folder_summary_dispose (GObject *object)
+{
+	CamelFolderSummaryPrivate *priv;
 
-	p->filter_charset = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
+	priv = CAMEL_FOLDER_SUMMARY_GET_PRIVATE (object);
 
-	s->message_info_size = sizeof(CamelMessageInfoBase);
-	s->content_info_size = sizeof(CamelMessageContentInfo);
-	p->flag_cache = g_hash_table_new (g_str_hash, g_str_equal);
+	if (priv->filter_index != NULL) {
+		g_object_unref (priv->filter_index);
+		priv->filter_index = NULL;
+	}
 
-	s->message_info_chunks = NULL;
-	s->content_info_chunks = NULL;
-	p->need_preview = FALSE;
-	p->preview_updates = g_hash_table_new (g_str_hash, g_str_equal);
+	if (priv->filter_64 != NULL) {
+		g_object_unref (priv->filter_64);
+		priv->filter_64 = NULL;
+	}
 
-	s->version = CAMEL_FOLDER_SUMMARY_VERSION;
-	s->flags = 0;
-	s->time = 0;
-	s->nextuid = 1;
+	if (priv->filter_qp != NULL) {
+		g_object_unref (priv->filter_qp);
+		priv->filter_qp = NULL;
+	}
 
-	s->uids = g_ptr_array_new ();
-	s->loaded_infos = g_hash_table_new (g_str_hash, g_str_equal);
+	if (priv->filter_uu != NULL) {
+		g_object_unref (priv->filter_uu);
+		priv->filter_uu = NULL;
+	}
 
-	p->summary_lock = g_mutex_new();
-	p->io_lock = g_mutex_new();
-	p->filter_lock = g_mutex_new();
-	p->alloc_lock = g_mutex_new();
-	p->ref_lock = g_mutex_new();
+	if (priv->filter_save != NULL) {
+		g_object_unref (priv->filter_save);
+		priv->filter_save = NULL;
+	}
 
-	s->meta_summary = g_malloc0(sizeof(CamelFolderMetaSummary));
+	if (priv->filter_html != NULL) {
+		g_object_unref (priv->filter_html);
+		priv->filter_html = NULL;
+	}
 
-	/* Default is 20, any implementor having UIDs that has length
-	   exceeding 20, has to override this value
-	*/
-	s->meta_summary->uid_len = 20;
-	s->cache_load_time = 0;
-	s->timeout_handle = 0;
-}
+	if (priv->filter_stream != NULL) {
+		g_object_unref (priv->filter_stream);
+		priv->filter_stream = NULL;
+	}
 
-static void free_o_name(gpointer key, gpointer value, gpointer data)
-{
-	camel_object_unref((CamelObject *)value);
-	g_free(key);
+	if (priv->index != NULL) {
+		g_object_unref (priv->index);
+		priv->index = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_folder_summary_finalize (CamelObject *obj)
+folder_summary_finalize (GObject *object)
 {
-	struct _CamelFolderSummaryPrivate *p;
-	CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (object);
 
-	p = _PRIVATE(obj);
-	g_hash_table_destroy (p->flag_cache);
-	if (s->timeout_handle)
-		g_source_remove (s->timeout_handle);
+	g_hash_table_destroy (summary->priv->flag_cache);
+	if (summary->timeout_handle)
+		g_source_remove (summary->timeout_handle);
 	/*camel_folder_summary_clear(s);*/
-	g_ptr_array_foreach (s->uids, (GFunc) camel_pstring_free, NULL);
-	g_ptr_array_free (s->uids, TRUE);
-	g_hash_table_destroy (s->loaded_infos);
+	g_ptr_array_foreach (summary->uids, (GFunc) camel_pstring_free, NULL);
+	g_ptr_array_free (summary->uids, TRUE);
+	g_hash_table_destroy (summary->loaded_infos);
 
-	g_hash_table_foreach(p->filter_charset, free_o_name, NULL);
-	g_hash_table_destroy(p->filter_charset);
+	g_hash_table_foreach(summary->priv->filter_charset, free_o_name, NULL);
+	g_hash_table_destroy(summary->priv->filter_charset);
 
-	g_free(s->summary_path);
+	g_free(summary->summary_path);
 
 #ifndef ALWAYS_ALLOC
-	if (s->message_info_chunks)
-		e_memchunk_destroy(s->message_info_chunks);
-	if (s->content_info_chunks)
-		e_memchunk_destroy(s->content_info_chunks);
+	if (summary->message_info_chunks)
+		e_memchunk_destroy(summary->message_info_chunks);
+	if (summary->content_info_chunks)
+		e_memchunk_destroy(summary->content_info_chunks);
 #endif
 
-	if (p->filter_index)
-		camel_object_unref((CamelObject *)p->filter_index);
-	if (p->filter_64)
-		camel_object_unref((CamelObject *)p->filter_64);
-	if (p->filter_qp)
-		camel_object_unref((CamelObject *)p->filter_qp);
-	if (p->filter_uu)
-		camel_object_unref((CamelObject *)p->filter_uu);
-	if (p->filter_save)
-		camel_object_unref((CamelObject *)p->filter_save);
-	if (p->filter_html)
-		camel_object_unref((CamelObject *)p->filter_html);
-
-	if (p->filter_stream)
-		camel_object_unref((CamelObject *)p->filter_stream);
-	if (p->index)
-		camel_object_unref((CamelObject *)p->index);
-
 	/* Freeing memory occupied by meta-summary-header */
-	g_free(s->meta_summary->path);
-	g_free(s->meta_summary);
+	g_free(summary->meta_summary->path);
+	g_free(summary->meta_summary);
 
-	g_mutex_free(p->summary_lock);
-	g_mutex_free(p->io_lock);
-	g_mutex_free(p->filter_lock);
-	g_mutex_free(p->alloc_lock);
-	g_mutex_free(p->ref_lock);
+	g_mutex_free(summary->priv->summary_lock);
+	g_mutex_free(summary->priv->io_lock);
+	g_mutex_free(summary->priv->filter_lock);
+	g_mutex_free(summary->priv->alloc_lock);
+	g_mutex_free(summary->priv->ref_lock);
 
-	g_free(p);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
-CamelType
-camel_folder_summary_get_type (void)
+static	gint
+summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *record)
+{
+	io(printf("Loading header from db \n"));
+
+	s->version = record->version;
+
+	/* We may not worry, as we are setting a new standard here */
+#if 0
+	/* Legacy version check, before version 12 we have no upgrade knowledge */
+	if ((s->version > 0xff) && (s->version & 0xff) < 12) {
+		io(printf ("Summary header version mismatch"));
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (!(s->version < 0x100 && s->version >= 13))
+		io(printf("Loading legacy summary\n"));
+	else
+		io(printf("loading new-format summary\n"));
+#endif
+
+	s->flags = record->flags;
+	s->nextuid = record->nextuid;
+	s->time = record->time;
+	s->saved_count = record->saved_count;
+
+	s->unread_count = record->unread_count;
+	s->deleted_count = record->deleted_count;
+	s->junk_count = record->junk_count;
+	s->visible_count = record->visible_count;
+	s->junk_not_deleted_count = record->jnd_count;
+
+	return 0;
+}
+
+static	CamelFIRecord *
+summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
+{
+	CamelFIRecord * record = g_new0 (CamelFIRecord, 1);
+	CamelDB *db;
+	gchar *table_name;
+
+	/* Though we are going to read, we do this during write, so lets use it that way */
+	db = s->folder->parent_store->cdb_w;
+	table_name = s->folder->full_name;
+
+	io(printf("Savining header to db\n"));
+
+	record->folder_name = table_name;
+
+	/* we always write out the current version */
+	record->version = CAMEL_FOLDER_SUMMARY_VERSION;
+	record->flags  = s->flags;
+	record->nextuid = s->nextuid;
+	record->time = s->time;
+
+	/* FIXME: Ever heard of Constructors and initializing ? */
+	if (camel_db_count_total_message_info (db, table_name, &(record->saved_count), NULL))
+		record->saved_count = 0;
+	if (camel_db_count_junk_message_info (db, table_name, &(record->junk_count), NULL))
+		record->junk_count = 0;
+	if (camel_db_count_deleted_message_info (db, table_name, &(record->deleted_count), NULL))
+		record->deleted_count = 0;
+	if (camel_db_count_unread_message_info (db, table_name, &(record->unread_count), NULL))
+		record->unread_count = 0;
+	if (camel_db_count_visible_message_info (db, table_name, &(record->visible_count), NULL))
+		record->visible_count = 0;
+	if (camel_db_count_junk_not_deleted_message_info (db, table_name, &(record->jnd_count), NULL))
+		record->jnd_count = 0;
+
+	s->unread_count = record->unread_count;
+	s->deleted_count = record->deleted_count;
+	s->junk_count = record->junk_count;
+	s->visible_count = record->visible_count;
+	s->junk_not_deleted_count = record->jnd_count;
+
+	return record;
+}
+
+static CamelMessageInfo *
+message_info_from_db (CamelFolderSummary *s, CamelMIRecord *record)
+{
+	CamelMessageInfoBase *mi;
+	gint i;
+	gint count;
+	gchar *part, *label;
+
+	mi = (CamelMessageInfoBase *)camel_message_info_new(s);
+
+	io(printf("Loading message info from db\n"));
+
+	mi->flags = record->flags;
+	mi->size = record->size;
+	mi->date_sent = record->dsent;
+	mi->date_received = record->dreceived;
+
+	mi->uid = (gchar *) camel_pstring_strdup (record->uid);
+	mi->subject = (gchar *) camel_pstring_add (record->subject, FALSE);
+	mi->from = (gchar *) camel_pstring_add (record->from, FALSE);
+	mi->to = (gchar *) camel_pstring_add (record->to, FALSE);
+	mi->cc = (gchar *) camel_pstring_add (record->cc, FALSE);
+	mi->mlist = (gchar *) camel_pstring_add (record->mlist, FALSE);
+
+	/* Evolution itself doesn't yet use this, so we ignore it (saving some memory) */
+	mi->bodystructure = NULL;
+
+	/* Extract Message id & References */
+	mi->content = NULL;
+	part = record->part;
+	if (part) {
+		EXTRACT_FIRST_DIGIT (mi->message_id.id.part.hi)
+		EXTRACT_DIGIT (mi->message_id.id.part.lo)
+		EXTRACT_DIGIT (count)
+
+		if (count > 0) {
+			mi->references = g_malloc(sizeof(*mi->references) + ((count-1) * sizeof(mi->references->references[0])));
+			mi->references->size = count;
+			for (i=0;i<count;i++) {
+				EXTRACT_DIGIT (mi->references->references[i].id.part.hi)
+				EXTRACT_DIGIT (mi->references->references[i].id.part.lo)
+			}
+		} else
+			mi->references = NULL;
+
+	}
+
+	/* Extract User flags/labels */
+	part = record->labels;
+	if (part) {
+		label = part;
+		for (i=0;part[i];i++) {
+
+			if (part[i] == ' ') {
+				part[i] = 0;
+				camel_flag_set(&mi->user_flags, label, TRUE);
+				label = &(part[i+1]);
+			}
+		}
+		camel_flag_set(&mi->user_flags, label, TRUE);
+	}
+
+	/* Extract User tags */
+	part = record->usertags;
+	EXTRACT_FIRST_DIGIT (count)
+	for (i=0;i<count;i++) {
+		gint len;
+		gchar *name, *value;
+		EXTRACT_STRING (name)
+		EXTRACT_STRING (value)
+		camel_tag_set(&mi->user_tags, name, value);
+		g_free(name);
+		g_free(value);
+	}
+
+	return (CamelMessageInfo *) mi;
+}
+
+static CamelMIRecord *
+message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info)
+{
+	CamelMIRecord *record = g_new0(CamelMIRecord, 1);
+	CamelMessageInfoBase *mi = (CamelMessageInfoBase *) info;
+	GString *tmp;
+	CamelFlag *flag;
+	CamelTag *tag;
+	gint count, i;
+
+	/* Assume that we dont have to take care of DB Safeness. It will be done while doing the DB transaction */
+	record->uid = (gchar *) camel_pstring_strdup(camel_message_info_uid(mi));
+	record->flags = mi->flags;
+
+	record->read =  ((mi->flags & (CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK))) ? 1 : 0;
+	record->deleted = mi->flags & CAMEL_MESSAGE_DELETED ? 1 : 0;
+	record->replied = mi->flags & CAMEL_MESSAGE_ANSWERED ? 1 : 0;
+	record->important = mi->flags & CAMEL_MESSAGE_FLAGGED ? 1 : 0;
+	record->junk = mi->flags & CAMEL_MESSAGE_JUNK ? 1 : 0;
+	record->dirty = mi->flags & CAMEL_MESSAGE_FOLDER_FLAGGED ? 1 : 0;
+	record->attachment = mi->flags & CAMEL_MESSAGE_ATTACHMENTS ? 1 : 0;
+
+	record->size = mi->size;
+	record->dsent = mi->date_sent;
+	record->dreceived = mi->date_received;
+
+	record->subject = (gchar *) camel_pstring_strdup(camel_message_info_subject (mi));
+	record->from = (gchar *) camel_pstring_strdup(camel_message_info_from (mi));
+	record->to = (gchar *) camel_pstring_strdup(camel_message_info_to (mi));
+	record->cc = (gchar *) camel_pstring_strdup(camel_message_info_cc (mi));
+	record->mlist = (gchar *) camel_pstring_strdup(camel_message_info_mlist (mi));
+
+	record->followup_flag = (gchar *) camel_pstring_strdup(camel_message_info_user_tag(info, "follow-up"));
+	record->followup_completed_on = (gchar *) camel_pstring_strdup(camel_message_info_user_tag(info, "completed-on"));
+	record->followup_due_by = (gchar *) camel_pstring_strdup(camel_message_info_user_tag(info, "due-by"));
+
+	record->bodystructure = mi->bodystructure ? g_strdup (mi->bodystructure) : NULL;
+
+	tmp = g_string_new (NULL);
+	if (mi->references) {
+		g_string_append_printf (tmp, "%lu %lu %lu", (gulong)mi->message_id.id.part.hi, (gulong)mi->message_id.id.part.lo, (gulong)mi->references->size);
+		for (i=0;i<mi->references->size;i++)
+			g_string_append_printf (tmp, " %lu %lu", (gulong)mi->references->references[i].id.part.hi, (gulong)mi->references->references[i].id.part.lo);
+	} else {
+		g_string_append_printf (tmp, "%lu %lu %lu", (gulong)mi->message_id.id.part.hi, (gulong)mi->message_id.id.part.lo, (gulong) 0);
+	}
+	record->part = tmp->str;
+	g_string_free (tmp, FALSE);
+
+	tmp = g_string_new (NULL);
+	flag = mi->user_flags;
+	while (flag) {
+		g_string_append_printf (tmp, "%s ", flag->name);
+		flag = flag->next;
+	}
+
+	/* Strip off the last space */
+	if (tmp->len)
+		tmp->len--;
+
+	record->labels = tmp->str;
+	g_string_free (tmp, FALSE);
+
+	tmp = g_string_new (NULL);
+	count = camel_tag_list_size(&mi->user_tags);
+	g_string_append_printf (tmp, "%lu", (gulong)count);
+	tag = mi->user_tags;
+	while (tag) {
+		/* FIXME: Should we handle empty tags? Can it be empty? If it potential crasher ahead*/
+		g_string_append_printf (tmp, " %lu-%s %lu-%s", (gulong)strlen(tag->name), tag->name, (gulong)strlen(tag->value), tag->value);
+		tag = tag->next;
+	}
+	record->usertags = tmp->str;
+	g_string_free (tmp, FALSE);
+
+	return record;
+}
+
+static CamelMessageContentInfo *
+content_info_from_db(CamelFolderSummary *s, CamelMIRecord *record)
+{
+	CamelMessageContentInfo *ci;
+	gchar *type, *subtype;
+	guint32 count, i;
+	CamelContentType *ct;
+	gchar *part = record->cinfo;
+	gint len;
+
+	io(printf("Loading content info from db\n"));
+
+	if (!part)
+		return NULL;
+
+	ci = camel_folder_summary_content_info_new(s);
+	if (*part == ' ') part++; /* Move off the space in the record*/
+
+	EXTRACT_FIRST_STRING (type)
+	EXTRACT_STRING (subtype)
+	ct = camel_content_type_new(type, subtype);
+	g_free(type);		/* can this be removed? */
+	g_free(subtype);
+	EXTRACT_DIGIT (count)
+
+	for (i = 0; i < count; i++) {
+		gchar *name, *value;
+		EXTRACT_STRING (name)
+		EXTRACT_STRING (value)
+
+		camel_content_type_set_param(ct, name, value);
+		/* TODO: do this so we dont have to double alloc/free */
+		g_free(name);
+		g_free(value);
+	}
+	ci->type = ct;
+
+	/* FIXME[disk-summary] move all these to camel pstring */
+	EXTRACT_STRING (ci->id);
+	EXTRACT_STRING (ci->description)
+	EXTRACT_STRING (ci->encoding)
+	EXTRACT_DIGIT (ci->size)
+
+	record->cinfo = part; /* Keep moving the cursor in the record */
+
+	ci->childs = NULL;
+
+	return ci;
+}
+
+static gint
+content_info_to_db(CamelFolderSummary *s, CamelMessageContentInfo *ci, CamelMIRecord *record)
+{
+	CamelContentType *ct;
+	struct _camel_header_param *hp;
+	GString *str = g_string_new (NULL);
+	gchar *oldr;
+
+	io(printf("Saving content info to db\n"));
+
+	ct = ci->type;
+	if (ct) {
+		if (ct->type)
+			g_string_append_printf (str, " %d-%s", (gint) strlen (ct->type), ct->type);
+		else
+			g_string_append_printf (str, " 0-");
+		if (ct->subtype)
+			g_string_append_printf (str, " %d-%s", (gint) strlen (ct->subtype), ct->subtype);
+		else
+			g_string_append_printf (str, " 0-");
+		g_string_append_printf (str, " %d", my_list_size((struct _node **)&ct->params));
+		hp = ct->params;
+		while (hp) {
+			if (hp->name)
+				g_string_append_printf (str, " %d-%s", (gint)strlen(hp->name), hp->name);
+			else
+				g_string_append_printf (str, " 0-");
+			if (hp->value)
+				g_string_append_printf (str, " %d-%s", (gint)strlen (hp->value), hp->value);
+			else
+				g_string_append_printf (str, " 0-");
+			hp = hp->next;
+		}
+	} else {
+		g_string_append_printf (str, " %d-", 0);
+		g_string_append_printf (str, " %d-", 0);
+		g_string_append_printf (str, " %d", 0);
+	}
+
+	if (ci->id)
+		g_string_append_printf (str, " %d-%s", (gint)strlen (ci->id), ci->id);
+	else
+		g_string_append_printf (str, " 0-");
+	if (ci->description)
+		g_string_append_printf (str, " %d-%s", (gint)strlen (ci->description), ci->description);
+	else
+		g_string_append_printf (str, " 0-");
+	if (ci->encoding)
+		g_string_append_printf (str, " %d-%s", (gint)strlen (ci->encoding), ci->encoding);
+	else
+		g_string_append_printf (str, " 0-");
+	g_string_append_printf (str, " %u", ci->size);
+
+	if (record->cinfo) {
+		oldr = record->cinfo;
+		record->cinfo = g_strconcat(oldr, str->str, NULL);
+		g_free (oldr); g_string_free (str, TRUE);
+	} else {
+		record->cinfo = str->str;
+		g_string_free (str, FALSE);
+	}
+
+	return 0;
+}
+
+static gint
+summary_header_save(CamelFolderSummary *s, FILE *out)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	gint unread = 0, deleted = 0, junk = 0, count, i;
+
+	fseek(out, 0, SEEK_SET);
+
+	io(printf("Savining header\n"));
 
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (), "CamelFolderSummary",
-					    sizeof (CamelFolderSummary),
-					    sizeof (CamelFolderSummaryClass),
-					    (CamelObjectClassInitFunc) camel_folder_summary_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_folder_summary_init,
-					    (CamelObjectFinalizeFunc) camel_folder_summary_finalize);
+	/* we always write out the current version */
+	camel_file_util_encode_fixed_int32(out, CAMEL_FOLDER_SUMMARY_VERSION);
+	camel_file_util_encode_fixed_int32(out, s->flags);
+	camel_file_util_encode_fixed_int32(out, s->nextuid);
+	camel_file_util_encode_time_t(out, s->time);
+
+	count = camel_folder_summary_count(s);
+	for (i=0; i<count; i++) {
+		CamelMessageInfo *info = camel_folder_summary_index(s, i);
+		guint32 flags;
+
+		if (info == NULL)
+			continue;
+
+		flags = camel_message_info_flags(info);
+		if ((flags & CAMEL_MESSAGE_SEEN) == 0)
+			unread++;
+		if ((flags & CAMEL_MESSAGE_DELETED) != 0)
+			deleted++;
+		if ((flags & CAMEL_MESSAGE_JUNK) != 0)
+			junk++;
+
+		camel_message_info_free(info);
+	}
+
+	camel_file_util_encode_fixed_int32(out, count);
+	camel_file_util_encode_fixed_int32(out, unread);
+	camel_file_util_encode_fixed_int32(out, deleted);
+
+	return camel_file_util_encode_fixed_int32(out, junk);
+}
+
+static CamelMessageInfo *
+message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
+{
+	CamelMessageInfoBase *to, *from = (CamelMessageInfoBase *)mi;
+	CamelFlag *flag;
+	CamelTag *tag;
+
+	to = (CamelMessageInfoBase *)camel_message_info_new(s);
+
+	to->flags = from->flags;
+	to->size = from->size;
+	to->date_sent = from->date_sent;
+	to->date_received = from->date_received;
+	to->refcount = 1;
+
+	/* NB: We don't clone the uid */
+
+	to->subject = camel_pstring_strdup(from->subject);
+	to->from = camel_pstring_strdup(from->from);
+	to->to = camel_pstring_strdup(from->to);
+	to->cc = camel_pstring_strdup(from->cc);
+	to->mlist = camel_pstring_strdup(from->mlist);
+	memcpy(&to->message_id, &from->message_id, sizeof(to->message_id));
+	to->preview = g_strdup (from->preview);
+	if (from->references) {
+		gint len = sizeof(*from->references) + ((from->references->size-1) * sizeof(from->references->references[0]));
+
+		to->references = g_malloc(len);
+		memcpy(to->references, from->references, len);
 	}
 
+	flag = from->user_flags;
+	while (flag) {
+		camel_flag_set(&to->user_flags, flag->name, TRUE);
+		flag = flag->next;
+	}
+
+	tag = from->user_tags;
+	while (tag) {
+		camel_tag_set(&to->user_tags, tag->name, tag->value);
+		tag = tag->next;
+	}
+
+	if (from->content) {
+		/* FIXME: copy content-infos */
+	}
+
+	return (CamelMessageInfo *)to;
+}
+
+static gconstpointer
+info_ptr(const CamelMessageInfo *mi, gint id)
+{
+	switch (id) {
+	case CAMEL_MESSAGE_INFO_SUBJECT:
+		return ((const CamelMessageInfoBase *)mi)->subject;
+	case CAMEL_MESSAGE_INFO_FROM:
+		return ((const CamelMessageInfoBase *)mi)->from;
+	case CAMEL_MESSAGE_INFO_TO:
+		return ((const CamelMessageInfoBase *)mi)->to;
+	case CAMEL_MESSAGE_INFO_CC:
+		return ((const CamelMessageInfoBase *)mi)->cc;
+	case CAMEL_MESSAGE_INFO_MLIST:
+		return ((const CamelMessageInfoBase *)mi)->mlist;
+	case CAMEL_MESSAGE_INFO_MESSAGE_ID:
+		return &((const CamelMessageInfoBase *)mi)->message_id;
+	case CAMEL_MESSAGE_INFO_REFERENCES:
+		return ((const CamelMessageInfoBase *)mi)->references;
+	case CAMEL_MESSAGE_INFO_USER_FLAGS:
+		return ((const CamelMessageInfoBase *)mi)->user_flags;
+	case CAMEL_MESSAGE_INFO_USER_TAGS:
+		return ((const CamelMessageInfoBase *)mi)->user_tags;
+	case CAMEL_MESSAGE_INFO_HEADERS:
+		return ((const CamelMessageInfoBase *)mi)->headers;
+	case CAMEL_MESSAGE_INFO_PREVIEW:
+		return ((const CamelMessageInfoBase *)mi)->preview;
+
+	default:
+		abort();
+	}
+}
+
+static guint32
+info_uint32(const CamelMessageInfo *mi, gint id)
+{
+	switch (id) {
+	case CAMEL_MESSAGE_INFO_FLAGS:
+		return ((const CamelMessageInfoBase *)mi)->flags;
+	case CAMEL_MESSAGE_INFO_SIZE:
+		return ((const CamelMessageInfoBase *)mi)->size;
+	default:
+		abort();
+	}
+}
+
+static time_t
+info_time(const CamelMessageInfo *mi, gint id)
+{
+	switch (id) {
+	case CAMEL_MESSAGE_INFO_DATE_SENT:
+		return ((const CamelMessageInfoBase *)mi)->date_sent;
+	case CAMEL_MESSAGE_INFO_DATE_RECEIVED:
+		return ((const CamelMessageInfoBase *)mi)->date_received;
+	default:
+		abort();
+	}
+}
+
+static gboolean
+info_user_flag(const CamelMessageInfo *mi, const gchar *id)
+{
+	return camel_flag_get(&((CamelMessageInfoBase *)mi)->user_flags, id);
+}
+
+static const gchar *
+info_user_tag(const CamelMessageInfo *mi, const gchar *id)
+{
+	return camel_tag_get(&((CamelMessageInfoBase *)mi)->user_tags, id);
+}
+
+static gboolean
+info_set_user_flag(CamelMessageInfo *info, const gchar *name, gboolean value)
+{
+	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
+	gint res;
+
+	res = camel_flag_set(&mi->user_flags, name, value);
+
+	/* TODO: check this item is still in the summary first */
+	if (mi->summary && res && mi->summary->folder && mi->uid) {
+		CamelFolderChangeInfo *changes = camel_folder_change_info_new();
+
+		mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
+		mi->dirty = TRUE;
+		camel_folder_summary_touch(mi->summary);
+		camel_folder_change_info_change_uid(changes, camel_message_info_uid(info));
+		camel_object_trigger_event(mi->summary->folder, "folder_changed", changes);
+		camel_folder_change_info_free(changes);
+	}
+
+	return res;
+}
+
+static gboolean
+info_set_user_tag(CamelMessageInfo *info, const gchar *name, const gchar *value)
+{
+	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
+	gint res;
+
+	res = camel_tag_set(&mi->user_tags, name, value);
+
+	if (mi->summary && res && mi->summary->folder && mi->uid) {
+		CamelFolderChangeInfo *changes = camel_folder_change_info_new();
+
+		mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
+		mi->dirty = TRUE;
+		camel_folder_summary_touch(mi->summary);
+		camel_folder_change_info_change_uid(changes, camel_message_info_uid(info));
+		camel_object_trigger_event(mi->summary->folder, "folder_changed", changes);
+		camel_folder_change_info_free(changes);
+	}
+
+	return res;
+}
+
+static gboolean
+info_set_flags(CamelMessageInfo *info, guint32 flags, guint32 set)
+{
+	guint32 old;
+	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
+	gint read=0, deleted=0, junk=0;
+	/* TODO: locking? */
+
+	if (flags & CAMEL_MESSAGE_SEEN && ((set & CAMEL_MESSAGE_SEEN) != (mi->flags & CAMEL_MESSAGE_SEEN)))
+	{ read = set & CAMEL_MESSAGE_SEEN ? 1 : -1; d(printf("Setting read as %d\n", set & CAMEL_MESSAGE_SEEN ? 1 : 0));}
+
+	if (flags & CAMEL_MESSAGE_DELETED && ((set & CAMEL_MESSAGE_DELETED) != (mi->flags & CAMEL_MESSAGE_DELETED)))
+	{ deleted = set & CAMEL_MESSAGE_DELETED ? 1 : -1; d(printf("Setting deleted as %d\n", set & CAMEL_MESSAGE_DELETED ? 1 : 0));}
+
+	if (flags & CAMEL_MESSAGE_JUNK && ((set & CAMEL_MESSAGE_JUNK) != (mi->flags & CAMEL_MESSAGE_JUNK)))
+	{ junk = set & CAMEL_MESSAGE_JUNK ? 1 : -1; d(printf("Setting junk as %d\n", set & CAMEL_MESSAGE_JUNK ? 1 : 0));}
+
+	old = mi->flags;
+	mi->flags = (old & ~flags) | (set & flags);
+	if (old != mi->flags) {
+		mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
+		mi->dirty = TRUE;
+		if (mi->summary)
+			camel_folder_summary_touch(mi->summary);
+	}
+
+	if (((old & ~CAMEL_MESSAGE_SYSTEM_MASK) == (mi->flags & ~CAMEL_MESSAGE_SYSTEM_MASK)) && !((set & CAMEL_MESSAGE_JUNK_LEARN) && !(set & CAMEL_MESSAGE_JUNK)))
+		return FALSE;
+
+	if (mi->summary) {
+		if (read && junk == 0 && !(mi->flags & CAMEL_MESSAGE_JUNK))
+			mi->summary->unread_count -= read;
+		else if (junk > 0)
+			mi->summary->unread_count -= (old & CAMEL_MESSAGE_SEEN) ? 0 : 1;
+		else if (junk < 0)
+			mi->summary->unread_count -= (old & CAMEL_MESSAGE_SEEN) ? 0 : -1;
+
+		if (deleted)
+			mi->summary->deleted_count += deleted;
+		if (junk)
+			mi->summary->junk_count += junk;
+		if (junk && !deleted)
+			mi->summary->junk_not_deleted_count += junk;
+		else if ((mi->flags & CAMEL_MESSAGE_JUNK) && deleted)
+			mi->summary->junk_not_deleted_count -= deleted;
+
+		if (((junk && !(mi->flags & CAMEL_MESSAGE_DELETED)))||  (deleted && !(mi->flags & CAMEL_MESSAGE_JUNK)) )
+			mi->summary->visible_count -= junk ? junk : deleted;
+	}
+	if (mi->uid)
+		g_hash_table_replace (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(mi->summary)->flag_cache, (gchar *)mi->uid, GUINT_TO_POINTER(mi->flags));
+	if (mi->summary && mi->summary->folder && mi->uid) {
+		CamelFolderChangeInfo *changes = camel_folder_change_info_new();
+
+		camel_folder_change_info_change_uid(changes, camel_message_info_uid(info));
+		camel_object_trigger_event(mi->summary->folder, "folder_changed", changes);
+		camel_folder_change_info_free(changes);
+	}
+
+	d(printf("%d %d %d %d %d\n", mi->summary->unread_count, mi->summary->deleted_count, mi->summary->junk_count, mi->summary->junk_not_deleted_count, mi->summary->visible_count));
+	return TRUE;
+}
+
+static void
+folder_summary_class_init (CamelFolderSummaryClass *class)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelFolderSummaryPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = folder_summary_dispose;
+	object_class->finalize = folder_summary_finalize;
+
+	class->summary_header_load = summary_header_load;
+	class->summary_header_save = summary_header_save;
+
+	class->summary_header_from_db = summary_header_from_db;
+	class->summary_header_to_db = summary_header_to_db;
+	class->message_info_from_db = message_info_from_db;
+	class->message_info_to_db = message_info_to_db;
+	class->content_info_from_db = content_info_from_db;
+	class->content_info_to_db = content_info_to_db;
+
+	class->message_info_new_from_header  = message_info_new_from_header;
+	class->message_info_new_from_parser = message_info_new_from_parser;
+	class->message_info_new_from_message = message_info_new_from_message;
+	class->message_info_load = message_info_load;
+	class->message_info_save = message_info_save;
+	class->meta_message_info_save = meta_message_info_save;
+	class->message_info_free = message_info_free;
+	class->message_info_clone = message_info_clone;
+	class->message_info_from_uid = message_info_from_uid;
+
+	class->content_info_new_from_header  = content_info_new_from_header;
+	class->content_info_new_from_parser = content_info_new_from_parser;
+	class->content_info_new_from_message = content_info_new_from_message;
+	class->content_info_load = content_info_load;
+	class->content_info_save = content_info_save;
+	class->content_info_free = content_info_free;
+
+	class->next_uid_string = next_uid_string;
+
+	class->info_ptr = info_ptr;
+	class->info_uint32 = info_uint32;
+	class->info_time = info_time;
+	class->info_user_flag = info_user_flag;
+	class->info_user_tag = info_user_tag;
+
+#if 0
+	class->info_set_string = info_set_string;
+	class->info_set_uint32 = info_set_uint32;
+	class->info_set_time = info_set_time;
+	class->info_set_ptr = info_set_ptr;
+#endif
+	class->info_set_user_flag = info_set_user_flag;
+	class->info_set_user_tag = info_set_user_tag;
+
+	class->info_set_flags = info_set_flags;
+
+}
+
+static void
+folder_summary_init (CamelFolderSummary *summary)
+{
+	summary->priv = CAMEL_FOLDER_SUMMARY_GET_PRIVATE (summary);
+
+	summary->priv->filter_charset = g_hash_table_new (
+		camel_strcase_hash, camel_strcase_equal);
+
+	summary->message_info_size = sizeof(CamelMessageInfoBase);
+	summary->content_info_size = sizeof(CamelMessageContentInfo);
+	summary->priv->flag_cache = g_hash_table_new (g_str_hash, g_str_equal);
+
+	summary->message_info_chunks = NULL;
+	summary->content_info_chunks = NULL;
+	summary->priv->need_preview = FALSE;
+	summary->priv->preview_updates = g_hash_table_new (g_str_hash, g_str_equal);
+#if defined (DOESTRV) || defined (DOEPOOLV)
+	summary->message_info_strings = CAMEL_MESSAGE_INFO_LAST;
+#endif
+
+	summary->version = CAMEL_FOLDER_SUMMARY_VERSION;
+	summary->flags = 0;
+	summary->time = 0;
+	summary->nextuid = 1;
+
+	summary->uids = g_ptr_array_new ();
+	summary->loaded_infos = g_hash_table_new (g_str_hash, g_str_equal);
+
+	summary->priv->summary_lock = g_mutex_new();
+	summary->priv->io_lock = g_mutex_new();
+	summary->priv->filter_lock = g_mutex_new();
+	summary->priv->alloc_lock = g_mutex_new();
+	summary->priv->ref_lock = g_mutex_new();
+
+	summary->meta_summary = g_malloc0(sizeof(CamelFolderMetaSummary));
+
+	/* Default is 20, any implementor having UIDs that has length
+	   exceeding 20, has to override this value
+	*/
+	summary->meta_summary->uid_len = 20;
+	summary->cache_load_time = 0;
+	summary->timeout_handle = 0;
+}
+
+GType
+camel_folder_summary_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelFolderSummary",
+			sizeof (CamelFolderSummaryClass),
+			(GClassInitFunc) folder_summary_class_init,
+			sizeof (CamelFolderSummary),
+			(GInstanceInitFunc) folder_summary_init,
+			0);
+
 	return type;
 }
 
@@ -279,8 +992,9 @@ camel_folder_summary_get_type (void)
 CamelFolderSummary *
 camel_folder_summary_new (struct _CamelFolder *folder)
 {
-	CamelFolderSummary *new = CAMEL_FOLDER_SUMMARY ( camel_object_new (camel_folder_summary_get_type ()));
+	CamelFolderSummary *new;
 
+	new = g_object_new (CAMEL_TYPE_FOLDER_SUMMARY, NULL);
 	new->folder = folder;
 
 	return new;
@@ -320,14 +1034,14 @@ camel_folder_summary_set_filename(CamelFolderSummary *s, const gchar *name)
 void
 camel_folder_summary_set_index(CamelFolderSummary *s, CamelIndex *index)
 {
-	struct _CamelFolderSummaryPrivate *p = _PRIVATE(s);
+	struct _CamelFolderSummaryPrivate *p = CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s);
 
 	if (p->index)
-		camel_object_unref((CamelObject *)p->index);
+		g_object_unref (p->index);
 
 	p->index = index;
 	if (index)
-		camel_object_ref((CamelObject *)index);
+		g_object_ref (index);
 }
 
 /**
@@ -610,11 +1324,18 @@ message_info_from_uid (CamelFolderSummary *s, const gchar *uid)
  * Returns: the summary item, or %NULL if the uid @uid is not available
  **/
 CamelMessageInfo *
-camel_folder_summary_uid (CamelFolderSummary *s, const gchar *uid)
+camel_folder_summary_uid (CamelFolderSummary *summary,
+                          const gchar *uid)
 {
-	if (!s)
-		return NULL;
-	return ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_from_uid(s, uid);
+	CamelFolderSummaryClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary), NULL);
+	g_return_val_if_fail (uid != NULL, NULL);
+
+	class = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary);
+	g_return_val_if_fail (class->message_info_from_uid != NULL, NULL);
+
+	return class->message_info_from_uid (summary, uid);
 }
 
 /**
@@ -672,9 +1393,16 @@ camel_folder_summary_set_uid(CamelFolderSummary *s, guint32 uid)
  * This string must be freed by the caller.
  **/
 gchar *
-camel_folder_summary_next_uid_string(CamelFolderSummary *s)
+camel_folder_summary_next_uid_string (CamelFolderSummary *summary)
 {
-	return ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->next_uid_string(s);
+	CamelFolderSummaryClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_FOLDER_SUMMARY (summary), NULL);
+
+	class = CAMEL_FOLDER_SUMMARY_GET_CLASS (summary);
+	g_return_val_if_fail (class->next_uid_string != NULL, NULL);
+
+	return class->next_uid_string (summary);
 }
 
 static CamelMessageContentInfo *
@@ -685,7 +1413,7 @@ perform_content_info_load_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
 	CamelMessageContentInfo *ci, *pci;
 	gchar *part;
 
-	ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_from_db (s, mir);
+	ci = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_from_db (s, mir);
 	if (ci == NULL)
 		return NULL;
 	part = mir->cinfo;
@@ -717,7 +1445,7 @@ perform_content_info_load(CamelFolderSummary *s, FILE *in)
 	guint32 count;
 	CamelMessageContentInfo *ci, *part;
 
-	ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_load(s, in);
+	ci = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_load (s, in);
 	if (ci == NULL)
 		return NULL;
 
@@ -833,7 +1561,7 @@ remove_cache (CamelSession *session, CamelSessionThreadMsg *msg)
 static void remove_cache_end (CamelSession *session, CamelSessionThreadMsg *msg)
 {
 		struct _folder_summary_free_msg *m = (struct _folder_summary_free_msg *)msg;
-		camel_object_unref (m->summary);
+		g_object_unref (m->summary);
 }
 
 static CamelSessionThreadOps remove_timeout_ops = {
@@ -860,7 +1588,7 @@ cfs_try_release_memory (CamelFolderSummary *s)
 		return TRUE;
 
 	m = camel_session_thread_msg_new(session, &remove_timeout_ops, sizeof(*m));
-	camel_object_ref (s);
+	g_object_ref (s);
 	m->summary = s;
 	camel_session_thread_queue(session, &m->msg, 0);
 
@@ -998,7 +1726,7 @@ camel_folder_summary_reload_from_db (CamelFolderSummary *s, CamelException *ex)
 	if (!g_getenv("CAMEL_FREE_INFOS") && !s->timeout_handle)
 		s->timeout_handle = g_timeout_add_seconds (SUMMARY_CACHE_DROP, (GSourceFunc) cfs_try_release_memory, s);
 
-	if (_PRIVATE(s)->need_preview) {
+	if (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->need_preview) {
 		struct _preview_update_msg *m;
 
 		m = camel_session_thread_msg_new(((CamelService *)s->folder->parent_store)->session, &preview_update_ops, sizeof(*m));
@@ -1014,7 +1742,7 @@ void
 camel_folder_summary_add_preview (CamelFolderSummary *s, CamelMessageInfo *info)
 {
 	CAMEL_SUMMARY_LOCK(s, summary_lock);
-	g_hash_table_insert (_PRIVATE(s)->preview_updates, (gchar *)info->uid, ((CamelMessageInfoBase *)info)->preview);
+	g_hash_table_insert (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->preview_updates, (gchar *)info->uid, ((CamelMessageInfoBase *)info)->preview);
 	CAMEL_SUMMARY_UNLOCK(s, summary_lock);
 }
 
@@ -1058,7 +1786,7 @@ camel_folder_summary_dump (CamelFolderSummary *s)
 GHashTable *
 camel_folder_summary_get_flag_cache (CamelFolderSummary *summary)
 {
-	struct _CamelFolderSummaryPrivate *p = _PRIVATE(summary);
+	struct _CamelFolderSummaryPrivate *p = CAMEL_FOLDER_SUMMARY_GET_PRIVATE(summary);
 
 	return p->flag_cache;
 }
@@ -1070,7 +1798,7 @@ camel_folder_summary_load_from_db (CamelFolderSummary *s, CamelException *ex)
 	gchar *folder_name;
 	gint ret = 0;
 	CamelException ex2;
-	struct _CamelFolderSummaryPrivate *p = _PRIVATE(s);
+	struct _CamelFolderSummaryPrivate *p = CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s);
 
 	/* struct _db_pass_data data; */
 	d(printf ("\ncamel_folder_summary_load_from_db called \n"));
@@ -1193,7 +1921,7 @@ camel_read_mir_callback (gpointer  ref, gint ncol, gchar ** cols, gchar ** name)
 	}
 	CAMEL_SUMMARY_UNLOCK (s, summary_lock);
 
-	info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_from_db (s, mir);
+	info = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_from_db (s, mir);
 
 	if (info) {
 
@@ -1262,12 +1990,12 @@ camel_folder_summary_load(CamelFolderSummary *s)
 		return -1;
 
 	CAMEL_SUMMARY_LOCK(s, io_lock);
-	if ( ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_load (s, in) == -1)
 		goto error;
 
 	/* now read in each message ... */
 	for (i=0;i<s->saved_count;i++) {
-		mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_load(s, in);
+		mi = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_load (s, in);
 
 		if (mi == NULL)
 			goto error;
@@ -1334,14 +2062,14 @@ camel_folder_summary_migrate_infos(CamelFolderSummary *s)
 	if (in == NULL)
 		return -1;
 
-	if ( ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_load (s, in) == -1)
 		goto error;
 
 	/* now read in each message ... */
 	for (i=0;i<s->saved_count;i++) {
 		CamelTag *tag;
 
-		mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_load(s, in);
+		mi = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_load (s, in);
 
 		if (mi == NULL)
 			goto error;
@@ -1371,7 +2099,7 @@ camel_folder_summary_migrate_infos(CamelFolderSummary *s)
 	if (fclose (in) != 0)
 		return -1;
 
-	record = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_to_db (s, &ex));
+	record = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_to_db (s, &ex);
 	if (!record) {
 		return -1;
 	}
@@ -1412,7 +2140,7 @@ perform_content_info_save_to_db (CamelFolderSummary *s, CamelMessageContentInfo
 	CamelMessageContentInfo *part;
 	gchar *oldr;
 
-	if (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->content_info_to_db (s, ci, record) == -1)
+	if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_to_db (s, ci, record) == -1)
 		return -1;
 
 	oldr = record->cinfo;
@@ -1436,7 +2164,7 @@ perform_content_info_save(CamelFolderSummary *s, FILE *out, CamelMessageContentI
 {
 	CamelMessageContentInfo *part;
 
-	if (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->content_info_save (s, out, ci) == -1)
+	if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_save (s, out, ci) == -1)
 		return -1;
 
 	if (camel_file_util_encode_uint32 (out, my_list_size ((struct _node **)&ci->childs)) == -1)
@@ -1473,7 +2201,7 @@ save_to_db_cb (gpointer key, gpointer value, gpointer data)
 	if (!args->migration && !mi->dirty)
 		return;
 
-	mir = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_to_db (s, (CamelMessageInfo *)mi);
+	mir = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_to_db (s, (CamelMessageInfo *) mi);
 
 	if (mir && s->build_content) {
 		if (perform_content_info_save_to_db (s, ((CamelMessageInfoBase *)mi)->content, mir) == -1) {
@@ -1552,11 +2280,11 @@ camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex)
 	gint ret, count;
 
 	d(printf ("\ncamel_folder_summary_save_to_db called \n"));
-	if (_PRIVATE(s)->need_preview && g_hash_table_size(_PRIVATE(s)->preview_updates)) {
+	if (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->need_preview && g_hash_table_size(CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->preview_updates)) {
 		camel_db_begin_transaction (s->folder->parent_store->cdb_w, NULL);
 		CAMEL_SUMMARY_LOCK(s, summary_lock);
-		g_hash_table_foreach (_PRIVATE(s)->preview_updates, (GHFunc)msg_save_preview, s->folder);
-		g_hash_table_remove_all (_PRIVATE(s)->preview_updates);
+		g_hash_table_foreach (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->preview_updates, (GHFunc)msg_save_preview, s->folder);
+		g_hash_table_remove_all (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->preview_updates);
 		CAMEL_SUMMARY_UNLOCK(s, summary_lock);
 		camel_db_end_transaction (s->folder->parent_store->cdb_w, NULL);
 	}
@@ -1601,7 +2329,7 @@ camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex)
 
 	camel_db_end_transaction (cdb, ex);
 
-	record = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_to_db (s, ex));
+	record = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_to_db (s, ex);
 	if (!record) {
 		s->flags |= CAMEL_SUMMARY_DIRTY;
 		return -1;
@@ -1632,7 +2360,7 @@ camel_folder_summary_header_save_to_db (CamelFolderSummary *s, CamelException *e
 
 	d(printf ("\ncamel_folder_summary_header_save_to_db called \n"));
 
-	record = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_to_db (s, ex));
+	record = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_to_db (s, ex);
 	if (!record) {
 		return -1;
 	}
@@ -1722,7 +2450,7 @@ camel_folder_summary_save(CamelFolderSummary *s)
 
 	CAMEL_SUMMARY_LOCK(s, io_lock);
 
-	if (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_save(s, out) == -1)
+	if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_save (s, out) == -1)
 		goto exception;
 
 	if (summary_meta_header_save(s, out_meta) == -1)
@@ -1734,10 +2462,10 @@ camel_folder_summary_save(CamelFolderSummary *s)
 	count = s->messages->len;
 	for (i = 0; i < count; i++) {
 		mi = s->messages->pdata[i];
-		if (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->meta_message_info_save (s, out_meta, out, mi) == -1)
+		if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->meta_message_info_save (s, out_meta, out, mi) == -1)
 			goto exception;
 
-		if (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->message_info_save (s, out, mi) == -1)
+		if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_save (s, out, mi) == -1)
 			goto exception;
 
 		if (s->build_content) {
@@ -1810,7 +2538,7 @@ camel_folder_summary_header_load_from_db (CamelFolderSummary *s, CamelStore *sto
 	camel_db_read_folder_info_record (cdb, folder_name, &record, ex);
 
 	if (record) {
-		if ( ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_from_db (s, record) == -1)
+		if (CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_from_db (s, record) == -1)
 			ret = -1;
 	} else {
 		ret = -1;
@@ -1856,7 +2584,7 @@ camel_folder_summary_header_load(CamelFolderSummary *s)
 	}
 
 	CAMEL_SUMMARY_LOCK(s, io_lock);
-	ret = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in);
+	ret = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->summary_header_load (s, in);
 	ret = summary_meta_header_load(s, in_meta);
 	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 
@@ -1931,7 +2659,7 @@ camel_folder_summary_add (CamelFolderSummary *s, CamelMessageInfo *info)
 	/* FIXME[disk-summary] SHould we ref it or redesign it later on */
 	/* The uid array should have its own memory. We will unload the infos when not reqd.*/
 	g_ptr_array_add (s->uids, (gpointer) camel_pstring_strdup((camel_message_info_uid(info))));
-	g_hash_table_replace (_PRIVATE(s)->flag_cache, (gchar *)info->uid, GUINT_TO_POINTER(camel_message_info_flags(info)));
+	g_hash_table_replace (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->flag_cache, (gchar *)info->uid, GUINT_TO_POINTER(camel_message_info_flags(info)));
 
 	g_hash_table_insert (s->loaded_infos, (gpointer) camel_message_info_uid (info), info);
 	s->flags |= CAMEL_SUMMARY_DIRTY;
@@ -1956,7 +2684,7 @@ camel_folder_summary_insert (CamelFolderSummary *s, CamelMessageInfo *info, gboo
 
 	g_hash_table_insert (s->loaded_infos, (gchar *) camel_message_info_uid (info), info);
 	if (load) {
-		g_hash_table_replace (_PRIVATE(s)->flag_cache, (gchar *)info->uid, GUINT_TO_POINTER(camel_message_info_flags(info)));
+		g_hash_table_replace (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->flag_cache, (gchar *)info->uid, GUINT_TO_POINTER(camel_message_info_flags(info)));
 	}
 
 	if (!load)
@@ -2089,7 +2817,7 @@ camel_folder_summary_add_from_message (CamelFolderSummary *s, CamelMimeMessage *
 CamelMessageInfo *
 camel_folder_summary_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
 {
-	return ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_new_from_header(s, h);
+	return CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_new_from_header (s, h);
 }
 
 /**
@@ -2119,7 +2847,7 @@ camel_folder_summary_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser
 	CamelMessageInfo *info = NULL;
 	gchar *buffer;
 	gsize len;
-	struct _CamelFolderSummaryPrivate *p = _PRIVATE(s);
+	struct _CamelFolderSummaryPrivate *p = CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s);
 	off_t start;
 	CamelIndexName *name = NULL;
 
@@ -2127,7 +2855,7 @@ camel_folder_summary_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser
 
 	start = camel_mime_parser_tell(mp);
 	if (camel_mime_parser_step(mp, &buffer, &len) != CAMEL_MIME_PARSER_STATE_EOF) {
-		info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_new_from_parser(s, mp);
+		info = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_new_from_parser (s, mp);
 
 		camel_mime_parser_unstep(mp);
 
@@ -2140,10 +2868,10 @@ camel_folder_summary_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser
 
 		if (p->index) {
 			if (p->filter_index == NULL)
-				p->filter_index = camel_mime_filter_index_new_index(p->index);
+				p->filter_index = camel_mime_filter_index_new (p->index);
 			camel_index_delete_name(p->index, camel_message_info_uid(info));
 			name = camel_index_add_name(p->index, camel_message_info_uid(info));
-			camel_mime_filter_index_set_name(p->filter_index, name);
+			camel_mime_filter_index_set_name(CAMEL_MIME_FILTER_INDEX (p->filter_index), name);
 		}
 
 		/* always scan the content info, even if we dont save it */
@@ -2151,8 +2879,8 @@ camel_folder_summary_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser
 
 		if (name && p->index) {
 			camel_index_write_name(p->index, name);
-			camel_object_unref((CamelObject *)name);
-			camel_mime_filter_index_set_name(p->filter_index, NULL);
+			g_object_unref (name);
+			camel_mime_filter_index_set_name(CAMEL_MIME_FILTER_INDEX (p->filter_index), NULL);
 		}
 
 		CAMEL_SUMMARY_UNLOCK(s, filter_lock);
@@ -2177,10 +2905,10 @@ CamelMessageInfo *
 camel_folder_summary_info_new_from_message(CamelFolderSummary *s, CamelMimeMessage *msg, const gchar *bodystructure)
 {
 	CamelMessageInfo *info;
-	struct _CamelFolderSummaryPrivate *p = _PRIVATE(s);
+	struct _CamelFolderSummaryPrivate *p = CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s);
 	CamelIndexName *name = NULL;
 
-	info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_new_from_message(s, msg, bodystructure);
+	info = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_new_from_message (s, msg, bodystructure);
 
 	/* assign a unique uid, this is slightly 'wrong' as we do not really
 	 * know if we are going to store this in the summary, but we need it set for indexing */
@@ -2191,16 +2919,16 @@ camel_folder_summary_info_new_from_message(CamelFolderSummary *s, CamelMimeMessa
 
 	if (p->index) {
 		if (p->filter_index == NULL)
-			p->filter_index = camel_mime_filter_index_new_index(p->index);
+			p->filter_index = camel_mime_filter_index_new (p->index);
 		camel_index_delete_name(p->index, camel_message_info_uid(info));
 		name = camel_index_add_name(p->index, camel_message_info_uid(info));
-		camel_mime_filter_index_set_name(p->filter_index, name);
+		camel_mime_filter_index_set_name(CAMEL_MIME_FILTER_INDEX (p->filter_index), name);
 
 		if (p->filter_stream == NULL) {
 			CamelStream *null = camel_stream_null_new();
 
-			p->filter_stream = camel_stream_filter_new_with_stream(null);
-			camel_object_unref((CamelObject *)null);
+			p->filter_stream = camel_stream_filter_new (null);
+			g_object_unref (null);
 		}
 	}
 
@@ -2208,8 +2936,8 @@ camel_folder_summary_info_new_from_message(CamelFolderSummary *s, CamelMimeMessa
 
 	if (name) {
 		camel_index_write_name(p->index, name);
-		camel_object_unref((CamelObject *)name);
-		camel_mime_filter_index_set_name(p->filter_index, NULL);
+		g_object_unref (name);
+		camel_mime_filter_index_set_name(CAMEL_MIME_FILTER_INDEX (p->filter_index), NULL);
 	}
 
 	CAMEL_SUMMARY_UNLOCK(s, filter_lock);
@@ -2230,7 +2958,7 @@ camel_folder_summary_content_info_free(CamelFolderSummary *s, CamelMessageConten
 	CamelMessageContentInfo *pw, *pn;
 
 	pw = ci->childs;
-	((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_free(s, ci);
+	CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_free (s, ci);
 	while (pw) {
 		pn = pw->next;
 		camel_folder_summary_content_info_free(s, pw);
@@ -2276,6 +3004,11 @@ camel_folder_summary_clear(CamelFolderSummary *s)
 	s->uids = g_ptr_array_new ();
 	s->visible_count = s->deleted_count = s->unread_count = 0;
 
+	g_ptr_array_foreach (s->uids, (GFunc) camel_pstring_free, NULL);
+	g_ptr_array_free (s->uids, TRUE);
+	s->uids = g_ptr_array_new ();
+	s->visible_count = s->deleted_count = s->unread_count = 0;
+
 	g_hash_table_destroy(s->loaded_infos);
 	s->loaded_infos = g_hash_table_new(g_str_hash, g_str_equal);
 
@@ -2749,42 +3482,6 @@ summary_meta_header_load(CamelFolderSummary *s, FILE *in)
 }
 #endif
 
-static	gint
-summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *record)
-{
-	io(printf("Loading header from db \n"));
-
-	s->version = record->version;
-
-	/* We may not worry, as we are setting a new standard here */
-#if 0
-	/* Legacy version check, before version 12 we have no upgrade knowledge */
-	if ((s->version > 0xff) && (s->version & 0xff) < 12) {
-		io(printf ("Summary header version mismatch"));
-		errno = EINVAL;
-		return -1;
-	}
-
-	if (!(s->version < 0x100 && s->version >= 13))
-		io(printf("Loading legacy summary\n"));
-	else
-		io(printf("loading new-format summary\n"));
-#endif
-
-	s->flags = record->flags;
-	s->nextuid = record->nextuid;
-	s->time = record->time;
-	s->saved_count = record->saved_count;
-
-	s->unread_count = record->unread_count;
-	s->deleted_count = record->deleted_count;
-	s->junk_count = record->junk_count;
-	s->visible_count = record->visible_count;
-	s->junk_not_deleted_count = record->jnd_count;
-
-	return 0;
-}
-
 static gint
 summary_header_load(CamelFolderSummary *s, FILE *in)
 {
@@ -2830,91 +3527,6 @@ summary_header_load(CamelFolderSummary *s, FILE *in)
 	return 0;
 }
 
-static	CamelFIRecord *
-summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
-{
-	CamelFIRecord * record = g_new0 (CamelFIRecord, 1);
-	CamelDB *db;
-	gchar *table_name;
-
-	/* Though we are going to read, we do this during write, so lets use it that way */
-	db = s->folder->parent_store->cdb_w;
-	table_name = s->folder->full_name;
-
-	io(printf("Savining header to db\n"));
-
-	record->folder_name = table_name;
-
-	/* we always write out the current version */
-	record->version = CAMEL_FOLDER_SUMMARY_VERSION;
-	record->flags  = s->flags;
-	record->nextuid = s->nextuid;
-	record->time = s->time;
-
-	/* FIXME: Ever heard of Constructors and initializing ? */
-	if (camel_db_count_total_message_info (db, table_name, &(record->saved_count), NULL))
-		record->saved_count = 0;
-	if (camel_db_count_junk_message_info (db, table_name, &(record->junk_count), NULL))
-		record->junk_count = 0;
-	if (camel_db_count_deleted_message_info (db, table_name, &(record->deleted_count), NULL))
-		record->deleted_count = 0;
-	if (camel_db_count_unread_message_info (db, table_name, &(record->unread_count), NULL))
-		record->unread_count = 0;
-	if (camel_db_count_visible_message_info (db, table_name, &(record->visible_count), NULL))
-		record->visible_count = 0;
-	if (camel_db_count_junk_not_deleted_message_info (db, table_name, &(record->jnd_count), NULL))
-		record->jnd_count = 0;
-
-	s->unread_count = record->unread_count;
-	s->deleted_count = record->deleted_count;
-	s->junk_count = record->junk_count;
-	s->visible_count = record->visible_count;
-	s->junk_not_deleted_count = record->jnd_count;
-
-	return record;
-}
-
-static gint
-summary_header_save(CamelFolderSummary *s, FILE *out)
-{
-	gint unread = 0, deleted = 0, junk = 0, count, i;
-
-	fseek(out, 0, SEEK_SET);
-
-	io(printf("Savining header\n"));
-
-	/* we always write out the current version */
-	camel_file_util_encode_fixed_int32(out, CAMEL_FOLDER_SUMMARY_VERSION);
-	camel_file_util_encode_fixed_int32(out, s->flags);
-	camel_file_util_encode_fixed_int32(out, s->nextuid);
-	camel_file_util_encode_time_t(out, s->time);
-
-	count = camel_folder_summary_count(s);
-	for (i=0; i<count; i++) {
-		CamelMessageInfo *info = camel_folder_summary_index(s, i);
-		guint32 flags;
-
-		if (info == NULL)
-			continue;
-
-		flags = camel_message_info_flags(info);
-		if ((flags & CAMEL_MESSAGE_SEEN) == 0)
-			unread++;
-		if ((flags & CAMEL_MESSAGE_DELETED) != 0)
-			deleted++;
-		if ((flags & CAMEL_MESSAGE_JUNK) != 0)
-			junk++;
-
-		camel_message_info_free(info);
-	}
-
-	camel_file_util_encode_fixed_int32(out, count);
-	camel_file_util_encode_fixed_int32(out, unread);
-	camel_file_util_encode_fixed_int32(out, deleted);
-
-	return camel_file_util_encode_fixed_int32(out, junk);
-}
-
 #if 0
 static gint
 summary_meta_header_save(CamelFolderSummary *s, FILE *out_meta)
@@ -2948,7 +3560,7 @@ message_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser *mp)
 	case CAMEL_MIME_PARSER_STATE_HEADER:
 	case CAMEL_MIME_PARSER_STATE_MESSAGE:
 	case CAMEL_MIME_PARSER_STATE_MULTIPART:
-		mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_new_from_header(s, camel_mime_parser_headers_raw(mp));
+		mi = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_new_from_header (s, camel_mime_parser_headers_raw (mp));
 		break;
 	default:
 		g_error("Invalid parser state");
@@ -2966,7 +3578,7 @@ content_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser *mp)
 	case CAMEL_MIME_PARSER_STATE_HEADER:
 	case CAMEL_MIME_PARSER_STATE_MESSAGE:
 	case CAMEL_MIME_PARSER_STATE_MULTIPART:
-		ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_new_from_header(s, camel_mime_parser_headers_raw(mp));
+		ci = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_new_from_header (s, camel_mime_parser_headers_raw (mp));
 		if (ci) {
 			ci->type = camel_mime_parser_content_type(mp);
 			camel_content_type_ref(ci->type);
@@ -2983,8 +3595,10 @@ static CamelMessageInfo *
 message_info_new_from_message(CamelFolderSummary *s, CamelMimeMessage *msg, const gchar *bodystructure)
 {
 	CamelMessageInfo *mi;
+	struct _camel_header_raw *headers;
 
-	mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_new_from_header(s, ((CamelMimePart *)msg)->headers);
+	headers = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (msg));
+	mi = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_new_from_header (s, headers);
 	((CamelMessageInfoBase *)mi)->bodystructure = g_strdup (bodystructure);
 
 	return mi;
@@ -2994,8 +3608,10 @@ static CamelMessageContentInfo *
 content_info_new_from_message(CamelFolderSummary *s, CamelMimePart *mp)
 {
 	CamelMessageContentInfo *ci;
+	struct _camel_header_raw *headers;
 
-	ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_new_from_header(s, mp->headers);
+	headers = camel_mime_part_get_raw_headers (mp);
+	ci = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_new_from_header (s, headers);
 
 	return ci;
 }
@@ -3184,84 +3800,6 @@ message_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
 }
 
 static CamelMessageInfo *
-message_info_from_db (CamelFolderSummary *s, CamelMIRecord *record)
-{
-	CamelMessageInfoBase *mi;
-	gint i;
-	gint count;
-	gchar *part, *label;
-
-	mi = (CamelMessageInfoBase *)camel_message_info_new(s);
-
-	io(printf("Loading message info from db\n"));
-
-	mi->flags = record->flags;
-	mi->size = record->size;
-	mi->date_sent = record->dsent;
-	mi->date_received = record->dreceived;
-
-	mi->uid = (gchar *) camel_pstring_strdup (record->uid);
-	mi->subject = (gchar *) camel_pstring_add (record->subject, FALSE);
-	mi->from = (gchar *) camel_pstring_add (record->from, FALSE);
-	mi->to = (gchar *) camel_pstring_add (record->to, FALSE);
-	mi->cc = (gchar *) camel_pstring_add (record->cc, FALSE);
-	mi->mlist = (gchar *) camel_pstring_add (record->mlist, FALSE);
-
-	/* Evolution itself doesn't yet use this, so we ignore it (saving some memory) */
-	mi->bodystructure = NULL;
-
-	/* Extract Message id & References */
-	mi->content = NULL;
-	part = record->part;
-	if (part) {
-		EXTRACT_FIRST_DIGIT (mi->message_id.id.part.hi)
-		EXTRACT_DIGIT (mi->message_id.id.part.lo)
-		EXTRACT_DIGIT (count)
-
-		if (count > 0) {
-			mi->references = g_malloc(sizeof(*mi->references) + ((count-1) * sizeof(mi->references->references[0])));
-			mi->references->size = count;
-			for (i=0;i<count;i++) {
-				EXTRACT_DIGIT (mi->references->references[i].id.part.hi)
-				EXTRACT_DIGIT (mi->references->references[i].id.part.lo)
-			}
-		} else
-			mi->references = NULL;
-
-	}
-
-	/* Extract User flags/labels */
-	part = record->labels;
-	if (part) {
-		label = part;
-		for (i=0;part[i];i++) {
-
-			if (part[i] == ' ') {
-				part[i] = 0;
-				camel_flag_set(&mi->user_flags, label, TRUE);
-				label = &(part[i+1]);
-			}
-		}
-		camel_flag_set(&mi->user_flags, label, TRUE);
-	}
-
-	/* Extract User tags */
-	part = record->usertags;
-	EXTRACT_FIRST_DIGIT (count)
-	for (i=0;i<count;i++) {
-		gint len;
-		gchar *name, *value;
-		EXTRACT_STRING (name)
-		EXTRACT_STRING (value)
-		camel_tag_set(&mi->user_tags, name, value);
-		g_free(name);
-		g_free(value);
-	}
-
-	return (CamelMessageInfo *) mi;
-}
-
-static CamelMessageInfo *
 message_info_load(CamelFolderSummary *s, FILE *in)
 {
 	CamelMessageInfoBase *mi;
@@ -3360,84 +3898,6 @@ meta_message_info_save(CamelFolderSummary *s, FILE *out_meta, FILE *out, CamelMe
 	return ferror(out);
 }
 
-static CamelMIRecord *
-message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info)
-{
-	CamelMIRecord *record = g_new0(CamelMIRecord, 1);
-	CamelMessageInfoBase *mi = (CamelMessageInfoBase *) info;
-	GString *tmp;
-	CamelFlag *flag;
-	CamelTag *tag;
-	gint count, i;
-
-	/* Assume that we dont have to take care of DB Safeness. It will be done while doing the DB transaction */
-	record->uid = (gchar *) camel_pstring_strdup(camel_message_info_uid(mi));
-	record->flags = mi->flags;
-
-	record->read =  ((mi->flags & (CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK))) ? 1 : 0;
-	record->deleted = mi->flags & CAMEL_MESSAGE_DELETED ? 1 : 0;
-	record->replied = mi->flags & CAMEL_MESSAGE_ANSWERED ? 1 : 0;
-	record->important = mi->flags & CAMEL_MESSAGE_FLAGGED ? 1 : 0;
-	record->junk = mi->flags & CAMEL_MESSAGE_JUNK ? 1 : 0;
-	record->dirty = mi->flags & CAMEL_MESSAGE_FOLDER_FLAGGED ? 1 : 0;
-	record->attachment = mi->flags & CAMEL_MESSAGE_ATTACHMENTS ? 1 : 0;
-
-	record->size = mi->size;
-	record->dsent = mi->date_sent;
-	record->dreceived = mi->date_received;
-
-	record->subject = (gchar *) camel_pstring_strdup(camel_message_info_subject (mi));
-	record->from = (gchar *) camel_pstring_strdup(camel_message_info_from (mi));
-	record->to = (gchar *) camel_pstring_strdup(camel_message_info_to (mi));
-	record->cc = (gchar *) camel_pstring_strdup(camel_message_info_cc (mi));
-	record->mlist = (gchar *) camel_pstring_strdup(camel_message_info_mlist (mi));
-
-	record->followup_flag = (gchar *) camel_pstring_strdup(camel_message_info_user_tag(info, "follow-up"));
-	record->followup_completed_on = (gchar *) camel_pstring_strdup(camel_message_info_user_tag(info, "completed-on"));
-	record->followup_due_by = (gchar *) camel_pstring_strdup(camel_message_info_user_tag(info, "due-by"));
-
-	record->bodystructure = mi->bodystructure ? g_strdup (mi->bodystructure) : NULL;
-
-	tmp = g_string_new (NULL);
-	if (mi->references) {
-		g_string_append_printf (tmp, "%lu %lu %lu", (gulong)mi->message_id.id.part.hi, (gulong)mi->message_id.id.part.lo, (gulong)mi->references->size);
-		for (i=0;i<mi->references->size;i++)
-			g_string_append_printf (tmp, " %lu %lu", (gulong)mi->references->references[i].id.part.hi, (gulong)mi->references->references[i].id.part.lo);
-	} else {
-		g_string_append_printf (tmp, "%lu %lu %lu", (gulong)mi->message_id.id.part.hi, (gulong)mi->message_id.id.part.lo, (gulong) 0);
-	}
-	record->part = tmp->str;
-	g_string_free (tmp, FALSE);
-
-	tmp = g_string_new (NULL);
-	flag = mi->user_flags;
-	while (flag) {
-		g_string_append_printf (tmp, "%s ", flag->name);
-		flag = flag->next;
-	}
-
-	/* Strip off the last space */
-	if (tmp->len)
-		tmp->len--;
-
-	record->labels = tmp->str;
-	g_string_free (tmp, FALSE);
-
-	tmp = g_string_new (NULL);
-	count = camel_tag_list_size(&mi->user_tags);
-	g_string_append_printf (tmp, "%lu", (gulong)count);
-	tag = mi->user_tags;
-	while (tag) {
-		/* FIXME: Should we handle empty tags? Can it be empty? If it potential crasher ahead*/
-		g_string_append_printf (tmp, " %lu-%s %lu-%s", (gulong)strlen(tag->name), tag->name, (gulong)strlen(tag->value), tag->value);
-		tag = tag->next;
-	}
-	record->usertags = tmp->str;
-	g_string_free (tmp, FALSE);
-
-	return record;
-}
-
 static gint
 message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *info)
 {
@@ -3553,56 +4013,6 @@ content_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
 }
 
 static CamelMessageContentInfo *
-content_info_from_db(CamelFolderSummary *s, CamelMIRecord *record)
-{
-	CamelMessageContentInfo *ci;
-	gchar *type, *subtype;
-	guint32 count, i;
-	CamelContentType *ct;
-	gchar *part = record->cinfo;
-	gint len;
-
-	io(printf("Loading content info from db\n"));
-
-	if (!part)
-		return NULL;
-
-	ci = camel_folder_summary_content_info_new(s);
-	if (*part == ' ') part++; /* Move off the space in the record*/
-
-	EXTRACT_FIRST_STRING (type)
-	EXTRACT_STRING (subtype)
-	ct = camel_content_type_new(type, subtype);
-	g_free(type);		/* can this be removed? */
-	g_free(subtype);
-	EXTRACT_DIGIT (count)
-
-	for (i = 0; i < count; i++) {
-		gchar *name, *value;
-		EXTRACT_STRING (name)
-		EXTRACT_STRING (value)
-
-		camel_content_type_set_param(ct, name, value);
-		/* TODO: do this so we dont have to double alloc/free */
-		g_free(name);
-		g_free(value);
-	}
-	ci->type = ct;
-
-	/* FIXME[disk-summary] move all these to camel pstring */
-	EXTRACT_STRING (ci->id);
-	EXTRACT_STRING (ci->description)
-	EXTRACT_STRING (ci->encoding)
-	EXTRACT_DIGIT (ci->size)
-
-	record->cinfo = part; /* Keep moving the cursor in the record */
-
-	ci->childs = NULL;
-
-	return ci;
-}
-
-static CamelMessageContentInfo *
 content_info_load(CamelFolderSummary *s, FILE *in)
 {
 	CamelMessageContentInfo *ci;
@@ -3654,71 +4064,6 @@ content_info_load(CamelFolderSummary *s, FILE *in)
 }
 
 static gint
-content_info_to_db(CamelFolderSummary *s, CamelMessageContentInfo *ci, CamelMIRecord *record)
-{
-	CamelContentType *ct;
-	struct _camel_header_param *hp;
-	GString *str = g_string_new (NULL);
-	gchar *oldr;
-
-	io(printf("Saving content info to db\n"));
-
-	ct = ci->type;
-	if (ct) {
-		if (ct->type)
-			g_string_append_printf (str, " %d-%s", (gint) strlen (ct->type), ct->type);
-		else
-			g_string_append_printf (str, " 0-");
-		if (ct->subtype)
-			g_string_append_printf (str, " %d-%s", (gint) strlen (ct->subtype), ct->subtype);
-		else
-			g_string_append_printf (str, " 0-");
-		g_string_append_printf (str, " %d", my_list_size((struct _node **)&ct->params));
-		hp = ct->params;
-		while (hp) {
-			if (hp->name)
-				g_string_append_printf (str, " %d-%s", (gint)strlen(hp->name), hp->name);
-			else
-				g_string_append_printf (str, " 0-");
-			if (hp->value)
-				g_string_append_printf (str, " %d-%s", (gint)strlen (hp->value), hp->value);
-			else
-				g_string_append_printf (str, " 0-");
-			hp = hp->next;
-		}
-	} else {
-		g_string_append_printf (str, " %d-", 0);
-		g_string_append_printf (str, " %d-", 0);
-		g_string_append_printf (str, " %d", 0);
-	}
-
-	if (ci->id)
-		g_string_append_printf (str, " %d-%s", (gint)strlen (ci->id), ci->id);
-	else
-		g_string_append_printf (str, " 0-");
-	if (ci->description)
-		g_string_append_printf (str, " %d-%s", (gint)strlen (ci->description), ci->description);
-	else
-		g_string_append_printf (str, " 0-");
-	if (ci->encoding)
-		g_string_append_printf (str, " %d-%s", (gint)strlen (ci->encoding), ci->encoding);
-	else
-		g_string_append_printf (str, " 0-");
-	g_string_append_printf (str, " %u", ci->size);
-
-	if (record->cinfo) {
-		oldr = record->cinfo;
-		record->cinfo = g_strconcat(oldr, str->str, NULL);
-		g_free (oldr); g_string_free (str, TRUE);
-	} else {
-		record->cinfo = str->str;
-		g_string_free (str, FALSE);
-	}
-
-	return 0;
-}
-
-static gint
 content_info_save(CamelFolderSummary *s, FILE *out, CamelMessageContentInfo *ci)
 {
 	CamelContentType *ct;
@@ -3789,8 +4134,8 @@ summary_build_content_info(CamelFolderSummary *s, CamelMessageInfo *msginfo, Cam
 	CamelMessageContentInfo *info = NULL;
 	CamelContentType *ct;
 	gint enc_id = -1, chr_id = -1, html_id = -1, idx_id = -1;
-	struct _CamelFolderSummaryPrivate *p = _PRIVATE(s);
-	CamelMimeFilterCharset *mfc;
+	struct _CamelFolderSummaryPrivate *p = CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s);
+	CamelMimeFilter *mfc;
 	CamelMessageContentInfo *part;
 	const gchar *calendar_header;
 
@@ -3800,7 +4145,7 @@ summary_build_content_info(CamelFolderSummary *s, CamelMessageInfo *msginfo, Cam
 	state = camel_mime_parser_step(mp, &buffer, &len);
 
 	if (s->build_content)
-		info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_new_from_parser(s, mp);
+		info = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_new_from_parser (s, mp);
 
 	switch (state) {
 	case CAMEL_MIME_PARSER_STATE_HEADER:
@@ -3836,24 +4181,24 @@ summary_build_content_info(CamelFolderSummary *s, CamelMessageInfo *msginfo, Cam
 				if (!g_ascii_strcasecmp(encoding, "base64")) {
 					d(printf(" decoding base64\n"));
 					if (p->filter_64 == NULL)
-						p->filter_64 = camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_BASE64_DEC);
+						p->filter_64 = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_BASE64_DEC);
 					else
-						camel_mime_filter_reset((CamelMimeFilter *)p->filter_64);
-					enc_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)p->filter_64);
+						camel_mime_filter_reset(p->filter_64);
+					enc_id = camel_mime_parser_filter_add(mp, p->filter_64);
 				} else if (!g_ascii_strcasecmp(encoding, "quoted-printable")) {
 					d(printf(" decoding quoted-printable\n"));
 					if (p->filter_qp == NULL)
-						p->filter_qp = camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_QP_DEC);
+						p->filter_qp = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_QP_DEC);
 					else
-						camel_mime_filter_reset((CamelMimeFilter *)p->filter_qp);
-					enc_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)p->filter_qp);
+						camel_mime_filter_reset(p->filter_qp);
+					enc_id = camel_mime_parser_filter_add(mp, p->filter_qp);
 				} else if (!g_ascii_strcasecmp (encoding, "x-uuencode")) {
 					d(printf(" decoding x-uuencode\n"));
 					if (p->filter_uu == NULL)
-						p->filter_uu = camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_UU_DEC);
+						p->filter_uu = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_UU_DEC);
 					else
-						camel_mime_filter_reset((CamelMimeFilter *)p->filter_uu);
-					enc_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)p->filter_uu);
+						camel_mime_filter_reset(p->filter_uu);
+					enc_id = camel_mime_parser_filter_add(mp, p->filter_uu);
 				} else {
 					d(printf(" ignoring encoding %s\n", encoding));
 				}
@@ -3867,14 +4212,14 @@ summary_build_content_info(CamelFolderSummary *s, CamelMessageInfo *msginfo, Cam
 				d(printf(" Adding conversion filter from %s to UTF-8\n", charset));
 				mfc = g_hash_table_lookup(p->filter_charset, charset);
 				if (mfc == NULL) {
-					mfc = camel_mime_filter_charset_new_convert(charset, "UTF-8");
+					mfc = camel_mime_filter_charset_new (charset, "UTF-8");
 					if (mfc)
 						g_hash_table_insert(p->filter_charset, g_strdup(charset), mfc);
 				} else {
 					camel_mime_filter_reset((CamelMimeFilter *)mfc);
 				}
 				if (mfc) {
-					chr_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)mfc);
+					chr_id = camel_mime_parser_filter_add(mp, mfc);
 				} else {
 					w(g_warning("Cannot convert '%s' to 'UTF-8', message index may be corrupt", charset));
 				}
@@ -3891,7 +4236,7 @@ summary_build_content_info(CamelFolderSummary *s, CamelMessageInfo *msginfo, Cam
 			}
 
 			/* and this filter actually does the indexing */
-			idx_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)p->filter_index);
+			idx_id = camel_mime_parser_filter_add(mp, p->filter_index);
 		}
 		/* and scan/index everything */
 		while (camel_mime_parser_step(mp, &buffer, &len) != CAMEL_MIME_PARSER_STATE_BODY_END)
@@ -3951,15 +4296,15 @@ summary_build_content_info_message(CamelFolderSummary *s, CamelMessageInfo *msgi
 {
 	CamelDataWrapper *containee;
 	gint parts, i;
-	struct _CamelFolderSummaryPrivate *p = _PRIVATE(s);
+	struct _CamelFolderSummaryPrivate *p = CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s);
 	CamelMessageContentInfo *info = NULL, *child;
 	CamelContentType *ct;
 	const struct _camel_header_raw *header;
 
 	if (s->build_content)
-		info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_new_from_message(s, object);
+		info = CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->content_info_new_from_message (s, object);
 
-	containee = camel_medium_get_content_object(CAMEL_MEDIUM(object));
+	containee = camel_medium_get_content(CAMEL_MEDIUM(object));
 
 	if (containee == NULL)
 		return info;
@@ -3984,7 +4329,8 @@ summary_build_content_info_message(CamelFolderSummary *s, CamelMessageInfo *msgi
 		camel_message_info_set_flags(msginfo, CAMEL_MESSAGE_SECURE, CAMEL_MESSAGE_SECURE);
 	}
 
-	for (header = object->headers; header; header = header->next) {
+	header = camel_mime_part_get_raw_headers (object);
+	for (; header; header = header->next) {
 		const gchar *value = header->value;
 
 		/* skip preceding spaces in the value */
@@ -4030,15 +4376,21 @@ summary_build_content_info_message(CamelFolderSummary *s, CamelMessageInfo *msgi
 				p->filter_html = camel_mime_filter_html_new();
 			else
 				camel_mime_filter_reset((CamelMimeFilter *)p->filter_html);
-			html_id = camel_stream_filter_add(p->filter_stream, (CamelMimeFilter *)p->filter_html);
+			html_id = camel_stream_filter_add (
+				CAMEL_STREAM_FILTER (p->filter_stream),
+				(CamelMimeFilter *)p->filter_html);
 		}
-		idx_id = camel_stream_filter_add(p->filter_stream, (CamelMimeFilter *)p->filter_index);
+		idx_id = camel_stream_filter_add (
+			CAMEL_STREAM_FILTER (p->filter_stream),
+			p->filter_index);
 
-		camel_data_wrapper_decode_to_stream(containee, (CamelStream *)p->filter_stream);
-		camel_stream_flush((CamelStream *)p->filter_stream);
+		camel_data_wrapper_decode_to_stream(containee, p->filter_stream);
+		camel_stream_flush(p->filter_stream);
 
-		camel_stream_filter_remove(p->filter_stream, idx_id);
-		camel_stream_filter_remove(p->filter_stream, html_id);
+		camel_stream_filter_remove (
+			CAMEL_STREAM_FILTER (p->filter_stream), idx_id);
+		camel_stream_filter_remove (
+			CAMEL_STREAM_FILTER (p->filter_stream), html_id);
 	}
 
 	return info;
@@ -4485,7 +4837,7 @@ CamelMessageInfo *
 camel_message_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *header)
 {
 	if (s)
-		return ((CamelFolderSummaryClass *)((CamelObject *)s)->klass)->message_info_new_from_header(s, header);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (s)->message_info_new_from_header(s, header);
 	else
 		return message_info_new_from_header(NULL, header);
 }
@@ -4521,7 +4873,7 @@ camel_message_info_free(gpointer o)
 			camel_folder_summary_content_info_free(mi->summary, ((CamelMessageInfoBase *)mi)->content);
 		}
 
-		((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(mi->summary)))->message_info_free(mi->summary, mi);
+		CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->message_info_free (mi->summary, mi);
 	} else {
 		GLOBAL_INFO_LOCK(info);
 		mi->refcount--;
@@ -4535,56 +4887,6 @@ camel_message_info_free(gpointer o)
 	}
 }
 
-static CamelMessageInfo *
-message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
-{
-	CamelMessageInfoBase *to, *from = (CamelMessageInfoBase *)mi;
-	CamelFlag *flag;
-	CamelTag *tag;
-
-	to = (CamelMessageInfoBase *)camel_message_info_new(s);
-
-	to->flags = from->flags;
-	to->size = from->size;
-	to->date_sent = from->date_sent;
-	to->date_received = from->date_received;
-	to->refcount = 1;
-
-	/* NB: We don't clone the uid */
-
-	to->subject = camel_pstring_strdup(from->subject);
-	to->from = camel_pstring_strdup(from->from);
-	to->to = camel_pstring_strdup(from->to);
-	to->cc = camel_pstring_strdup(from->cc);
-	to->mlist = camel_pstring_strdup(from->mlist);
-	memcpy(&to->message_id, &from->message_id, sizeof(to->message_id));
-	to->preview = g_strdup (from->preview);
-	if (from->references) {
-		gint len = sizeof(*from->references) + ((from->references->size-1) * sizeof(from->references->references[0]));
-
-		to->references = g_malloc(len);
-		memcpy(to->references, from->references, len);
-	}
-
-	flag = from->user_flags;
-	while (flag) {
-		camel_flag_set(&to->user_flags, flag->name, TRUE);
-		flag = flag->next;
-	}
-
-	tag = from->user_tags;
-	while (tag) {
-		camel_tag_set(&to->user_tags, tag->name, tag->value);
-		tag = tag->next;
-	}
-
-	if (from->content) {
-		/* FIXME: copy content-infos */
-	}
-
-	return (CamelMessageInfo *)to;
-}
-
 /**
  * camel_message_info_clone:
  * @info: a #CamelMessageInfo
@@ -4599,81 +4901,11 @@ camel_message_info_clone(gconstpointer o)
 	const CamelMessageInfo *mi = o;
 
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->message_info_clone(mi->summary, mi);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->message_info_clone (mi->summary, mi);
 	else
 		return message_info_clone(NULL, mi);
 }
 
-static gconstpointer
-info_ptr(const CamelMessageInfo *mi, gint id)
-{
-	switch (id) {
-	case CAMEL_MESSAGE_INFO_SUBJECT:
-		return ((const CamelMessageInfoBase *)mi)->subject;
-	case CAMEL_MESSAGE_INFO_FROM:
-		return ((const CamelMessageInfoBase *)mi)->from;
-	case CAMEL_MESSAGE_INFO_TO:
-		return ((const CamelMessageInfoBase *)mi)->to;
-	case CAMEL_MESSAGE_INFO_CC:
-		return ((const CamelMessageInfoBase *)mi)->cc;
-	case CAMEL_MESSAGE_INFO_MLIST:
-		return ((const CamelMessageInfoBase *)mi)->mlist;
-	case CAMEL_MESSAGE_INFO_MESSAGE_ID:
-		return &((const CamelMessageInfoBase *)mi)->message_id;
-	case CAMEL_MESSAGE_INFO_REFERENCES:
-		return ((const CamelMessageInfoBase *)mi)->references;
-	case CAMEL_MESSAGE_INFO_USER_FLAGS:
-		return ((const CamelMessageInfoBase *)mi)->user_flags;
-	case CAMEL_MESSAGE_INFO_USER_TAGS:
-		return ((const CamelMessageInfoBase *)mi)->user_tags;
-	case CAMEL_MESSAGE_INFO_HEADERS:
-		return ((const CamelMessageInfoBase *)mi)->headers;
-	case CAMEL_MESSAGE_INFO_PREVIEW:
-		return ((const CamelMessageInfoBase *)mi)->preview;
-
-	default:
-		abort();
-	}
-}
-
-static guint32
-info_uint32(const CamelMessageInfo *mi, gint id)
-{
-	switch (id) {
-	case CAMEL_MESSAGE_INFO_FLAGS:
-		return ((const CamelMessageInfoBase *)mi)->flags;
-	case CAMEL_MESSAGE_INFO_SIZE:
-		return ((const CamelMessageInfoBase *)mi)->size;
-	default:
-		abort();
-	}
-}
-
-static time_t
-info_time(const CamelMessageInfo *mi, gint id)
-{
-	switch (id) {
-	case CAMEL_MESSAGE_INFO_DATE_SENT:
-		return ((const CamelMessageInfoBase *)mi)->date_sent;
-	case CAMEL_MESSAGE_INFO_DATE_RECEIVED:
-		return ((const CamelMessageInfoBase *)mi)->date_received;
-	default:
-		abort();
-	}
-}
-
-static gboolean
-info_user_flag(const CamelMessageInfo *mi, const gchar *id)
-{
-	return camel_flag_get(&((CamelMessageInfoBase *)mi)->user_flags, id);
-}
-
-static const gchar *
-info_user_tag(const CamelMessageInfo *mi, const gchar *id)
-{
-	return camel_tag_get(&((CamelMessageInfoBase *)mi)->user_tags, id);
-}
-
 /**
  * camel_message_info_ptr:
  * @mi: a #CamelMessageInfo
@@ -4687,7 +4919,7 @@ gconstpointer
 camel_message_info_ptr(const CamelMessageInfo *mi, gint id)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_ptr(mi, id);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_ptr (mi, id);
 	else
 		return info_ptr(mi, id);
 }
@@ -4705,7 +4937,7 @@ guint32
 camel_message_info_uint32(const CamelMessageInfo *mi, gint id)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_uint32(mi, id);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_uint32 (mi, id);
 	else
 		return info_uint32(mi, id);
 }
@@ -4723,7 +4955,7 @@ time_t
 camel_message_info_time(const CamelMessageInfo *mi, gint id)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_time(mi, id);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_time (mi, id);
 	else
 		return info_time(mi, id);
 }
@@ -4741,7 +4973,7 @@ gboolean
 camel_message_info_user_flag(const CamelMessageInfo *mi, const gchar *id)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_user_flag(mi, id);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_user_flag (mi, id);
 	else
 		return info_user_flag(mi, id);
 }
@@ -4759,78 +4991,15 @@ const gchar *
 camel_message_info_user_tag(const CamelMessageInfo *mi, const gchar *id)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_user_tag(mi, id);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_user_tag (mi, id);
 	else
 		return info_user_tag(mi, id);
 }
 
-static gboolean
-info_set_flags(CamelMessageInfo *info, guint32 flags, guint32 set)
-{
-	guint32 old;
-	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
-	gint read=0, deleted=0, junk=0;
-	/* TODO: locking? */
-
-	if (flags & CAMEL_MESSAGE_SEEN && ((set & CAMEL_MESSAGE_SEEN) != (mi->flags & CAMEL_MESSAGE_SEEN)))
-	{ read = set & CAMEL_MESSAGE_SEEN ? 1 : -1; d(printf("Setting read as %d\n", set & CAMEL_MESSAGE_SEEN ? 1 : 0));}
-
-	if (flags & CAMEL_MESSAGE_DELETED && ((set & CAMEL_MESSAGE_DELETED) != (mi->flags & CAMEL_MESSAGE_DELETED)))
-	{ deleted = set & CAMEL_MESSAGE_DELETED ? 1 : -1; d(printf("Setting deleted as %d\n", set & CAMEL_MESSAGE_DELETED ? 1 : 0));}
-
-	if (flags & CAMEL_MESSAGE_JUNK && ((set & CAMEL_MESSAGE_JUNK) != (mi->flags & CAMEL_MESSAGE_JUNK)))
-	{ junk = set & CAMEL_MESSAGE_JUNK ? 1 : -1; d(printf("Setting junk as %d\n", set & CAMEL_MESSAGE_JUNK ? 1 : 0));}
-
-	old = mi->flags;
-	mi->flags = (old & ~flags) | (set & flags);
-	if (old != mi->flags) {
-		mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
-		mi->dirty = TRUE;
-		if (mi->summary)
-			camel_folder_summary_touch(mi->summary);
-	}
-
-	if (((old & ~CAMEL_MESSAGE_SYSTEM_MASK) == (mi->flags & ~CAMEL_MESSAGE_SYSTEM_MASK)) && !((set & CAMEL_MESSAGE_JUNK_LEARN) && !(set & CAMEL_MESSAGE_JUNK)))
-		return FALSE;
-
-	if (mi->summary) {
-		if (read && junk == 0 && !(mi->flags & CAMEL_MESSAGE_JUNK))
-			mi->summary->unread_count -= read;
-		else if (junk > 0)
-			mi->summary->unread_count -= (old & CAMEL_MESSAGE_SEEN) ? 0 : 1;
-		else if (junk < 0)
-			mi->summary->unread_count -= (old & CAMEL_MESSAGE_SEEN) ? 0 : -1;
-
-		if (deleted)
-			mi->summary->deleted_count += deleted;
-		if (junk)
-			mi->summary->junk_count += junk;
-		if (junk && !deleted)
-			mi->summary->junk_not_deleted_count += junk;
-		else if ((mi->flags & CAMEL_MESSAGE_JUNK) && deleted)
-			mi->summary->junk_not_deleted_count -= deleted;
-
-		if (((junk && !(mi->flags & CAMEL_MESSAGE_DELETED)))||  (deleted && !(mi->flags & CAMEL_MESSAGE_JUNK)) )
-			mi->summary->visible_count -= junk ? junk : deleted;
-	}
-	if (mi->uid)
-		g_hash_table_replace (_PRIVATE(mi->summary)->flag_cache, (gchar *)mi->uid, GUINT_TO_POINTER(mi->flags));
-	if (mi->summary && mi->summary->folder && mi->uid) {
-		CamelFolderChangeInfo *changes = camel_folder_change_info_new();
-
-		camel_folder_change_info_change_uid(changes, camel_message_info_uid(info));
-		camel_object_trigger_event(mi->summary->folder, "folder_changed", changes);
-		camel_folder_change_info_free(changes);
-	}
-
-	d(printf("%d %d %d %d %d\n", mi->summary->unread_count, mi->summary->deleted_count, mi->summary->junk_count, mi->summary->junk_not_deleted_count, mi->summary->visible_count));
-	return TRUE;
-}
-
 void
 camel_folder_summary_update_flag_cache (CamelFolderSummary *s, const gchar *uid, guint32 flag)
 {
-	g_hash_table_replace (_PRIVATE(s)->flag_cache, (gchar *) uid, GUINT_TO_POINTER(flag));
+	g_hash_table_replace (CAMEL_FOLDER_SUMMARY_GET_PRIVATE(s)->flag_cache, (gchar *) uid, GUINT_TO_POINTER(flag));
 }
 /**
  * camel_message_info_set_flags:
@@ -4846,34 +5015,11 @@ gboolean
 camel_message_info_set_flags(CamelMessageInfo *mi, guint32 flags, guint32 set)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_set_flags(mi, flags, set);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_set_flags (mi, flags, set);
 	else
 		return info_set_flags(mi, flags, set);
 }
 
-static gboolean
-info_set_user_flag(CamelMessageInfo *info, const gchar *name, gboolean value)
-{
-	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
-	gint res;
-
-	res = camel_flag_set(&mi->user_flags, name, value);
-
-	/* TODO: check this item is still in the summary first */
-	if (mi->summary && res && mi->summary->folder && mi->uid) {
-		CamelFolderChangeInfo *changes = camel_folder_change_info_new();
-
-		mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
-		mi->dirty = TRUE;
-		camel_folder_summary_touch(mi->summary);
-		camel_folder_change_info_change_uid(changes, camel_message_info_uid(info));
-		camel_object_trigger_event(mi->summary->folder, "folder_changed", changes);
-		camel_folder_change_info_free(changes);
-	}
-
-	return res;
-}
-
 /**
  * camel_message_info_set_user_flag:
  * @mi: a #CamelMessageInfo
@@ -4888,33 +5034,11 @@ gboolean
 camel_message_info_set_user_flag(CamelMessageInfo *mi, const gchar *id, gboolean state)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_set_user_flag(mi, id, state);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_set_user_flag (mi, id, state);
 	else
 		return info_set_user_flag(mi, id, state);
 }
 
-static gboolean
-info_set_user_tag(CamelMessageInfo *info, const gchar *name, const gchar *value)
-{
-	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
-	gint res;
-
-	res = camel_tag_set(&mi->user_tags, name, value);
-
-	if (mi->summary && res && mi->summary->folder && mi->uid) {
-		CamelFolderChangeInfo *changes = camel_folder_change_info_new();
-
-		mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
-		mi->dirty = TRUE;
-		camel_folder_summary_touch(mi->summary);
-		camel_folder_change_info_change_uid(changes, camel_message_info_uid(info));
-		camel_object_trigger_event(mi->summary->folder, "folder_changed", changes);
-		camel_folder_change_info_free(changes);
-	}
-
-	return res;
-}
-
 /**
  * camel_message_info_set_user_tag:
  * @mi: a #CamelMessageInfo
@@ -4929,7 +5053,7 @@ gboolean
 camel_message_info_set_user_tag(CamelMessageInfo *mi, const gchar *id, const gchar *val)
 {
 	if (mi->summary)
-		return ((CamelFolderSummaryClass *)((CamelObject *)mi->summary)->klass)->info_set_user_tag(mi, id, val);
+		return CAMEL_FOLDER_SUMMARY_GET_CLASS (mi->summary)->info_set_user_tag (mi, id, val);
 	else
 		return info_set_user_tag(mi, id, val);
 }
@@ -4981,69 +5105,16 @@ camel_message_info_dump (CamelMessageInfo *mi)
 	/*camel_content_info_dump(mi->content, 0);*/
 }
 
-static void
-camel_folder_summary_class_init (CamelFolderSummaryClass *klass)
-{
-	camel_folder_summary_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
-
-	klass->summary_header_load = summary_header_load;
-	klass->summary_header_save = summary_header_save;
-
-	klass->summary_header_from_db = summary_header_from_db;
-	klass->summary_header_to_db = summary_header_to_db;
-	klass->message_info_from_db = message_info_from_db;
-	klass->message_info_to_db = message_info_to_db;
-	klass->content_info_from_db = content_info_from_db;
-	klass->content_info_to_db = content_info_to_db;
-
-	klass->message_info_new_from_header  = message_info_new_from_header;
-	klass->message_info_new_from_parser = message_info_new_from_parser;
-	klass->message_info_new_from_message = message_info_new_from_message;
-	klass->message_info_load = message_info_load;
-	klass->message_info_save = message_info_save;
-	klass->meta_message_info_save = meta_message_info_save;
-	klass->message_info_free = message_info_free;
-	klass->message_info_clone = message_info_clone;
-	klass->message_info_from_uid = message_info_from_uid;
-
-	klass->content_info_new_from_header  = content_info_new_from_header;
-	klass->content_info_new_from_parser = content_info_new_from_parser;
-	klass->content_info_new_from_message = content_info_new_from_message;
-	klass->content_info_load = content_info_load;
-	klass->content_info_save = content_info_save;
-	klass->content_info_free = content_info_free;
-
-	klass->next_uid_string = next_uid_string;
-
-	klass->info_ptr = info_ptr;
-	klass->info_uint32 = info_uint32;
-	klass->info_time = info_time;
-	klass->info_user_flag = info_user_flag;
-	klass->info_user_tag = info_user_tag;
-
-#if 0
-	klass->info_set_string = info_set_string;
-	klass->info_set_uint32 = info_set_uint32;
-	klass->info_set_time = info_set_time;
-	klass->info_set_ptr = info_set_ptr;
-#endif
-	klass->info_set_user_flag = info_set_user_flag;
-	klass->info_set_user_tag = info_set_user_tag;
-
-	klass->info_set_flags = info_set_flags;
-
-}
-
 /* Utils */
 void
 camel_folder_summary_set_need_preview (CamelFolderSummary *summary, gboolean preview)
 {
-	_PRIVATE(summary)->need_preview = preview;
+	CAMEL_FOLDER_SUMMARY_GET_PRIVATE(summary)->need_preview = preview;
 }
 
 gboolean
 camel_folder_summary_get_need_preview (CamelFolderSummary *summary)
 {
-	return _PRIVATE(summary)->need_preview;
+	return CAMEL_FOLDER_SUMMARY_GET_PRIVATE(summary)->need_preview;
 }
 
diff --git a/camel/camel-folder-summary.h b/camel/camel-folder-summary.h
index 9f771cb..f2d7a6a 100644
--- a/camel/camel-folder-summary.h
+++ b/camel/camel-folder-summary.h
@@ -19,32 +19,56 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_FOLDER_SUMMARY_H
-#define _CAMEL_FOLDER_SUMMARY_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_FOLDER_SUMMARY_H
+#define CAMEL_FOLDER_SUMMARY_H
 
 #include <stdio.h>
 #include <time.h>
+
+#include <camel/camel-mime-message.h>
 #include <camel/camel-mime-parser.h>
 #include <camel/camel-object.h>
 #include <camel/camel-index.h>
 
-#define CAMEL_FOLDER_SUMMARY_TYPE         camel_folder_summary_get_type ()
-#define CAMEL_FOLDER_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_folder_summary_get_type (), CamelFolderSummary)
-#define CAMEL_FOLDER_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_folder_summary_get_type (), CamelFolderSummaryClass)
-#define CAMEL_IS_FOLDER_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_folder_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_FOLDER_SUMMARY \
+	(camel_folder_summary_get_type ())
+#define CAMEL_FOLDER_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_FOLDER_SUMMARY, CamelFolderSummary))
+#define CAMEL_FOLDER_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_FOLDER_SUMMARY, CamelFolderSummaryClass))
+#define CAMEL_IS_FOLDER_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_FOLDER_SUMMARY))
+#define CAMEL_IS_FOLDER_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_FOLDER_SUMMARY))
+#define CAMEL_FOLDER_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_FOLDER_SUMMARY, CamelFolderSummaryClass))
 
 G_BEGIN_DECLS
 
 struct _CamelFolder;
+struct _CamelStore;
 
-/*typedef struct _CamelFolderSummary      CamelFolderSummary;*/
+typedef struct _CamelFolderSummary CamelFolderSummary;
 typedef struct _CamelFolderSummaryClass CamelFolderSummaryClass;
+typedef struct _CamelFolderSummaryPrivate CamelFolderSummaryPrivate;
 
 typedef struct _CamelMessageInfo CamelMessageInfo;
 typedef struct _CamelMessageInfoBase CamelMessageInfoBase;
 
 typedef struct _CamelFolderMetaSummary CamelFolderMetaSummary;
 
+typedef struct _CamelMessageContentInfo CamelMessageContentInfo;
+
 /* A tree of message content info structures
    describe the content structure of the message (if it has any) */
 struct _CamelMessageContentInfo {
@@ -207,8 +231,7 @@ typedef enum _CamelFolderSummaryFlags {
 
 struct _CamelFolderSummary {
 	CamelObject parent;
-
-	struct _CamelFolderSummaryPrivate *priv;
+	CamelFolderSummaryPrivate *priv;
 
 	/* header info */
 	guint32 version;	/* version of file loaded/loading */
@@ -323,7 +346,7 @@ struct _CamelFolderMetaSummary {
 	gchar *path;		/* Path to meta-summary-file */
 };
 
-CamelType			 camel_folder_summary_get_type	(void);
+GType			 camel_folder_summary_get_type	(void);
 CamelFolderSummary      *camel_folder_summary_new	(struct _CamelFolder *folder);
 
 /* Deprecated */
@@ -346,7 +369,7 @@ gint camel_folder_summary_load_from_db (CamelFolderSummary *s, CamelException *e
 
 /* only load the header */
 gint camel_folder_summary_header_load(CamelFolderSummary *summary);
-gint camel_folder_summary_header_load_from_db (CamelFolderSummary *s, CamelStore *store, const gchar *folder_name, CamelException *ex);
+gint camel_folder_summary_header_load_from_db (CamelFolderSummary *s, struct _CamelStore *store, const gchar *folder_name, CamelException *ex);
 gint camel_folder_summary_header_save_to_db (CamelFolderSummary *s, CamelException *ex);
 
 /* set the dirty bit on the summary */
@@ -485,4 +508,4 @@ gint camel_folder_summary_migrate_infos(CamelFolderSummary *s);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_FOLDER_SUMMARY_H */
+#endif /* CAMEL_FOLDER_SUMMARY_H */
diff --git a/camel/camel-folder-thread.c b/camel/camel-folder-thread.c
index 4c3b51e..ff9221d 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);
+	g_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);
+		g_object_unref (thread->folder);
 	}
 	e_memchunk_destroy(thread->node_chunks);
 	g_free(thread);
diff --git a/camel/camel-folder-thread.h b/camel/camel-folder-thread.h
index 1479648..2d973d2 100644
--- a/camel/camel-folder-thread.h
+++ b/camel/camel-folder-thread.h
@@ -19,8 +19,12 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_FOLDER_THREAD_H
-#define _CAMEL_FOLDER_THREAD_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_FOLDER_THREAD_H
+#define CAMEL_FOLDER_THREAD_H
 
 #include <camel/camel-folder-summary.h>
 #include <camel/camel-folder.h>
@@ -65,4 +69,4 @@ gint camel_folder_threaded_messages_dump(CamelFolderThreadNode *c);
 
 G_END_DECLS
 
-#endif /* !_CAMEL_FOLDER_THREAD_H */
+#endif /* !CAMEL_FOLDER_THREAD_H */
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index e5af4af..d63782d 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -28,7 +28,6 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include <libedataserver/e-memory.h>
@@ -46,15 +45,14 @@
 #include "camel-vtrash-folder.h"
 #include "camel-string-utils.h"
 
+#define CAMEL_FOLDER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_FOLDER, CamelFolderPrivate))
+
 #define d(x)
 #define w(x)
 
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelFolder */
-#define CF_CLASS(so) ((CamelFolderClass *)((CamelObject *)(so))->klass)
-
-static void camel_folder_finalize (CamelObject *object);
+static gpointer parent_class;
 
 static void refresh_info (CamelFolder *folder, CamelException *ex);
 
@@ -65,20 +63,20 @@ static const gchar *get_name (CamelFolder *folder);
 static const gchar *get_full_name (CamelFolder *folder);
 static CamelStore *get_parent_store   (CamelFolder *folder);
 
-static guint32 get_permanent_flags(CamelFolder *folder);
-static guint32 get_message_flags(CamelFolder *folder, const gchar *uid);
-static gboolean set_message_flags(CamelFolder *folder, const gchar *uid, guint32 flags, guint32 set);
-static gboolean get_message_user_flag(CamelFolder *folder, const gchar *uid, const gchar *name);
-static void set_message_user_flag(CamelFolder *folder, const gchar *uid, const gchar *name, gboolean value);
-static const gchar *get_message_user_tag(CamelFolder *folder, const gchar *uid, const gchar *name);
-static void set_message_user_tag(CamelFolder *folder, const gchar *uid, const gchar *name, const gchar *value);
+static guint32 get_permanent_flags (CamelFolder *folder);
+static guint32 get_message_flags (CamelFolder *folder, const gchar *uid);
+static gboolean set_message_flags (CamelFolder *folder, const gchar *uid, guint32 flags, guint32 set);
+static gboolean get_message_user_flag (CamelFolder *folder, const gchar *uid, const gchar *name);
+static void set_message_user_flag (CamelFolder *folder, const gchar *uid, const gchar *name, gboolean value);
+static const gchar *get_message_user_tag (CamelFolder *folder, const gchar *uid, const gchar *name);
+static void set_message_user_tag (CamelFolder *folder, const gchar *uid, const gchar *name, const gchar *value);
 
-static gint get_message_count(CamelFolder *folder);
+static gint get_message_count (CamelFolder *folder);
 
 static void expunge             (CamelFolder *folder,
 				 CamelException *ex);
-static gint folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args);
-static void folder_free(CamelObject *o, guint32 tag, gpointer val);
+static gint folder_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
+static void folder_free (CamelObject *o, guint32 tag, gpointer val);
 
 static void append_message (CamelFolder *folder, CamelMimeMessage *message,
 			    const CamelMessageInfo *info, gchar **appended_uid,
@@ -127,131 +125,165 @@ static gchar *           get_filename          (CamelFolder *folder,
 static CamelFolderQuotaInfo *get_quota_info  (CamelFolder *folder);
 
 static void
-camel_folder_class_init (CamelFolderClass *camel_folder_class)
-{
-	CamelObjectClass *camel_object_class = CAMEL_OBJECT_CLASS (camel_folder_class);
-
-	parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
-
-	/* virtual method definition */
-	camel_folder_class->sync = folder_sync;
-	camel_folder_class->refresh_info = refresh_info;
-	camel_folder_class->get_name = get_name;
-	camel_folder_class->get_full_name = get_full_name;
-	camel_folder_class->get_parent_store = get_parent_store;
-	camel_folder_class->expunge = expunge;
-	camel_folder_class->get_message_count = get_message_count;
-	camel_folder_class->append_message = append_message;
-	camel_folder_class->get_permanent_flags = get_permanent_flags;
-	camel_folder_class->get_message_flags = get_message_flags;
-	camel_folder_class->set_message_flags = set_message_flags;
-	camel_folder_class->get_message_user_flag = get_message_user_flag;
-	camel_folder_class->set_message_user_flag = set_message_user_flag;
-	camel_folder_class->get_message_user_tag = get_message_user_tag;
-	camel_folder_class->set_message_user_tag = set_message_user_tag;
-	camel_folder_class->get_message = get_message;
-	camel_folder_class->get_uids = get_uids;
-	camel_folder_class->get_uncached_uids = get_uncached_uids;
-	camel_folder_class->free_uids = free_uids;
-	camel_folder_class->cmp_uids = cmp_uids;
-	camel_folder_class->sort_uids = sort_uids;
-	camel_folder_class->get_summary = get_summary;
-	camel_folder_class->free_summary = free_summary;
-	camel_folder_class->search_by_expression = search_by_expression;
-	camel_folder_class->count_by_expression = count_by_expression;
-	camel_folder_class->search_by_uids = search_by_uids;
-	camel_folder_class->search_free = search_free;
-	camel_folder_class->get_message_info = get_message_info;
-	camel_folder_class->ref_message_info = ref_message_info;
-	camel_folder_class->free_message_info = free_message_info;
-	camel_folder_class->transfer_messages_to = transfer_messages_to;
-	camel_folder_class->delete = delete;
-	camel_folder_class->rename = folder_rename;
-	camel_folder_class->freeze = freeze;
-	camel_folder_class->sync_message = NULL;
-	camel_folder_class->thaw = thaw;
-	camel_folder_class->is_frozen = is_frozen;
-	camel_folder_class->get_quota_info = get_quota_info;
-	camel_folder_class->get_filename = get_filename;
-
-	/* virtual method overload */
-	camel_object_class->getv = folder_getv;
-	camel_object_class->free = folder_free;
+folder_dispose (GObject *object)
+{
+	CamelFolder *folder;
+
+	folder = CAMEL_FOLDER (object);
+
+	if (folder->parent_store != NULL) {
+		g_object_unref (folder->parent_store);
+		folder->parent_store = NULL;
+	}
 
-	/* events */
-	camel_object_class_add_event(camel_object_class, "folder_changed", folder_changed);
-	camel_object_class_add_event(camel_object_class, "deleted", NULL);
-	camel_object_class_add_event(camel_object_class, "renamed", NULL);
+	if (folder->summary) {
+		folder->summary->folder = NULL;
+		g_object_unref (folder->summary);
+		folder->summary = NULL;
+	}
+
+	/* Chain up to parent's dispose () method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_folder_init (gpointer object, gpointer klass)
+folder_finalize (GObject *object)
 {
-	CamelFolder *folder = object;
+	CamelFolder *folder;
+	CamelFolderPrivate *priv;
 
-	folder->priv = g_malloc0(sizeof(*folder->priv));
-	folder->priv->frozen = 0;
-	folder->priv->changed_frozen = camel_folder_change_info_new();
-	g_static_rec_mutex_init(&folder->priv->lock);
-	g_static_mutex_init(&folder->priv->change_lock);
+	folder = CAMEL_FOLDER (object);
+	priv = CAMEL_FOLDER_GET_PRIVATE (object);
+
+	g_free (folder->name);
+	g_free (folder->full_name);
+	g_free (folder->description);
+
+	camel_folder_change_info_free (priv->changed_frozen);
+
+	g_static_rec_mutex_free (&priv->lock);
+	g_static_mutex_free (&priv->change_lock);
+
+	/* Chain up to parent's finalize () method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_folder_finalize (CamelObject *object)
+folder_class_init (CamelFolderClass *class)
 {
-	CamelFolder *camel_folder = CAMEL_FOLDER (object);
-	struct _CamelFolderPrivate *p = camel_folder->priv;
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
 
-	g_free(camel_folder->name);
-	g_free(camel_folder->full_name);
-	g_free(camel_folder->description);
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelFolderPrivate));
 
-	if (camel_folder->parent_store)
-		camel_object_unref (camel_folder->parent_store);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = folder_dispose;
+	object_class->finalize = folder_finalize;
 
-	if (camel_folder->summary) {
-		camel_folder->summary->folder = NULL;
-		camel_object_unref (camel_folder->summary);
-	}
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = folder_getv;
+	camel_object_class->free = folder_free;
+
+	class->sync = folder_sync;
+	class->refresh_info = refresh_info;
+	class->get_name = get_name;
+	class->get_full_name = get_full_name;
+	class->get_parent_store = get_parent_store;
+	class->expunge = expunge;
+	class->get_message_count = get_message_count;
+	class->append_message = append_message;
+	class->get_permanent_flags = get_permanent_flags;
+	class->get_message_flags = get_message_flags;
+	class->set_message_flags = set_message_flags;
+	class->get_message_user_flag = get_message_user_flag;
+	class->set_message_user_flag = set_message_user_flag;
+	class->get_message_user_tag = get_message_user_tag;
+	class->set_message_user_tag = set_message_user_tag;
+	class->get_message = get_message;
+	class->get_uids = get_uids;
+	class->get_uncached_uids = get_uncached_uids;
+	class->free_uids = free_uids;
+	class->cmp_uids = cmp_uids;
+	class->sort_uids = sort_uids;
+	class->get_summary = get_summary;
+	class->free_summary = free_summary;
+	class->search_by_expression = search_by_expression;
+	class->count_by_expression = count_by_expression;
+	class->search_by_uids = search_by_uids;
+	class->search_free = search_free;
+	class->get_message_info = get_message_info;
+	class->ref_message_info = ref_message_info;
+	class->free_message_info = free_message_info;
+	class->transfer_messages_to = transfer_messages_to;
+	class->delete = delete;
+	class->rename = folder_rename;
+	class->freeze = freeze;
+	class->sync_message = NULL;
+	class->thaw = thaw;
+	class->is_frozen = is_frozen;
+	class->get_quota_info = get_quota_info;
+	class->get_filename = get_filename;
+
+	camel_object_class_add_event (
+		camel_object_class, "folder_changed", folder_changed);
+	camel_object_class_add_event (
+		camel_object_class, "deleted", NULL);
+	camel_object_class_add_event (
+		camel_object_class, "renamed", NULL);
+}
 
-	camel_folder_change_info_free(p->changed_frozen);
+static void
+folder_init (CamelFolder *folder)
+{
+	folder->priv = CAMEL_FOLDER_GET_PRIVATE (folder);
 
-	g_static_rec_mutex_free(&p->lock);
-	g_static_mutex_free(&p->change_lock);
+	folder->priv->frozen = 0;
+	folder->priv->changed_frozen = camel_folder_change_info_new ();
 
-	g_free(p);
+	g_static_rec_mutex_init (&folder->priv->lock);
+	g_static_mutex_init (&folder->priv->change_lock);
 }
 
-CamelType
+GType
 camel_folder_get_type (void)
 {
-	static CamelType camel_folder_type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (camel_folder_type == CAMEL_INVALID_TYPE)	{
-		camel_folder_type = camel_type_register (CAMEL_OBJECT_TYPE, "CamelFolder",
-							 sizeof (CamelFolder),
-							 sizeof (CamelFolderClass),
-							 (CamelObjectClassInitFunc) camel_folder_class_init,
-							 NULL,
-							 (CamelObjectInitFunc) camel_folder_init,
-							 (CamelObjectFinalizeFunc) camel_folder_finalize );
-	}
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelFolder",
+			sizeof (CamelFolderClass),
+			(GClassInitFunc) folder_class_init,
+			sizeof (CamelFolder),
+			(GInstanceInitFunc) folder_init,
+			0);
 
-	return camel_folder_type;
+	return type;
 }
 
 static gchar *
 get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex)
 {
-	w(g_warning ("CamelFolder::get_filename not implemented for '%s'",
+	w (g_warning ("CamelFolder::get_filename not implemented for '%s'",
 		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
 	return g_strdup ("/dev/null");
 }
 
 gchar *
-camel_folder_get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex)
+camel_folder_get_filename (CamelFolder *folder,
+                           const gchar *uid,
+                           CamelException *ex)
 {
-	return CF_CLASS (folder)->get_filename (folder, uid, ex);
+	CamelFolderClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_filename != NULL, NULL);
+
+	return class->get_filename (folder, uid, ex);
 }
 
 /**
@@ -274,7 +306,7 @@ camel_folder_construct (CamelFolder *folder, CamelStore *parent_store,
 
 	folder->parent_store = parent_store;
 	if (parent_store)
-		camel_object_ref(parent_store);
+		g_object_ref (parent_store);
 
 	folder->name = g_strdup (name);
 	folder->full_name = g_strdup (full_name);
@@ -283,8 +315,8 @@ camel_folder_construct (CamelFolder *folder, CamelStore *parent_store,
 static void
 folder_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 {
-	w(g_warning ("CamelFolder::sync not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+	w (g_warning ("CamelFolder::sync not implemented for '%s'",
+		     G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 }
 
 /**
@@ -297,16 +329,23 @@ folder_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
  * expunging deleted messages as well.
  **/
 void
-camel_folder_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
+camel_folder_sync (CamelFolder *folder,
+                   gboolean expunge,
+                   CamelException *ex)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
-	CAMEL_FOLDER_REC_LOCK(folder, lock);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->sync != NULL);
+
+	CAMEL_FOLDER_REC_LOCK (folder, lock);
 
 	if (!(folder->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED))
-		CF_CLASS (folder)->sync (folder, expunge, ex);
+		class->sync (folder, expunge, ex);
 
-	CAMEL_FOLDER_REC_UNLOCK(folder, lock);
+	CAMEL_FOLDER_REC_UNLOCK (folder, lock);
 }
 
 static void
@@ -323,17 +362,25 @@ refresh_info (CamelFolder *folder, CamelException *ex)
  * Updates a folder's summary to be in sync with its backing store.
  **/
 void
-camel_folder_refresh_info (CamelFolder *folder, CamelException *ex)
+camel_folder_refresh_info (CamelFolder *folder,
+                           CamelException *ex)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->refresh_info != NULL);
+
 	CAMEL_FOLDER_REC_LOCK (folder, lock);
-	CF_CLASS (folder)->refresh_info (folder, ex);
+
+	class->refresh_info (folder, ex);
+
 	CAMEL_FOLDER_REC_UNLOCK (folder, lock);
 }
 
 static gint
-folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
+folder_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
 {
 	CamelFolder *folder = (CamelFolder *)object;
 	gint i;
@@ -349,7 +396,7 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 			/* CamelObject args */
 		case CAMEL_OBJECT_ARG_DESCRIPTION:
 			if (folder->description == NULL)
-				folder->description = g_strdup_printf("%s", folder->full_name);
+				folder->description = g_strdup_printf ("%s", folder->full_name);
 			*arg->ca_str = folder->description;
 			break;
 
@@ -367,7 +414,7 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 			*arg->ca_int = folder->permanent_flags;
 			break;
 		case CAMEL_FOLDER_ARG_TOTAL:
-			*arg->ca_int = camel_folder_summary_count(folder->summary);
+			*arg->ca_int = camel_folder_summary_count (folder->summary);
 			break;
 		case CAMEL_FOLDER_ARG_UNREAD:
 		case CAMEL_FOLDER_ARG_DELETED:
@@ -391,7 +438,7 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 					/* count = camel_folder_summary_count (folder->summary);
 					for (j = 0; j < count; j++) {
 						if ((info = camel_folder_summary_index (folder->summary, j))) {
-							guint32 flags = camel_message_info_flags(info);
+							guint32 flags = camel_message_info_flags (info);
 
 							if ((flags & (CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK)) == 0)
 								unread++;
@@ -404,7 +451,7 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 							}
 							if ((flags & (CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK)) == 0)
 								visible++;
-							camel_message_info_free(info);
+							camel_message_info_free (info);
 						}
 
 					}*/
@@ -416,7 +463,7 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 						/*
 						folder->summary->junk_count = junked;
 						folder->summary->deleted_count = deleted;
-						printf("*************************** %s %d %d %d\n", folder->full_name, folder->summary->unread_count, unread, count);
+						printf ("*************************** %s %d %d %d\n", folder->full_name, folder->summary->unread_count, unread, count);
 						folder->summary->unread_count = unread; */
 					}
 				}
@@ -448,13 +495,13 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 			CamelMessageInfo *info;
 			GPtrArray *array;
 
-			count = camel_folder_summary_count(folder->summary);
-			array = g_ptr_array_new();
-			g_ptr_array_set_size(array, count);
+			count = camel_folder_summary_count (folder->summary);
+			array = g_ptr_array_new ();
+			g_ptr_array_set_size (array, count);
 			for (j=0; j<count; j++) {
-				if ((info = camel_folder_summary_index(folder->summary, j))) {
-					array->pdata[i] = g_strdup(camel_message_info_uid(info));
-					camel_message_info_free(info);
+				if ((info = camel_folder_summary_index (folder->summary, j))) {
+					array->pdata[i] = g_strdup (camel_message_info_uid (info));
+					camel_message_info_free (info);
 				}
 			}
 			*arg->ca_ptr = array;*/
@@ -462,7 +509,7 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 			g_assert (0);
 			break; }
 		case CAMEL_FOLDER_ARG_INFO_ARRAY:
-			*arg->ca_ptr = camel_folder_summary_array(folder->summary);
+			*arg->ca_ptr = camel_folder_summary_array (folder->summary);
 			break;
 		case CAMEL_FOLDER_ARG_PROPERTIES:
 			*arg->ca_ptr = NULL;
@@ -474,11 +521,11 @@ folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 		arg->tag = (tag & CAMEL_ARG_TYPE) | CAMEL_ARG_IGNORE;
 	}
 
-	return parent_class->getv(object, ex, args);
+	return CAMEL_OBJECT_CLASS (parent_class)->getv (object, ex, args);
 }
 
 static void
-folder_free(CamelObject *o, guint32 tag, gpointer val)
+folder_free (CamelObject *o, guint32 tag, gpointer val)
 {
 	CamelFolder *folder = (CamelFolder *)o;
 
@@ -488,17 +535,17 @@ folder_free(CamelObject *o, guint32 tag, gpointer val)
 		gint i;
 
 		for (i=0; i<array->len; i++)
-			g_free(array->pdata[i]);
-		g_ptr_array_free(array, TRUE);
+			g_free (array->pdata[i]);
+		g_ptr_array_free (array, TRUE);
 		break; }
 	case CAMEL_FOLDER_ARG_INFO_ARRAY:
 		camel_folder_free_summary (folder, val);
 		break;
 	case CAMEL_FOLDER_ARG_PROPERTIES:
-		g_slist_free(val);
+		g_slist_free (val);
 		break;
 	default:
-		parent_class->free(o, tag, val);
+		CAMEL_OBJECT_CLASS (parent_class)->free (o, tag, val);
 	}
 }
 
@@ -520,9 +567,14 @@ get_name (CamelFolder *folder)
 const gchar *
 camel_folder_get_name (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 
-	return CF_CLASS (folder)->get_name (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_name != NULL, NULL);
+
+	return class->get_name (folder);
 }
 
 static const gchar *
@@ -542,9 +594,14 @@ get_full_name (CamelFolder *folder)
 const gchar *
 camel_folder_get_full_name (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 
-	return CF_CLASS (folder)->get_full_name (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_full_name != NULL, NULL);
+
+	return class->get_full_name (folder);
 }
 
 static CamelStore *
@@ -562,16 +619,21 @@ get_parent_store (CamelFolder * folder)
 CamelStore *
 camel_folder_get_parent_store (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 
-	return CF_CLASS (folder)->get_parent_store (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_parent_store != NULL, NULL);
+
+	return class->get_parent_store (folder);
 }
 
 static void
 expunge (CamelFolder *folder, CamelException *ex)
 {
-	w(g_warning ("CamelFolder::expunge not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+	w (g_warning ("CamelFolder::expunge not implemented for '%s'",
+		     G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 }
 
 /**
@@ -582,24 +644,30 @@ expunge (CamelFolder *folder, CamelException *ex)
  * Delete messages which have been marked as "DELETED"
  **/
 void
-camel_folder_expunge (CamelFolder *folder, CamelException *ex)
+camel_folder_expunge (CamelFolder *folder,
+                      CamelException *ex)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
-	CAMEL_FOLDER_REC_LOCK(folder, lock);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->expunge != NULL);
+
+	CAMEL_FOLDER_REC_LOCK (folder, lock);
 
 	if (!(folder->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED))
-		CF_CLASS (folder)->expunge (folder, ex);
+		class->expunge (folder, ex);
 
-	CAMEL_FOLDER_REC_UNLOCK(folder, lock);
+	CAMEL_FOLDER_REC_UNLOCK (folder, lock);
 }
 
 static gint
 get_message_count (CamelFolder *folder)
 {
-	g_return_val_if_fail(folder->summary != NULL, -1);
+	g_return_val_if_fail (folder->summary != NULL, -1);
 
-	return camel_folder_summary_count(folder->summary);
+	return camel_folder_summary_count (folder->summary);
 }
 
 /**
@@ -611,13 +679,14 @@ get_message_count (CamelFolder *folder)
 gint
 camel_folder_get_message_count (CamelFolder *folder)
 {
-	gint ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), -1);
 
-	ret = CF_CLASS (folder)->get_message_count (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_message_count != NULL, -1);
 
-	return ret;
+	return class->get_message_count (folder);
 }
 
 /**
@@ -636,7 +705,7 @@ camel_folder_get_unread_message_count (CamelFolder *folder)
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), -1);
 
-	camel_object_get(folder, NULL, CAMEL_FOLDER_UNREAD, &count, 0);
+	camel_object_get (folder, NULL, CAMEL_FOLDER_UNREAD, &count, 0);
 
 	return count;
 }
@@ -655,7 +724,7 @@ camel_folder_get_deleted_message_count (CamelFolder *folder)
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), -1);
 
-	camel_object_get(folder, NULL, CAMEL_FOLDER_DELETED, &count, 0);
+	camel_object_get (folder, NULL, CAMEL_FOLDER_DELETED, &count, 0);
 
 	return count;
 }
@@ -667,10 +736,10 @@ append_message (CamelFolder *folder, CamelMimeMessage *message,
 {
 	camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
 			      _("Unsupported operation: append message: for %s"),
-			      camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder)));
+			      G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder)));
 
-	w(g_warning ("CamelFolder::append_message not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+	w (g_warning ("CamelFolder::append_message not implemented for '%s'",
+		     G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 
 	return;
 
@@ -690,15 +759,24 @@ append_message (CamelFolder *folder, CamelMimeMessage *message,
  * are used. If @info is %NULL, no flags or tags will be set.
  **/
 void
-camel_folder_append_message (CamelFolder *folder, CamelMimeMessage *message,
-			     const CamelMessageInfo *info, gchar **appended_uid,
-			     CamelException *ex)
+camel_folder_append_message (CamelFolder *folder,
+                             CamelMimeMessage *message,
+                             const CamelMessageInfo *info,
+                             gchar **appended_uid,
+                             CamelException *ex)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
-	CAMEL_FOLDER_REC_LOCK(folder, lock);
-	CF_CLASS (folder)->append_message (folder, message, info, appended_uid, ex);
-	CAMEL_FOLDER_REC_UNLOCK(folder, lock);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->append_message != NULL);
+
+	CAMEL_FOLDER_REC_LOCK (folder, lock);
+
+	class->append_message (folder, message, info, appended_uid, ex);
+
+	CAMEL_FOLDER_REC_UNLOCK (folder, lock);
 }
 
 static guint32
@@ -718,25 +796,30 @@ get_permanent_flags (CamelFolder *folder)
 guint32
 camel_folder_get_permanent_flags (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), 0);
 
-	return CF_CLASS (folder)->get_permanent_flags (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_permanent_flags != NULL, 0);
+
+	return class->get_permanent_flags (folder);
 }
 
 static guint32
-get_message_flags(CamelFolder *folder, const gchar *uid)
+get_message_flags (CamelFolder *folder, const gchar *uid)
 {
 	CamelMessageInfo *info;
 	guint32 flags;
 
-	g_return_val_if_fail(folder->summary != NULL, 0);
+	g_return_val_if_fail (folder->summary != NULL, 0);
 
-	info = camel_folder_summary_uid(folder->summary, uid);
+	info = camel_folder_summary_uid (folder->summary, uid);
 	if (info == NULL)
 		return 0;
 
-	flags = camel_message_info_flags(info);
-	camel_message_info_free(info);
+	flags = camel_message_info_flags (info);
+	camel_message_info_free (info);
 
 	return flags;
 }
@@ -752,31 +835,34 @@ get_message_flags(CamelFolder *folder, const gchar *uid)
  * message.
  **/
 guint32
-camel_folder_get_message_flags (CamelFolder *folder, const gchar *uid)
+camel_folder_get_message_flags (CamelFolder *folder,
+                                const gchar *uid)
 {
-	guint32 ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), 0);
+	g_return_val_if_fail (uid != NULL, 0);
 
-	ret = CF_CLASS (folder)->get_message_flags (folder, uid);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_message_flags != NULL, 0);
 
-	return ret;
+	return class->get_message_flags (folder, uid);
 }
 
 static gboolean
-set_message_flags(CamelFolder *folder, const gchar *uid, guint32 flags, guint32 set)
+set_message_flags (CamelFolder *folder, const gchar *uid, guint32 flags, guint32 set)
 {
 	CamelMessageInfo *info;
 	gint res;
 
-	g_return_val_if_fail(folder->summary != NULL, FALSE);
+	g_return_val_if_fail (folder->summary != NULL, FALSE);
 
-	info = camel_folder_summary_uid(folder->summary, uid);
+	info = camel_folder_summary_uid (folder->summary, uid);
 	if (info == NULL)
 		return FALSE;
 
-	res = camel_message_info_set_flags(info, flags, set);
-	camel_message_info_free(info);
+	res = camel_message_info_set_flags (info, flags, set);
+	camel_message_info_free (info);
 
 	return res;
 }
@@ -793,7 +879,7 @@ set_message_flags(CamelFolder *folder, const gchar *uid, guint32 flags, guint32
  * folder or store is closed. See #camel_folder_get_permanent_flags)
  *
  * E.g. to set the deleted flag and clear the draft flag, use
- * #camel_folder_set_message_flags(folder, uid, CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_DRAFT, CAMEL_MESSAGE_DELETED);
+ * #camel_folder_set_message_flags (folder, uid, CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_DRAFT, CAMEL_MESSAGE_DELETED);
  *
  * DEPRECATED: Use #camel_message_info_set_flags on the message info directly
  * (when it works)
@@ -801,32 +887,41 @@ set_message_flags(CamelFolder *folder, const gchar *uid, guint32 flags, guint32
  * Returns: %TRUE if the flags were changed or %FALSE otherwise
  **/
 gboolean
-camel_folder_set_message_flags(CamelFolder *folder, const gchar *uid, guint32 flags, guint32 set)
+camel_folder_set_message_flags (CamelFolder *folder,
+                                const gchar *uid,
+                                guint32 flags,
+                                guint32 set)
 {
-	g_return_val_if_fail(CAMEL_IS_FOLDER(folder), FALSE);
+	CamelFolderClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+	g_return_val_if_fail (uid != NULL, FALSE);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->set_message_flags != NULL, FALSE);
 
 	if ((flags & (CAMEL_MESSAGE_JUNK|CAMEL_MESSAGE_JUNK_LEARN)) == CAMEL_MESSAGE_JUNK) {
 		flags |= CAMEL_MESSAGE_JUNK_LEARN;
 		set &= ~CAMEL_MESSAGE_JUNK_LEARN;
 	}
 
-	return CF_CLASS(folder)->set_message_flags(folder, uid, flags, set);
+	return class->set_message_flags (folder, uid, flags, set);
 }
 
 static gboolean
-get_message_user_flag(CamelFolder *folder, const gchar *uid, const gchar *name)
+get_message_user_flag (CamelFolder *folder, const gchar *uid, const gchar *name)
 {
 	CamelMessageInfo *info;
 	gboolean ret;
 
-	g_return_val_if_fail(folder->summary != NULL, FALSE);
+	g_return_val_if_fail (folder->summary != NULL, FALSE);
 
-	info = camel_folder_summary_uid(folder->summary, uid);
+	info = camel_folder_summary_uid (folder->summary, uid);
 	if (info == NULL)
 		return FALSE;
 
-	ret = camel_message_info_user_flag(info, name);
-	camel_message_info_free(info);
+	ret = camel_message_info_user_flag (info, name);
+	camel_message_info_free (info);
 
 	return ret;
 }
@@ -844,31 +939,35 @@ get_message_user_flag(CamelFolder *folder, const gchar *uid, const gchar *name)
  * %FALSE otherwise
  **/
 gboolean
-camel_folder_get_message_user_flag (CamelFolder *folder, const gchar *uid,
-				    const gchar *name)
+camel_folder_get_message_user_flag (CamelFolder *folder,
+                                    const gchar *uid,
+                                    const gchar *name)
 {
-	gboolean ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), 0);
+	g_return_val_if_fail (uid != NULL, 0);
+	g_return_val_if_fail (name != NULL, 0);
 
-	ret = CF_CLASS (folder)->get_message_user_flag (folder, uid, name);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_message_user_flag != NULL, 0);
 
-	return ret;
+	return class->get_message_user_flag (folder, uid, name);
 }
 
 static void
-set_message_user_flag(CamelFolder *folder, const gchar *uid, const gchar *name, gboolean value)
+set_message_user_flag (CamelFolder *folder, const gchar *uid, const gchar *name, gboolean value)
 {
 	CamelMessageInfo *info;
 
-	g_return_if_fail(folder->summary != NULL);
+	g_return_if_fail (folder->summary != NULL);
 
-	info = camel_folder_summary_uid(folder->summary, uid);
+	info = camel_folder_summary_uid (folder->summary, uid);
 	if (info == NULL)
 		return;
 
-	camel_message_info_set_user_flag(info, name, value);
-	camel_message_info_free(info);
+	camel_message_info_set_user_flag (info, name, value);
+	camel_message_info_free (info);
 }
 
 /**
@@ -886,28 +985,37 @@ set_message_user_flag(CamelFolder *folder, const gchar *uid, const gchar *name,
  * folder or store is closed. See #camel_folder_get_permanent_flags)
  **/
 void
-camel_folder_set_message_user_flag (CamelFolder *folder, const gchar *uid,
-				    const gchar *name, gboolean value)
+camel_folder_set_message_user_flag (CamelFolder *folder,
+                                    const gchar *uid,
+                                    const gchar *name,
+                                    gboolean value)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (uid != NULL);
+	g_return_if_fail (name != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->set_message_user_flag != NULL);
 
-	CF_CLASS (folder)->set_message_user_flag (folder, uid, name, value);
+	class->set_message_user_flag (folder, uid, name, value);
 }
 
 static const gchar *
-get_message_user_tag(CamelFolder *folder, const gchar *uid, const gchar *name)
+get_message_user_tag (CamelFolder *folder, const gchar *uid, const gchar *name)
 {
 	CamelMessageInfo *info;
 	const gchar *ret;
 
-	g_return_val_if_fail(folder->summary != NULL, NULL);
+	g_return_val_if_fail (folder->summary != NULL, NULL);
 
-	info = camel_folder_summary_uid(folder->summary, uid);
+	info = camel_folder_summary_uid (folder->summary, uid);
 	if (info == NULL)
 		return NULL;
 
-	ret = camel_message_info_user_tag(info, name);
-	camel_message_info_free(info);
+	ret = camel_message_info_user_tag (info, name);
+	camel_message_info_free (info);
 
 	return ret;
 }
@@ -924,31 +1032,36 @@ get_message_user_tag(CamelFolder *folder, const gchar *uid, const gchar *name)
  * Returns: the value of the user tag
  **/
 const gchar *
-camel_folder_get_message_user_tag (CamelFolder *folder, const gchar *uid,  const gchar *name)
+camel_folder_get_message_user_tag (CamelFolder *folder,
+                                   const gchar *uid,
+                                   const gchar *name)
 {
-	const gchar *ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+	g_return_val_if_fail (uid != NULL, NULL);
+	g_return_val_if_fail (name != NULL, NULL);
 
-	/* FIXME: should duplicate string */
-	ret = CF_CLASS (folder)->get_message_user_tag (folder, uid, name);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_message_user_tag != NULL, NULL);
 
-	return ret;
+	/* FIXME: should duplicate string */
+	return class->get_message_user_tag (folder, uid, name);
 }
 
 static void
-set_message_user_tag(CamelFolder *folder, const gchar *uid, const gchar *name, const gchar *value)
+set_message_user_tag (CamelFolder *folder, const gchar *uid, const gchar *name, const gchar *value)
 {
 	CamelMessageInfo *info;
 
-	g_return_if_fail(folder->summary != NULL);
+	g_return_if_fail (folder->summary != NULL);
 
-	info = camel_folder_summary_uid(folder->summary, uid);
+	info = camel_folder_summary_uid (folder->summary, uid);
 	if (info == NULL)
 		return;
 
-	camel_message_info_set_user_tag(info, name, value);
-	camel_message_info_free(info);
+	camel_message_info_set_user_tag (info, name, value);
+	camel_message_info_free (info);
 }
 
 /**
@@ -966,19 +1079,29 @@ set_message_user_tag(CamelFolder *folder, const gchar *uid, const gchar *name, c
  * folder or store is closed. See #camel_folder_get_permanent_flags)
  **/
 void
-camel_folder_set_message_user_tag (CamelFolder *folder, const gchar *uid, const gchar *name, const gchar *value)
+camel_folder_set_message_user_tag (CamelFolder *folder,
+                                   const gchar *uid,
+                                   const gchar *name,
+                                   const gchar *value)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (uid != NULL);
+	g_return_if_fail (name != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->set_message_user_tag != NULL);
 
-	CF_CLASS (folder)->set_message_user_tag (folder, uid, name, value);
+	class->set_message_user_tag (folder, uid, name, value);
 }
 
 static CamelMessageInfo *
 get_message_info (CamelFolder *folder, const gchar *uid)
 {
-	g_return_val_if_fail(folder->summary != NULL, NULL);
+	g_return_val_if_fail (folder->summary != NULL, NULL);
 
-	return camel_folder_summary_uid(folder->summary, uid);
+	return camel_folder_summary_uid (folder->summary, uid);
 }
 
 /**
@@ -993,24 +1116,26 @@ get_message_info (CamelFolder *folder, const gchar *uid)
  * if the uid does not exist
  **/
 CamelMessageInfo *
-camel_folder_get_message_info (CamelFolder *folder, const gchar *uid)
+camel_folder_get_message_info (CamelFolder *folder,
+                               const gchar *uid)
 {
-	CamelMessageInfo *ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 	g_return_val_if_fail (uid != NULL, NULL);
 
-	ret = CF_CLASS (folder)->get_message_info (folder, uid);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_message_info != NULL, NULL);
 
-	return ret;
+	return class->get_message_info (folder, uid);
 }
 
 static void
 free_message_info (CamelFolder *folder, CamelMessageInfo *info)
 {
-	g_return_if_fail(folder->summary != NULL);
+	g_return_if_fail (folder->summary != NULL);
 
-	camel_message_info_free(info);
+	camel_message_info_free (info);
 }
 
 /**
@@ -1022,20 +1147,26 @@ free_message_info (CamelFolder *folder, CamelMessageInfo *info)
  * #camel_folder_get_message_info.
  **/
 void
-camel_folder_free_message_info(CamelFolder *folder, CamelMessageInfo *info)
+camel_folder_free_message_info (CamelFolder *folder,
+                                CamelMessageInfo *info)
 {
-	g_return_if_fail(CAMEL_IS_FOLDER (folder));
-	g_return_if_fail(info != NULL);
+	CamelFolderClass *class;
+
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (info != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->free_message_info != NULL);
 
-	CF_CLASS (folder)->free_message_info(folder, info);
+	class->free_message_info (folder, info);
 }
 
 static void
 ref_message_info (CamelFolder *folder, CamelMessageInfo *info)
 {
-	g_return_if_fail(folder->summary != NULL);
+	g_return_if_fail (folder->summary != NULL);
 
-	camel_message_info_ref(info);
+	camel_message_info_ref (info);
 }
 
 /**
@@ -1049,12 +1180,18 @@ ref_message_info (CamelFolder *folder, CamelMessageInfo *info)
  * #camel_folder_get_message_info.
  **/
 void
-camel_folder_ref_message_info(CamelFolder *folder, CamelMessageInfo *info)
+camel_folder_ref_message_info (CamelFolder *folder,
+                               CamelMessageInfo *info)
 {
-	g_return_if_fail(CAMEL_IS_FOLDER (folder));
-	g_return_if_fail(info != NULL);
+	CamelFolderClass *class;
 
-	CF_CLASS (folder)->ref_message_info(folder, info);
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (info != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->ref_message_info != NULL);
+
+	class->ref_message_info (folder, info);
 }
 
 /* TODO: is this function required anyway? */
@@ -1079,8 +1216,8 @@ camel_folder_has_summary_capability (CamelFolder *folder)
 static CamelMimeMessage *
 get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 {
-	w(g_warning ("CamelFolder::get_message not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+	w (g_warning ("CamelFolder::get_message not implemented for '%s'",
+		     G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 
 	return NULL;
 }
@@ -1102,16 +1239,16 @@ camel_folder_get_message (CamelFolder *folder, const gchar *uid, CamelException
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 
-	CAMEL_FOLDER_REC_LOCK(folder, lock);
+	CAMEL_FOLDER_REC_LOCK (folder, lock);
 
-	ret = CF_CLASS (folder)->get_message (folder, uid, ex);
+	ret = CAMEL_FOLDER_GET_CLASS (folder)->get_message (folder, uid, ex);
 
-	CAMEL_FOLDER_REC_UNLOCK(folder, lock);
+	CAMEL_FOLDER_REC_UNLOCK (folder, lock);
 
-	if (ret && camel_debug_start(":folder")) {
-		printf("CamelFolder:get_message('%s', '%s') =\n", folder->full_name, uid);
-		camel_mime_message_dump(ret, FALSE);
-		camel_debug_end();
+	if (ret && camel_debug_start (":folder")) {
+		printf ("CamelFolder:get_message ('%s', '%s') =\n", folder->full_name, uid);
+		camel_mime_message_dump (ret, FALSE);
+		camel_debug_end ();
 	}
 
 	return ret;
@@ -1129,27 +1266,35 @@ camel_folder_get_message (CamelFolder *folder, const gchar *uid, CamelException
  * Returns: void.
  **/
 void
-camel_folder_sync_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
+camel_folder_sync_message (CamelFolder *folder,
+                           const gchar *uid,
+                           CamelException *ex)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
-	CAMEL_FOLDER_REC_LOCK(folder, lock);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+
+	CAMEL_FOLDER_REC_LOCK (folder, lock);
 
 	/* Use the sync_message method if the class implements it. */
-	if (CF_CLASS (folder)->sync_message)
-		CF_CLASS (folder)->sync_message (folder, uid, ex);
+	if (class->sync_message != NULL)
+		class->sync_message (folder, uid, ex);
 	else {
 		CamelMimeMessage *message;
-		message = CF_CLASS (folder)->get_message (folder, uid, ex);
-		if (message)
-			  camel_object_unref(message);
+		message = class->get_message (folder, uid, ex);
+		if (message != NULL)
+			  g_object_unref (message);
 	}
-	CAMEL_FOLDER_REC_UNLOCK(folder, lock);
+
+	CAMEL_FOLDER_REC_UNLOCK (folder, lock);
 }
 
 static GPtrArray *
-get_uids(CamelFolder *folder)
+get_uids (CamelFolder *folder)
 {
-	g_return_val_if_fail(folder->summary != NULL, g_ptr_array_new ());
+	g_return_val_if_fail (folder->summary != NULL, g_ptr_array_new ());
 
 	return camel_folder_summary_array (folder->summary);
 }
@@ -1169,13 +1314,14 @@ get_uids(CamelFolder *folder)
 GPtrArray *
 camel_folder_get_uids (CamelFolder *folder)
 {
-	GPtrArray *ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 
-	ret = CF_CLASS (folder)->get_uids (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_uids != NULL, NULL);
 
-	return ret;
+	return class->get_uids (folder);
 }
 
 static void
@@ -1184,8 +1330,8 @@ free_uids (CamelFolder *folder, GPtrArray *array)
 	gint i;
 
 	for (i=0; i<array->len; i++)
-		camel_pstring_free(array->pdata[i]);
-	g_ptr_array_free(array, TRUE);
+		camel_pstring_free (array->pdata[i]);
+	g_ptr_array_free (array, TRUE);
 }
 
 /**
@@ -1196,11 +1342,18 @@ free_uids (CamelFolder *folder, GPtrArray *array)
  * Frees the array of UIDs returned by #camel_folder_get_uids.
  **/
 void
-camel_folder_free_uids (CamelFolder *folder, GPtrArray *array)
+camel_folder_free_uids (CamelFolder *folder,
+                        GPtrArray *array)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (array != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->free_uids != NULL);
 
-	CF_CLASS (folder)->free_uids (folder, array);
+	class->free_uids (folder, array);
 }
 
 /**
@@ -1212,11 +1365,11 @@ get_uncached_uids (CamelFolder *folder, GPtrArray * uids, CamelException *ex)
 	GPtrArray *result;
 	gint i;
 
-	result = g_ptr_array_new();
+	result = g_ptr_array_new ();
 
-	g_ptr_array_set_size(result, uids->len);
+	g_ptr_array_set_size (result, uids->len);
 	for (i = 0; i < uids->len; i++)
-	    result->pdata[i] = (gchar *)camel_pstring_strdup(uids->pdata[i]);
+	    result->pdata[i] = (gchar *)camel_pstring_strdup (uids->pdata[i]);
 	return result;
 }
 
@@ -1231,10 +1384,19 @@ get_uncached_uids (CamelFolder *folder, GPtrArray * uids, CamelException *ex)
  * Frees the array of UIDs returned by #camel_folder_get_uids.
  **/
 GPtrArray *
-camel_folder_get_uncached_uids (CamelFolder *folder, GPtrArray * uids, CamelException *ex)
+camel_folder_get_uncached_uids (CamelFolder *folder,
+                                GPtrArray *uids,
+                                CamelException *ex)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
-	return CF_CLASS (folder)->get_uncached_uids(folder, uids, ex);
+	g_return_val_if_fail (uids != NULL, NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_uncached_uids != NULL, NULL);
+
+	return class->get_uncached_uids (folder, uids, ex);
 }
 
 static gint
@@ -1258,13 +1420,20 @@ cmp_uids (CamelFolder *folder, const gchar *uid1, const gchar *uid2)
  * thus if provider uses different uid values, then it should subclass this function.
  **/
 gint
-camel_folder_cmp_uids (CamelFolder *folder, const gchar *uid1, const gchar *uid2)
+camel_folder_cmp_uids (CamelFolder *folder,
+                       const gchar *uid1,
+                       const gchar *uid2)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), 0);
 	g_return_val_if_fail (uid1 != NULL, 0);
 	g_return_val_if_fail (uid2 != NULL, 0);
 
-	return CF_CLASS (folder)->cmp_uids (folder, uid1, uid2);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->cmp_uids != NULL, 0);
+
+	return class->cmp_uids (folder, uid1, uid2);
 }
 
 static gint
@@ -1293,19 +1462,26 @@ sort_uids (CamelFolder *folder, GPtrArray *uids)
  * Sorts the array of UIDs.
  **/
 void
-camel_folder_sort_uids (CamelFolder *folder, GPtrArray *uids)
+camel_folder_sort_uids (CamelFolder *folder,
+                        GPtrArray *uids)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (uids != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->sort_uids != NULL);
 
-	CF_CLASS (folder)->sort_uids (folder, uids);
+	class->sort_uids (folder, uids);
 }
 
 static GPtrArray *
-get_summary(CamelFolder *folder)
+get_summary (CamelFolder *folder)
 {
-	g_assert(folder->summary != NULL);
+	g_assert (folder->summary != NULL);
 
-	return camel_folder_summary_array(folder->summary);
+	return camel_folder_summary_array (folder->summary);
 }
 
 /**
@@ -1321,17 +1497,18 @@ get_summary(CamelFolder *folder)
 GPtrArray *
 camel_folder_get_summary (CamelFolder *folder)
 {
-	GPtrArray *ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 
-	ret = CF_CLASS (folder)->get_summary (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_summary != NULL, NULL);
 
-	return ret;
+	return class->get_summary (folder);
 }
 
 static void
-free_summary(CamelFolder *folder, GPtrArray *summary)
+free_summary (CamelFolder *folder, GPtrArray *summary)
 {
 	g_ptr_array_foreach (summary, (GFunc) camel_pstring_free, NULL);
 	g_ptr_array_free (summary, TRUE);
@@ -1345,9 +1522,18 @@ free_summary(CamelFolder *folder, GPtrArray *summary)
  * Frees the summary array returned by #camel_folder_get_summary.
  **/
 void
-camel_folder_free_summary(CamelFolder *folder, GPtrArray *array)
+camel_folder_free_summary (CamelFolder *folder,
+                           GPtrArray *array)
 {
-	CF_CLASS(folder)->free_summary(folder, array);
+	CamelFolderClass *class;
+
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (array != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->free_summary != NULL);
+
+	class->free_summary (folder, array);
 }
 
 /**
@@ -1372,10 +1558,10 @@ search_by_expression (CamelFolder *folder, const gchar *expression,
 {
 	camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
 			      _("Unsupported operation: search by expression: for %s"),
-			      camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder)));
+			      G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder)));
 
-	w(g_warning ("CamelFolder::search_by_expression not implemented for "
-		     "'%s'", camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+	w (g_warning ("CamelFolder::search_by_expression not implemented for "
+		     "'%s'", G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 
 	return NULL;
 }
@@ -1392,19 +1578,21 @@ search_by_expression (CamelFolder *folder, const gchar *expression,
  * free the list and each of the elements when it is done.
  **/
 GPtrArray *
-camel_folder_search_by_expression (CamelFolder *folder, const gchar *expression,
-				   CamelException *ex)
+camel_folder_search_by_expression (CamelFolder *folder,
+                                   const gchar *expression,
+                                   CamelException *ex)
 {
-	GPtrArray *ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 	g_return_val_if_fail (folder->folder_flags & CAMEL_FOLDER_HAS_SEARCH_CAPABILITY, NULL);
 
-	/* NOTE: that it is upto the callee to lock */
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->search_by_expression != NULL, NULL);
 
-	ret = CF_CLASS (folder)->search_by_expression (folder, expression, ex);
+	/* NOTE: that it is upto the callee to lock */
 
-	return ret;
+	return class->search_by_expression (folder, expression, ex);
 }
 
 static guint32
@@ -1413,10 +1601,10 @@ count_by_expression (CamelFolder *folder, const gchar *expression,
 {
 	camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
 			      _("Unsupported operation: count by expression: for %s"),
-			      camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder)));
+			      G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder)));
 
-	w(g_warning ("CamelFolder::count_by_expression not implemented for "
-		     "'%s'", camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+	w (g_warning ("CamelFolder::count_by_expression not implemented for "
+		     "'%s'", G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 
 	return 0;
 }
@@ -1432,30 +1620,32 @@ count_by_expression (CamelFolder *folder, const gchar *expression,
  * Returns: an interger
  **/
 guint32
-camel_folder_count_by_expression (CamelFolder *folder, const gchar *expression,
-				   CamelException *ex)
+camel_folder_count_by_expression (CamelFolder *folder,
+                                  const gchar *expression,
+                                  CamelException *ex)
 {
-	guint32 ret;
+	CamelFolderClass *class;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), 0);
 	g_return_val_if_fail (folder->folder_flags & CAMEL_FOLDER_HAS_SEARCH_CAPABILITY, 0);
 
-	/* NOTE: that it is upto the callee to lock */
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->count_by_expression != NULL, 0);
 
-	ret = CF_CLASS (folder)->count_by_expression (folder, expression, ex);
+	/* NOTE: that it is upto the callee to lock */
 
-	return ret;
+	return class->count_by_expression (folder, expression, ex);
 }
 
 static GPtrArray *
-search_by_uids(CamelFolder *folder, const gchar *exp, GPtrArray *uids, CamelException *ex)
+search_by_uids (CamelFolder *folder, const gchar *exp, GPtrArray *uids, CamelException *ex)
 {
 	camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
 			      _("Unsupported operation: search by UIDs: for %s"),
-			      camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder)));
+			      G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder)));
 
-	w(g_warning ("CamelFolder::search_by_expression not implemented for "
-		     "'%s'", camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+	w (g_warning ("CamelFolder::search_by_expression not implemented for "
+		     "'%s'", G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 
 	return NULL;
 }
@@ -1473,18 +1663,22 @@ search_by_uids(CamelFolder *folder, const gchar *exp, GPtrArray *uids, CamelExce
  * free the list and each of the elements when it is done.
  **/
 GPtrArray *
-camel_folder_search_by_uids(CamelFolder *folder, const gchar *expr, GPtrArray *uids, CamelException *ex)
+camel_folder_search_by_uids (CamelFolder *folder,
+                             const gchar *expr,
+                             GPtrArray *uids,
+                             CamelException *ex)
 {
-	GPtrArray *ret;
+	CamelFolderClass *class;
 
-	g_return_val_if_fail(CAMEL_IS_FOLDER (folder), NULL);
-	g_return_val_if_fail(folder->folder_flags & CAMEL_FOLDER_HAS_SEARCH_CAPABILITY, NULL);
+	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+	g_return_val_if_fail (folder->folder_flags & CAMEL_FOLDER_HAS_SEARCH_CAPABILITY, NULL);
 
-	/* NOTE: that it is upto the callee to lock */
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->search_by_uids != NULL, NULL);
 
-	ret = CF_CLASS(folder)->search_by_uids(folder, expr, uids, ex);
+	/* NOTE: that it is upto the callee to lock */
 
-	return ret;
+	return class->search_by_uids (folder, expr, uids, ex);
 }
 
 static void
@@ -1506,12 +1700,20 @@ search_free (CamelFolder *folder, GPtrArray *result)
  * #camel_folder_search_by_uids.
  **/
 void
-camel_folder_search_free (CamelFolder *folder, GPtrArray *result)
+camel_folder_search_free (CamelFolder *folder,
+                          GPtrArray *result)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (result != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->search_free != NULL);
 
 	/* NOTE: upto the callee to lock */
-	CF_CLASS (folder)->search_free (folder, result);
+
+	class->search_free (folder, result);
 }
 
 static void
@@ -1524,23 +1726,27 @@ transfer_message_to (CamelFolder *source, const gchar *uid, CamelFolder *dest,
 
 	/* Default implementation. */
 
-	msg = camel_folder_get_message(source, uid, ex);
+	msg = camel_folder_get_message (source, uid, ex);
 	if (!msg)
 		return;
 
 	/* if its deleted we poke the flags, so we need to copy the messageinfo */
 	if ((source->folder_flags & CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY)
-			&& (minfo = camel_folder_get_message_info(source, uid))) {
-		info = camel_message_info_clone(minfo);
-		camel_folder_free_message_info(source, minfo);
-	} else
-		info = camel_message_info_new_from_header(NULL, ((CamelMimePart *)msg)->headers);
+			&& (minfo = camel_folder_get_message_info (source, uid))) {
+		info = camel_message_info_clone (minfo);
+		camel_folder_free_message_info (source, minfo);
+	} else {
+		struct _camel_header_raw *headers;
+
+		headers = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (msg));
+		info = camel_message_info_new_from_header (NULL, headers);
+	}
 
 	/* we don't want to retain the deleted flag */
-	camel_message_info_set_flags(info, CAMEL_MESSAGE_DELETED, 0);
+	camel_message_info_set_flags (info, CAMEL_MESSAGE_DELETED, 0);
 
 	camel_folder_append_message (dest, msg, info, transferred_uid, ex);
-	camel_object_unref (msg);
+	g_object_unref (msg);
 
 	if (delete_original && !camel_exception_is_set (ex))
 		camel_folder_set_message_flags (source, uid, CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_SEEN, ~0);
@@ -1560,31 +1766,31 @@ transfer_messages_to (CamelFolder *source, GPtrArray *uids, CamelFolder *dest, G
 		g_ptr_array_set_size (*transferred_uids, uids->len);
 	}
 
-	camel_exception_init(&local);
+	camel_exception_init (&local);
 	if (ex == NULL)
 		ex = &local;
 
-	camel_operation_start(NULL, delete_originals ? _("Moving messages") : _("Copying messages"));
+	camel_operation_start (NULL, delete_originals ? _("Moving messages") : _("Copying messages"));
 
 	if (uids->len > 1) {
-		camel_folder_freeze(dest);
+		camel_folder_freeze (dest);
 		if (delete_originals)
-			camel_folder_freeze(source);
+			camel_folder_freeze (source);
 	}
 	for (i = 0; i < uids->len && !camel_exception_is_set (ex); i++) {
 		if (transferred_uids)
 			ret_uid = (gchar **)&((*transferred_uids)->pdata[i]);
 		transfer_message_to (source, uids->pdata[i], dest, ret_uid, delete_originals, ex);
-		camel_operation_progress(NULL, i * 100 / uids->len);
+		camel_operation_progress (NULL, i * 100 / uids->len);
 	}
 	if (uids->len > 1) {
-		camel_folder_thaw(dest);
+		camel_folder_thaw (dest);
 		if (delete_originals)
-			camel_folder_thaw(source);
+			camel_folder_thaw (source);
 	}
 
-	camel_operation_end(NULL);
-	camel_exception_clear(&local);
+	camel_operation_end (NULL);
+	camel_exception_clear (&local);
 }
 
 /**
@@ -1602,13 +1808,18 @@ transfer_messages_to (CamelFolder *source, GPtrArray *uids, CamelFolder *dest, G
  * more efficient than using #camel_folder_append_message.
  **/
 void
-camel_folder_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
-				   CamelFolder *dest, GPtrArray **transferred_uids,
-				   gboolean delete_originals, CamelException *ex)
+camel_folder_transfer_messages_to (CamelFolder *source,
+                                   GPtrArray *uids,
+                                   CamelFolder *dest,
+                                   GPtrArray **transferred_uids,
+                                   gboolean delete_originals,
+                                   CamelException *ex)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (source));
-	g_return_if_fail (CAMEL_IS_FOLDER (dest));
 	g_return_if_fail (uids != NULL);
+	g_return_if_fail (CAMEL_IS_FOLDER (dest));
 
 	if (source == dest || uids->len == 0) {
 		/* source and destination folders are the same, or no work to do, do nothing. */
@@ -1620,11 +1831,16 @@ camel_folder_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 		 * vtrash transfer method.
 		 */
 		if (CAMEL_IS_VTRASH_FOLDER (dest))
-			CF_CLASS (dest)->transfer_messages_to (source, uids, dest, transferred_uids, delete_originals, ex);
+			class = CAMEL_FOLDER_GET_CLASS (dest);
 		else
-			CF_CLASS (source)->transfer_messages_to (source, uids, dest, transferred_uids, delete_originals, ex);
+			class = CAMEL_FOLDER_GET_CLASS (source);
+		class->transfer_messages_to (
+			source, uids, dest, transferred_uids,
+			delete_originals, ex);
 	} else
-		transfer_messages_to (source, uids, dest, transferred_uids, delete_originals, ex);
+		transfer_messages_to (
+			source, uids, dest, transferred_uids,
+			delete_originals, ex);
 }
 
 static void
@@ -1643,8 +1859,13 @@ delete (CamelFolder *folder)
 void
 camel_folder_delete (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->delete != NULL);
+
 	CAMEL_FOLDER_REC_LOCK (folder, lock);
 	if (folder->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED) {
 		CAMEL_FOLDER_REC_UNLOCK (folder, lock);
@@ -1653,7 +1874,7 @@ camel_folder_delete (CamelFolder *folder)
 
 	folder->folder_flags |= CAMEL_FOLDER_HAS_BEEN_DELETED;
 
-	CF_CLASS (folder)->delete (folder);
+	class->delete (folder);
 
 	CAMEL_FOLDER_REC_UNLOCK (folder, lock);
 
@@ -1668,13 +1889,13 @@ folder_rename (CamelFolder *folder, const gchar *new)
 {
 	gchar *tmp;
 
-	d(printf("CamelFolder:rename('%s')\n", new));
+	d (printf ("CamelFolder:rename ('%s')\n", new));
 
-	g_free(folder->full_name);
-	folder->full_name = g_strdup(new);
-	g_free(folder->name);
-	tmp = strrchr(new, '/');
-	folder->name = g_strdup(tmp?tmp+1:new);
+	g_free (folder->full_name);
+	folder->full_name = g_strdup (new);
+	g_free (folder->name);
+	tmp = strrchr (new, '/');
+	folder->name = g_strdup (tmp?tmp+1:new);
 }
 
 /**
@@ -1688,29 +1909,38 @@ folder_rename (CamelFolder *folder, const gchar *new)
  * is performed on the folder.
  **/
 void
-camel_folder_rename(CamelFolder *folder, const gchar *new)
+camel_folder_rename (CamelFolder *folder,
+                     const gchar *new)
 {
+	CamelFolderClass *class;
 	gchar *old;
 
-	old = g_strdup(folder->full_name);
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (new != NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->rename != NULL);
 
-	CF_CLASS (folder)->rename(folder, new);
+	old = g_strdup (folder->full_name);
+
+	class->rename (folder, new);
 	camel_db_rename_folder (folder->parent_store->cdb_w, old, new, NULL);
 	camel_object_trigger_event (folder, "renamed", old);
-	g_free(old);
+
+	g_free (old);
 }
 
 static void
 freeze (CamelFolder *folder)
 {
-	CAMEL_FOLDER_LOCK(folder, change_lock);
+	CAMEL_FOLDER_LOCK (folder, change_lock);
 
-	g_assert(folder->priv->frozen >= 0);
+	g_assert (folder->priv->frozen >= 0);
 
 	folder->priv->frozen++;
 
-	d(printf ("freeze(%p '%s') = %d\n", folder, folder->full_name, folder->priv->frozen));
-	CAMEL_FOLDER_UNLOCK(folder, change_lock);
+	d (printf ("freeze (%p '%s') = %d\n", folder, folder->full_name, folder->priv->frozen));
+	CAMEL_FOLDER_UNLOCK (folder, change_lock);
 }
 
 /**
@@ -1725,9 +1955,14 @@ freeze (CamelFolder *folder)
 void
 camel_folder_freeze (CamelFolder * folder)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
-	CF_CLASS (folder)->freeze (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->freeze != NULL);
+
+	class->freeze (folder);
 }
 
 static void
@@ -1735,25 +1970,25 @@ thaw (CamelFolder * folder)
 {
 	CamelFolderChangeInfo *info = NULL;
 
-	CAMEL_FOLDER_LOCK(folder, change_lock);
+	CAMEL_FOLDER_LOCK (folder, change_lock);
 
-	g_assert(folder->priv->frozen > 0);
+	g_assert (folder->priv->frozen > 0);
 
 	folder->priv->frozen--;
 
-	d(printf ("thaw(%p '%s') = %d\n", folder, folder->full_name, folder->priv->frozen));
+	d (printf ("thaw (%p '%s') = %d\n", folder, folder->full_name, folder->priv->frozen));
 
 	if (folder->priv->frozen == 0
-	    && camel_folder_change_info_changed(folder->priv->changed_frozen)) {
+	    && camel_folder_change_info_changed (folder->priv->changed_frozen)) {
 		info = folder->priv->changed_frozen;
-		folder->priv->changed_frozen = camel_folder_change_info_new();
+		folder->priv->changed_frozen = camel_folder_change_info_new ();
 	}
 
-	CAMEL_FOLDER_UNLOCK(folder, change_lock);
+	CAMEL_FOLDER_UNLOCK (folder, change_lock);
 
 	if (info) {
 		camel_object_trigger_event (folder, "folder_changed", info);
-		camel_folder_change_info_free(info);
+		camel_folder_change_info_free (info);
 	}
 }
 
@@ -1767,10 +2002,15 @@ thaw (CamelFolder * folder)
 void
 camel_folder_thaw (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 	g_return_if_fail (folder->priv->frozen != 0);
 
-	CF_CLASS (folder)->thaw (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->thaw != NULL);
+
+	class->thaw (folder);
 }
 
 static gboolean
@@ -1788,9 +2028,14 @@ is_frozen (CamelFolder *folder)
 gboolean
 camel_folder_is_frozen (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
 
-	return CF_CLASS (folder)->is_frozen (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->is_frozen != NULL, FALSE);
+
+	return class->is_frozen (folder);
 }
 
 static CamelFolderQuotaInfo *
@@ -1803,14 +2048,19 @@ get_quota_info (CamelFolder *folder)
  * camel_folder_get_quota_info:
  * @folder: a #CamelFolder object
  *
- * Returns: list of known quota(s) for the folder.
+ * Returns: list of known quota (s) for the folder.
  **/
 CamelFolderQuotaInfo *
 camel_folder_get_quota_info (CamelFolder *folder)
 {
+	CamelFolderClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 
-	return CF_CLASS (folder)->get_quota_info (folder);
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_quota_info != NULL, NULL);
+
+	return class->get_quota_info (folder);
 }
 
 /**
@@ -1894,7 +2144,7 @@ struct _folder_filter_msg {
 };
 
 static void
-filter_filter(CamelSession *session, CamelSessionThreadMsg *tmsg)
+filter_filter (CamelSession *session, CamelSessionThreadMsg *tmsg)
 {
 	struct _folder_filter_msg *m = (struct _folder_filter_msg *) tmsg;
 	CamelMessageInfo *info;
@@ -1908,14 +2158,14 @@ filter_filter(CamelSession *session, CamelSessionThreadMsg *tmsg)
 		camel_operation_start (NULL, _("Learning junk"));
 
 		for (i = 0; i < m->junk->len; i ++) {
-			CamelMimeMessage *msg = camel_folder_get_message(m->folder, m->junk->pdata[i], NULL);
+			CamelMimeMessage *msg = camel_folder_get_message (m->folder, m->junk->pdata[i], NULL);
 			gint pc = 100 * i / m->junk->len;
 
-			camel_operation_progress(NULL, pc);
+			camel_operation_progress (NULL, pc);
 
 			if (msg) {
 				camel_junk_plugin_report_junk (csp, msg);
-				camel_object_unref (msg);
+				g_object_unref (msg);
 			}
 		}
 		camel_operation_end (NULL);
@@ -1924,14 +2174,14 @@ filter_filter(CamelSession *session, CamelSessionThreadMsg *tmsg)
 	if (m->notjunk) {
 		camel_operation_start (NULL, _("Learning non-junk"));
 		for (i = 0; i < m->notjunk->len; i ++) {
-			CamelMimeMessage *msg = camel_folder_get_message(m->folder, m->notjunk->pdata[i], NULL);
+			CamelMimeMessage *msg = camel_folder_get_message (m->folder, m->notjunk->pdata[i], NULL);
 			gint pc = 100 * i / m->notjunk->len;
 
-			camel_operation_progress(NULL, pc);
+			camel_operation_progress (NULL, pc);
 
 			if (msg) {
 				camel_junk_plugin_report_notjunk (csp, msg);
-				camel_object_unref (msg);
+				g_object_unref (msg);
 			}
 		}
 		camel_operation_end (NULL);
@@ -1941,66 +2191,66 @@ filter_filter(CamelSession *session, CamelSessionThreadMsg *tmsg)
 		camel_junk_plugin_commit_reports (csp);
 
 	if (m->driver && m->recents) {
-		camel_operation_start(NULL, _("Filtering new message(s)"));
+		camel_operation_start (NULL, _("Filtering new message (s)"));
 
-		source_url = camel_service_get_url((CamelService *)m->folder->parent_store);
-		uri = camel_url_new(source_url, NULL);
-		g_free(source_url);
+		source_url = camel_service_get_url ((CamelService *)m->folder->parent_store);
+		uri = camel_url_new (source_url, NULL);
+		g_free (source_url);
 		if (m->folder->full_name && m->folder->full_name[0] != '/') {
-			gchar *tmp = alloca(strlen(m->folder->full_name)+2);
+			gchar *tmp = alloca (strlen (m->folder->full_name)+2);
 
-			sprintf(tmp, "/%s", m->folder->full_name);
-			camel_url_set_path(uri, tmp);
+			sprintf (tmp, "/%s", m->folder->full_name);
+			camel_url_set_path (uri, tmp);
 		} else
-			camel_url_set_path(uri, m->folder->full_name);
-		source_url = camel_url_to_string(uri, CAMEL_URL_HIDE_ALL);
-		camel_url_free(uri);
+			camel_url_set_path (uri, m->folder->full_name);
+		source_url = camel_url_to_string (uri, CAMEL_URL_HIDE_ALL);
+		camel_url_free (uri);
 
 		for (i=0;status == 0 && i<m->recents->len;i++) {
 			gchar *uid = m->recents->pdata[i];
 			gint pc = 100 * i / m->recents->len;
 
-			camel_operation_progress(NULL, pc);
+			camel_operation_progress (NULL, pc);
 
-			info = camel_folder_get_message_info(m->folder, uid);
+			info = camel_folder_get_message_info (m->folder, uid);
 			if (info == NULL) {
-				g_warning("uid %s vanished from folder: %s", uid, source_url);
+				g_warning ("uid %s vanished from folder: %s", uid, source_url);
 				continue;
 			}
 
-			status = camel_filter_driver_filter_message(m->driver, NULL, info, uid, m->folder, source_url, source_url, &m->ex);
+			status = camel_filter_driver_filter_message (m->driver, NULL, info, uid, m->folder, source_url, source_url, &m->ex);
 
-			camel_folder_free_message_info(m->folder, info);
+			camel_folder_free_message_info (m->folder, info);
 		}
 
-		camel_exception_init(&ex);
-		camel_filter_driver_flush(m->driver, &ex);
-		if (!camel_exception_is_set(&m->ex))
-			camel_exception_xfer(&m->ex, &ex);
+		camel_exception_init (&ex);
+		camel_filter_driver_flush (m->driver, &ex);
+		if (!camel_exception_is_set (&m->ex))
+			camel_exception_xfer (&m->ex, &ex);
 
-		g_free(source_url);
+		g_free (source_url);
 
-		camel_operation_end(NULL);
+		camel_operation_end (NULL);
 	}
 }
 
 static void
-filter_free(CamelSession *session, CamelSessionThreadMsg *msg)
+filter_free (CamelSession *session, CamelSessionThreadMsg *msg)
 {
 	struct _folder_filter_msg *m = (struct _folder_filter_msg *)msg;
 
 	if (m->driver)
-		camel_object_unref(m->driver);
+		g_object_unref (m->driver);
 	if (m->recents)
-		camel_folder_free_deep(m->folder, m->recents);
+		camel_folder_free_deep (m->folder, m->recents);
 	if (m->junk)
-		camel_folder_free_deep(m->folder, m->junk);
+		camel_folder_free_deep (m->folder, m->junk);
 	if (m->notjunk)
-		camel_folder_free_deep(m->folder, m->notjunk);
+		camel_folder_free_deep (m->folder, m->notjunk);
 
 	camel_folder_summary_save_to_db (m->folder->summary, &m->ex);
-	camel_folder_thaw(m->folder);
-	camel_object_unref(m->folder);
+	camel_folder_thaw (m->folder);
+	g_object_unref (m->folder);
 }
 
 static CamelSessionThreadOps filter_ops = {
@@ -2029,26 +2279,26 @@ folder_changed (CamelObject *obj, gpointer event_data)
 	GPtrArray *recents = NULL;
 	gint i;
 
-	d(printf ("folder_changed(%p:'%s', %p), frozen=%d\n", obj, folder->full_name, event_data, folder->priv->frozen));
-	d(printf(" added %d removed %d changed %d recent %d filter %d\n",
+	d (printf ("folder_changed (%p:'%s', %p), frozen=%d\n", obj, folder->full_name, event_data, folder->priv->frozen));
+	d (printf (" added %d removed %d changed %d recent %d filter %d\n",
 		 changed->uid_added->len, changed->uid_removed->len,
 		 changed->uid_changed->len, changed->uid_recent->len,
 		 p->uid_filter->len));
 
 	if (changed == NULL) {
-		w(g_warning ("Class %s is passing NULL to folder_changed event",
-			     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (folder))));
+		w (g_warning ("Class %s is passing NULL to folder_changed event",
+			     G_OBJECT_CLASS_NAME (G_OBJECT_TYPE (folder))));
 		return TRUE;
 	}
 
-	CAMEL_FOLDER_LOCK(folder, change_lock);
+	CAMEL_FOLDER_LOCK (folder, change_lock);
 	if (folder->priv->frozen) {
-		camel_folder_change_info_cat(folder->priv->changed_frozen, changed);
-		CAMEL_FOLDER_UNLOCK(folder, change_lock);
+		camel_folder_change_info_cat (folder->priv->changed_frozen, changed);
+		CAMEL_FOLDER_UNLOCK (folder, change_lock);
 
 		return FALSE;
 	}
-	CAMEL_FOLDER_UNLOCK(folder, change_lock);
+	CAMEL_FOLDER_UNLOCK (folder, change_lock);
 
 	if (session->junk_plugin && changed->uid_changed->len) {
 		guint32 flags;
@@ -2058,11 +2308,11 @@ folder_changed (CamelObject *obj, gpointer event_data)
 			if (flags & CAMEL_MESSAGE_JUNK_LEARN) {
 				if (flags & CAMEL_MESSAGE_JUNK) {
 					if (!junk)
-						junk = g_ptr_array_new();
+						junk = g_ptr_array_new ();
 					g_ptr_array_add (junk, g_strdup (changed->uid_changed->pdata [i]));
 				} else {
 					if (!notjunk)
-						notjunk = g_ptr_array_new();
+						notjunk = g_ptr_array_new ();
 					g_ptr_array_add (notjunk, g_strdup (changed->uid_changed->pdata [i]));
 				}
 				/* reset junk learn flag so that we don't process it again*/
@@ -2073,12 +2323,12 @@ folder_changed (CamelObject *obj, gpointer event_data)
 
 	if ((folder->folder_flags & (CAMEL_FOLDER_FILTER_RECENT|CAMEL_FOLDER_FILTER_JUNK))
 	    && p->uid_filter->len > 0)
-		driver = camel_session_get_filter_driver(session,
+		driver = camel_session_get_filter_driver (session,
 							 (folder->folder_flags & CAMEL_FOLDER_FILTER_RECENT)
 							 ? "incoming":"junktest", NULL);
 
 	if (driver) {
-		recents = g_ptr_array_new();
+		recents = g_ptr_array_new ();
 		for (i = 0; i < p->uid_filter->len; i++)
 			g_ptr_array_add (recents, g_strdup (p->uid_filter->pdata[i]));
 
@@ -2088,24 +2338,24 @@ folder_changed (CamelObject *obj, gpointer event_data)
 	if (driver || junk || notjunk) {
 		struct _folder_filter_msg *msg;
 
-		d(printf("* launching filter thread %d new mail, %d junk and %d not junk\n",
+		d (printf ("* launching filter thread %d new mail, %d junk and %d not junk\n",
 			 recents?recents->len:0, junk?junk->len:0, notjunk?notjunk->len:0));
 
-		msg = camel_session_thread_msg_new(session, &filter_ops, sizeof(*msg));
+		msg = camel_session_thread_msg_new (session, &filter_ops, sizeof (*msg));
 		msg->recents = recents;
 		msg->junk = junk;
 		msg->notjunk = notjunk;
 		msg->folder = folder;
-		camel_object_ref(folder);
-		camel_folder_freeze(folder);
+		g_object_ref (folder);
+		camel_folder_freeze (folder);
 		/* Copy changes back to changed_frozen list to retain
 		 * them while we are filtering */
-		CAMEL_FOLDER_LOCK(folder, change_lock);
-		camel_folder_change_info_cat(folder->priv->changed_frozen, changed);
-		CAMEL_FOLDER_UNLOCK(folder, change_lock);
+		CAMEL_FOLDER_LOCK (folder, change_lock);
+		camel_folder_change_info_cat (folder->priv->changed_frozen, changed);
+		CAMEL_FOLDER_UNLOCK (folder, change_lock);
 		msg->driver = driver;
-		camel_exception_init(&msg->ex);
-		camel_session_thread_queue(session, &msg->msg, 0);
+		camel_exception_init (&msg->ex);
+		camel_session_thread_queue (session, &msg->msg, 0);
 		return FALSE;
 	}
 
@@ -2173,20 +2423,20 @@ camel_folder_free_deep (CamelFolder *folder, GPtrArray *array)
  * Returns: a new #CamelFolderChangeInfo
  **/
 CamelFolderChangeInfo *
-camel_folder_change_info_new(void)
+camel_folder_change_info_new (void)
 {
 	CamelFolderChangeInfo *info;
 
 	info = g_slice_new (CamelFolderChangeInfo);
-	info->uid_added = g_ptr_array_new();
-	info->uid_removed = g_ptr_array_new();
-	info->uid_changed = g_ptr_array_new();
-	info->uid_recent = g_ptr_array_new();
+	info->uid_added = g_ptr_array_new ();
+	info->uid_removed = g_ptr_array_new ();
+	info->uid_changed = g_ptr_array_new ();
+	info->uid_recent = g_ptr_array_new ();
 	info->priv = g_slice_new (struct _CamelFolderChangeInfoPrivate);
-	info->priv->uid_stored = g_hash_table_new(g_str_hash, g_str_equal);
+	info->priv->uid_stored = g_hash_table_new (g_str_hash, g_str_equal);
 	info->priv->uid_source = NULL;
-	info->priv->uid_filter = g_ptr_array_new();
-	info->priv->uid_pool = e_mempool_new(512, 256, E_MEMPOOL_ALIGN_BYTE);
+	info->priv->uid_filter = g_ptr_array_new ();
+	info->priv->uid_pool = e_mempool_new (512, 256, E_MEMPOOL_ALIGN_BYTE);
 
 	return info;
 }
@@ -2199,19 +2449,19 @@ camel_folder_change_info_new(void)
  * Add a source uid for generating a changeset.
  **/
 void
-camel_folder_change_info_add_source(CamelFolderChangeInfo *info, const gchar *uid)
+camel_folder_change_info_add_source (CamelFolderChangeInfo *info, const gchar *uid)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
 	if (p->uid_source == NULL)
-		p->uid_source = g_hash_table_new(g_str_hash, g_str_equal);
+		p->uid_source = g_hash_table_new (g_str_hash, g_str_equal);
 
-	if (g_hash_table_lookup(p->uid_source, uid) == NULL)
-		g_hash_table_insert(p->uid_source, e_mempool_strdup(p->uid_pool, uid), GINT_TO_POINTER (1));
+	if (g_hash_table_lookup (p->uid_source, uid) == NULL)
+		g_hash_table_insert (p->uid_source, e_mempool_strdup (p->uid_pool, uid), GINT_TO_POINTER (1));
 }
 
 /**
@@ -2222,24 +2472,24 @@ camel_folder_change_info_add_source(CamelFolderChangeInfo *info, const gchar *ui
  * Add a list of source uid's for generating a changeset.
  **/
 void
-camel_folder_change_info_add_source_list(CamelFolderChangeInfo *info, const GPtrArray *list)
+camel_folder_change_info_add_source_list (CamelFolderChangeInfo *info, const GPtrArray *list)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 	gint i;
 
-	g_assert(info != NULL);
-	g_assert(list != NULL);
+	g_assert (info != NULL);
+	g_assert (list != NULL);
 
 	p = info->priv;
 
 	if (p->uid_source == NULL)
-		p->uid_source = g_hash_table_new(g_str_hash, g_str_equal);
+		p->uid_source = g_hash_table_new (g_str_hash, g_str_equal);
 
 	for (i=0;i<list->len;i++) {
 		gchar *uid = list->pdata[i];
 
-		if (g_hash_table_lookup(p->uid_source, uid) == NULL)
-			g_hash_table_insert(p->uid_source, e_mempool_strdup(p->uid_pool, uid), GINT_TO_POINTER (1));
+		if (g_hash_table_lookup (p->uid_source, uid) == NULL)
+			g_hash_table_insert (p->uid_source, e_mempool_strdup (p->uid_pool, uid), GINT_TO_POINTER (1));
 	}
 }
 
@@ -2251,25 +2501,25 @@ camel_folder_change_info_add_source_list(CamelFolderChangeInfo *info, const GPtr
  * Add a uid from the updated list, used to generate a changeset diff.
  **/
 void
-camel_folder_change_info_add_update(CamelFolderChangeInfo *info, const gchar *uid)
+camel_folder_change_info_add_update (CamelFolderChangeInfo *info, const gchar *uid)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 	gchar *key;
 	gint value;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
 	if (p->uid_source == NULL) {
-		camel_folder_change_info_add_uid(info, uid);
+		camel_folder_change_info_add_uid (info, uid);
 		return;
 	}
 
-	if (g_hash_table_lookup_extended(p->uid_source, uid, (gpointer) &key, (gpointer) &value)) {
-		g_hash_table_remove(p->uid_source, key);
+	if (g_hash_table_lookup_extended (p->uid_source, uid, (gpointer) &key, (gpointer) &value)) {
+		g_hash_table_remove (p->uid_source, key);
 	} else {
-		camel_folder_change_info_add_uid(info, uid);
+		camel_folder_change_info_add_uid (info, uid);
 	}
 }
 
@@ -2281,37 +2531,37 @@ camel_folder_change_info_add_update(CamelFolderChangeInfo *info, const gchar *ui
  * Add a list of uid's from the updated list.
  **/
 void
-camel_folder_change_info_add_update_list(CamelFolderChangeInfo *info, const GPtrArray *list)
+camel_folder_change_info_add_update_list (CamelFolderChangeInfo *info, const GPtrArray *list)
 {
 	gint i;
 
-	g_assert(info != NULL);
-	g_assert(list != NULL);
+	g_assert (info != NULL);
+	g_assert (list != NULL);
 
 	for (i=0;i<list->len;i++)
-		camel_folder_change_info_add_update(info, list->pdata[i]);
+		camel_folder_change_info_add_update (info, list->pdata[i]);
 }
 
 static void
-change_info_remove(gchar *key, gpointer value, CamelFolderChangeInfo *info)
+change_info_remove (gchar *key, gpointer value, CamelFolderChangeInfo *info)
 {
 	struct _CamelFolderChangeInfoPrivate *p = info->priv;
 	GPtrArray *olduids;
 	gchar *olduid;
 
-	if (g_hash_table_lookup_extended(p->uid_stored, key, (gpointer) &olduid, (gpointer) &olduids)) {
+	if (g_hash_table_lookup_extended (p->uid_stored, key, (gpointer) &olduid, (gpointer) &olduids)) {
 		/* if it was added/changed them removed, then remove it */
 		if (olduids != info->uid_removed) {
-			g_ptr_array_remove_fast(olduids, olduid);
-			g_ptr_array_add(info->uid_removed, olduid);
-			g_hash_table_insert(p->uid_stored, olduid, info->uid_removed);
+			g_ptr_array_remove_fast (olduids, olduid);
+			g_ptr_array_add (info->uid_removed, olduid);
+			g_hash_table_insert (p->uid_stored, olduid, info->uid_removed);
 		}
 		return;
 	}
 
 	/* we dont need to copy this, as they've already been copied into our pool */
-	g_ptr_array_add(info->uid_removed, key);
-	g_hash_table_insert(p->uid_stored, key, info->uid_removed);
+	g_ptr_array_add (info->uid_removed, key);
+	g_hash_table_insert (p->uid_stored, key, info->uid_removed);
 }
 
 /**
@@ -2322,23 +2572,23 @@ change_info_remove(gchar *key, gpointer value, CamelFolderChangeInfo *info)
  * differences into the added and removed lists.
  **/
 void
-camel_folder_change_info_build_diff(CamelFolderChangeInfo *info)
+camel_folder_change_info_build_diff (CamelFolderChangeInfo *info)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
 	if (p->uid_source) {
-		g_hash_table_foreach(p->uid_source, (GHFunc)change_info_remove, info);
-		g_hash_table_destroy(p->uid_source);
+		g_hash_table_foreach (p->uid_source, (GHFunc)change_info_remove, info);
+		g_hash_table_destroy (p->uid_source);
 		p->uid_source = NULL;
 	}
 }
 
 static void
-change_info_recent_uid(CamelFolderChangeInfo *info, const gchar *uid)
+change_info_recent_uid (CamelFolderChangeInfo *info, const gchar *uid)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 	GPtrArray *olduids;
@@ -2347,14 +2597,14 @@ change_info_recent_uid(CamelFolderChangeInfo *info, const gchar *uid)
 	p = info->priv;
 
 	/* always add to recent, but dont let anyone else know */
-	if (!g_hash_table_lookup_extended(p->uid_stored, uid, (gpointer *)&olduid, (gpointer *)&olduids)) {
-		olduid = e_mempool_strdup(p->uid_pool, uid);
+	if (!g_hash_table_lookup_extended (p->uid_stored, uid, (gpointer *)&olduid, (gpointer *)&olduids)) {
+		olduid = e_mempool_strdup (p->uid_pool, uid);
 	}
-	g_ptr_array_add(info->uid_recent, olduid);
+	g_ptr_array_add (info->uid_recent, olduid);
 }
 
 static void
-change_info_filter_uid(CamelFolderChangeInfo *info, const gchar *uid)
+change_info_filter_uid (CamelFolderChangeInfo *info, const gchar *uid)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 	GPtrArray *olduids;
@@ -2363,19 +2613,19 @@ change_info_filter_uid(CamelFolderChangeInfo *info, const gchar *uid)
 	p = info->priv;
 
 	/* always add to filter, but dont let anyone else know */
-	if (!g_hash_table_lookup_extended(p->uid_stored, uid, (gpointer *)&olduid, (gpointer *)&olduids)) {
-		olduid = e_mempool_strdup(p->uid_pool, uid);
+	if (!g_hash_table_lookup_extended (p->uid_stored, uid, (gpointer *)&olduid, (gpointer *)&olduids)) {
+		olduid = e_mempool_strdup (p->uid_pool, uid);
 	}
-	g_ptr_array_add(p->uid_filter, olduid);
+	g_ptr_array_add (p->uid_filter, olduid);
 }
 
 static void
-change_info_cat(CamelFolderChangeInfo *info, GPtrArray *source, void (*add)(CamelFolderChangeInfo *info, const gchar *uid))
+change_info_cat (CamelFolderChangeInfo *info, GPtrArray *source, void (*add)(CamelFolderChangeInfo *info, const gchar *uid))
 {
 	gint i;
 
 	for (i=0;i<source->len;i++)
-		add(info, source->pdata[i]);
+		add (info, source->pdata[i]);
 }
 
 /**
@@ -2387,16 +2637,16 @@ change_info_cat(CamelFolderChangeInfo *info, GPtrArray *source, void (*add)(Came
  * too.
  **/
 void
-camel_folder_change_info_cat(CamelFolderChangeInfo *info, CamelFolderChangeInfo *source)
+camel_folder_change_info_cat (CamelFolderChangeInfo *info, CamelFolderChangeInfo *source)
 {
-	g_assert(info != NULL);
-	g_assert(source != NULL);
+	g_assert (info != NULL);
+	g_assert (source != NULL);
 
-	change_info_cat(info, source->uid_added, camel_folder_change_info_add_uid);
-	change_info_cat(info, source->uid_removed, camel_folder_change_info_remove_uid);
-	change_info_cat(info, source->uid_changed, camel_folder_change_info_change_uid);
-	change_info_cat(info, source->uid_recent, change_info_recent_uid);
-	change_info_cat(info, source->priv->uid_filter, change_info_filter_uid);
+	change_info_cat (info, source->uid_added, camel_folder_change_info_add_uid);
+	change_info_cat (info, source->uid_removed, camel_folder_change_info_remove_uid);
+	change_info_cat (info, source->uid_changed, camel_folder_change_info_change_uid);
+	change_info_cat (info, source->uid_recent, change_info_recent_uid);
+	change_info_cat (info, source->priv->uid_filter, change_info_filter_uid);
 }
 
 /**
@@ -2407,30 +2657,30 @@ camel_folder_change_info_cat(CamelFolderChangeInfo *info, CamelFolderChangeInfo
  * Add a new uid to the changeinfo.
  **/
 void
-camel_folder_change_info_add_uid(CamelFolderChangeInfo *info, const gchar *uid)
+camel_folder_change_info_add_uid (CamelFolderChangeInfo *info, const gchar *uid)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 	GPtrArray *olduids;
 	gchar *olduid;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
-	if (g_hash_table_lookup_extended(p->uid_stored, uid, (gpointer) &olduid, (gpointer) &olduids)) {
+	if (g_hash_table_lookup_extended (p->uid_stored, uid, (gpointer) &olduid, (gpointer) &olduids)) {
 		/* if it was removed then added, promote it to a changed */
 		/* if it was changed then added, leave as changed */
 		if (olduids == info->uid_removed) {
-			g_ptr_array_remove_fast(olduids, olduid);
-			g_ptr_array_add(info->uid_changed, olduid);
-			g_hash_table_insert(p->uid_stored, olduid, info->uid_changed);
+			g_ptr_array_remove_fast (olduids, olduid);
+			g_ptr_array_add (info->uid_changed, olduid);
+			g_hash_table_insert (p->uid_stored, olduid, info->uid_changed);
 		}
 		return;
 	}
 
-	olduid = e_mempool_strdup(p->uid_pool, uid);
-	g_ptr_array_add(info->uid_added, olduid);
-	g_hash_table_insert(p->uid_stored, olduid, info->uid_added);
+	olduid = e_mempool_strdup (p->uid_pool, uid);
+	g_ptr_array_add (info->uid_added, olduid);
+	g_hash_table_insert (p->uid_stored, olduid, info->uid_added);
 }
 
 /**
@@ -2441,29 +2691,29 @@ camel_folder_change_info_add_uid(CamelFolderChangeInfo *info, const gchar *uid)
  * Add a uid to the removed uid list.
  **/
 void
-camel_folder_change_info_remove_uid(CamelFolderChangeInfo *info, const gchar *uid)
+camel_folder_change_info_remove_uid (CamelFolderChangeInfo *info, const gchar *uid)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 	GPtrArray *olduids;
 	gchar *olduid;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
-	if (g_hash_table_lookup_extended(p->uid_stored, uid, (gpointer) &olduid, (gpointer) &olduids)) {
+	if (g_hash_table_lookup_extended (p->uid_stored, uid, (gpointer) &olduid, (gpointer) &olduids)) {
 		/* if it was added/changed them removed, then remove it */
 		if (olduids != info->uid_removed) {
-			g_ptr_array_remove_fast(olduids, olduid);
-			g_ptr_array_add(info->uid_removed, olduid);
-			g_hash_table_insert(p->uid_stored, olduid, info->uid_removed);
+			g_ptr_array_remove_fast (olduids, olduid);
+			g_ptr_array_add (info->uid_removed, olduid);
+			g_hash_table_insert (p->uid_stored, olduid, info->uid_removed);
 		}
 		return;
 	}
 
-	olduid = e_mempool_strdup(p->uid_pool, uid);
-	g_ptr_array_add(info->uid_removed, olduid);
-	g_hash_table_insert(p->uid_stored, olduid, info->uid_removed);
+	olduid = e_mempool_strdup (p->uid_pool, uid);
+	g_ptr_array_add (info->uid_removed, olduid);
+	g_hash_table_insert (p->uid_stored, olduid, info->uid_removed);
 }
 
 /**
@@ -2474,24 +2724,24 @@ camel_folder_change_info_remove_uid(CamelFolderChangeInfo *info, const gchar *ui
  * Add a uid to the changed uid list.
  **/
 void
-camel_folder_change_info_change_uid(CamelFolderChangeInfo *info, const gchar *uid)
+camel_folder_change_info_change_uid (CamelFolderChangeInfo *info, const gchar *uid)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 	GPtrArray *olduids;
 	gchar *olduid;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
-	if (g_hash_table_lookup_extended(p->uid_stored, uid, (gpointer) &olduid, (gpointer) &olduids)) {
+	if (g_hash_table_lookup_extended (p->uid_stored, uid, (gpointer) &olduid, (gpointer) &olduids)) {
 		/* if we have it already, leave it as that */
 		return;
 	}
 
-	olduid = e_mempool_strdup(p->uid_pool, uid);
-	g_ptr_array_add(info->uid_changed, olduid);
-	g_hash_table_insert(p->uid_stored, olduid, info->uid_changed);
+	olduid = e_mempool_strdup (p->uid_pool, uid);
+	g_ptr_array_add (info->uid_changed, olduid);
+	g_hash_table_insert (p->uid_stored, olduid, info->uid_changed);
 }
 
 /**
@@ -2504,12 +2754,12 @@ camel_folder_change_info_change_uid(CamelFolderChangeInfo *info, const gchar *ui
  * filtering
  **/
 void
-camel_folder_change_info_recent_uid(CamelFolderChangeInfo *info, const gchar *uid)
+camel_folder_change_info_recent_uid (CamelFolderChangeInfo *info, const gchar *uid)
 {
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
-	change_info_recent_uid(info, uid);
-	change_info_filter_uid(info, uid);
+	change_info_recent_uid (info, uid);
+	change_info_filter_uid (info, uid);
 }
 
 /**
@@ -2522,9 +2772,9 @@ camel_folder_change_info_recent_uid(CamelFolderChangeInfo *info, const gchar *ui
  * otherwise
  **/
 gboolean
-camel_folder_change_info_changed(CamelFolderChangeInfo *info)
+camel_folder_change_info_changed (CamelFolderChangeInfo *info)
 {
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	return (info->uid_added->len || info->uid_removed->len || info->uid_changed->len || info->uid_recent->len);
 }
@@ -2537,26 +2787,26 @@ camel_folder_change_info_changed(CamelFolderChangeInfo *info)
  * processed.
  **/
 void
-camel_folder_change_info_clear(CamelFolderChangeInfo *info)
+camel_folder_change_info_clear (CamelFolderChangeInfo *info)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
-	g_ptr_array_set_size(info->uid_added, 0);
-	g_ptr_array_set_size(info->uid_removed, 0);
-	g_ptr_array_set_size(info->uid_changed, 0);
-	g_ptr_array_set_size(info->uid_recent, 0);
+	g_ptr_array_set_size (info->uid_added, 0);
+	g_ptr_array_set_size (info->uid_removed, 0);
+	g_ptr_array_set_size (info->uid_changed, 0);
+	g_ptr_array_set_size (info->uid_recent, 0);
 	if (p->uid_source) {
-		g_hash_table_destroy(p->uid_source);
+		g_hash_table_destroy (p->uid_source);
 		p->uid_source = NULL;
 	}
-	g_hash_table_destroy(p->uid_stored);
-	p->uid_stored = g_hash_table_new(g_str_hash, g_str_equal);
-	g_ptr_array_set_size(p->uid_filter, 0);
-	e_mempool_flush(p->uid_pool, TRUE);
+	g_hash_table_destroy (p->uid_stored);
+	p->uid_stored = g_hash_table_new (g_str_hash, g_str_equal);
+	g_ptr_array_set_size (p->uid_filter, 0);
+	e_mempool_flush (p->uid_pool, TRUE);
 }
 
 /**
@@ -2566,25 +2816,25 @@ camel_folder_change_info_clear(CamelFolderChangeInfo *info)
  * Free memory associated with the folder change info lists.
  **/
 void
-camel_folder_change_info_free(CamelFolderChangeInfo *info)
+camel_folder_change_info_free (CamelFolderChangeInfo *info)
 {
 	struct _CamelFolderChangeInfoPrivate *p;
 
-	g_assert(info != NULL);
+	g_assert (info != NULL);
 
 	p = info->priv;
 
 	if (p->uid_source)
-		g_hash_table_destroy(p->uid_source);
+		g_hash_table_destroy (p->uid_source);
 
-	g_hash_table_destroy(p->uid_stored);
-	g_ptr_array_free(p->uid_filter, TRUE);
-	e_mempool_destroy(p->uid_pool);
+	g_hash_table_destroy (p->uid_stored);
+	g_ptr_array_free (p->uid_filter, TRUE);
+	e_mempool_destroy (p->uid_pool);
 	g_slice_free (struct _CamelFolderChangeInfoPrivate, p);
 
-	g_ptr_array_free(info->uid_added, TRUE);
-	g_ptr_array_free(info->uid_removed, TRUE);
-	g_ptr_array_free(info->uid_changed, TRUE);
-	g_ptr_array_free(info->uid_recent, TRUE);
+	g_ptr_array_free (info->uid_added, TRUE);
+	g_ptr_array_free (info->uid_removed, TRUE);
+	g_ptr_array_free (info->uid_changed, TRUE);
+	g_ptr_array_free (info->uid_recent, TRUE);
 	g_slice_free (CamelFolderChangeInfo, info);
 }
diff --git a/camel/camel-folder.h b/camel/camel-folder.h
index 990c1a4..cfcf9d5 100644
--- a/camel/camel-folder.h
+++ b/camel/camel-folder.h
@@ -22,21 +22,45 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_FOLDER_H
-#define CAMEL_FOLDER_H 1
+#define CAMEL_FOLDER_H
 
-#include <glib.h>
 #include <camel/camel-object.h>
 #include <camel/camel-folder-summary.h>
 
-#define CAMEL_FOLDER_TYPE     (camel_folder_get_type ())
-#define CAMEL_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_FOLDER_TYPE, CamelFolder))
-#define CAMEL_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_FOLDER_TYPE, CamelFolderClass))
-#define CAMEL_IS_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_FOLDER \
+	(camel_folder_get_type ())
+#define CAMEL_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_FOLDER, CamelFolder))
+#define CAMEL_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_FOLDER, CamelFolderClass))
+#define CAMEL_IS_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_FOLDER))
+#define CAMEL_IS_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_FOLDER))
+#define CAMEL_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_FOLDER, CamelFolderClass))
 
 G_BEGIN_DECLS
 
+struct _CamelStore;
+
 typedef struct _CamelFolderChangeInfo CamelFolderChangeInfo;
+typedef struct _CamelFolderChangeInfoPrivate CamelFolderChangeInfoPrivate;
+
+typedef struct _CamelFolder CamelFolder;
+typedef struct _CamelFolderClass CamelFolderClass;
+typedef struct _CamelFolderPrivate CamelFolderPrivate;
 
 enum {
 	CAMEL_FOLDER_ARG_FIRST = CAMEL_ARG_FIRST + 0x1000,
@@ -81,7 +105,7 @@ struct _CamelFolderChangeInfo {
 	GPtrArray *uid_changed;
 	GPtrArray *uid_recent;
 
-	struct _CamelFolderChangeInfoPrivate *priv;
+	CamelFolderChangeInfoPrivate *priv;
 };
 
 typedef struct _CamelFolderQuotaInfo CamelFolderQuotaInfo;
@@ -95,16 +119,15 @@ struct _CamelFolderQuotaInfo {
 };
 
 struct _CamelFolder {
-	CamelObject parent_object;
-
-	struct _CamelFolderPrivate *priv;
+	CamelObject parent;
+	CamelFolderPrivate *priv;
 
 	/* get these via the :get() method, they might not be set otherwise */
 	gchar *name;
 	gchar *full_name;
 	gchar *description;
 
-	CamelStore *parent_store;
+	struct _CamelStore *parent_store;
 	CamelFolderSummary *summary;
 
 	guint32 folder_flags;
@@ -122,7 +145,7 @@ struct _CamelFolder {
 #define CAMEL_FOLDER_IS_JUNK                (1<<5)
 #define CAMEL_FOLDER_FILTER_JUNK	    (1<<6)
 
-typedef struct {
+struct _CamelFolderClass {
 	CamelObjectClass parent_class;
 
 	/* Virtual methods */
@@ -134,7 +157,7 @@ typedef struct {
 	const gchar *  (*get_name)  (CamelFolder *folder);
 	const gchar *  (*get_full_name)   (CamelFolder *folder);
 
-	CamelStore *  (*get_parent_store) (CamelFolder *folder);
+	struct _CamelStore *  (*get_parent_store) (CamelFolder *folder);
 
 	void (*expunge)  (CamelFolder *folder,
 			  CamelException *ex);
@@ -217,14 +240,13 @@ typedef struct {
                                CamelException *ex);
         GPtrArray * (*get_uncached_uids)(CamelFolder *, GPtrArray * uids, CamelException *);
 	gchar * (*get_filename) (CamelFolder *, const gchar *uid, CamelException *);
-} CamelFolderClass;
+};
 
-/* Standard Camel function */
-CamelType camel_folder_get_type (void);
+GType camel_folder_get_type (void);
 
 /* public methods */
 void               camel_folder_construct              (CamelFolder *folder,
-							CamelStore *parent_store,
+							struct _CamelStore *parent_store,
 							const gchar *full_name,
 							const gchar *name);
 
@@ -234,7 +256,7 @@ void               camel_folder_sync                   (CamelFolder *folder,
 							gboolean expunge,
 							CamelException *ex);
 
-CamelStore *       camel_folder_get_parent_store       (CamelFolder *folder);
+struct _CamelStore *       camel_folder_get_parent_store       (CamelFolder *folder);
 
 /* delete operations */
 void		   camel_folder_expunge                (CamelFolder *folder,
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index e254c29..db16735 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>
 
@@ -61,6 +60,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"
@@ -72,48 +72,20 @@
 static gint logid;
 #endif
 
-static CamelCipherContextClass *parent_class = NULL;
+#define CAMEL_GPG_CONTEXT_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_GPG_CONTEXT, CamelGpgContextPrivate))
 
-/**
- * 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;
-}
+struct _CamelGpgContextPrivate {
+	gboolean 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 *ctx, gboolean always_trust)
-{
-	g_return_if_fail (CAMEL_IS_GPG_CONTEXT (ctx));
+enum {
+	PROP_0,
+	PROP_ALWAYS_TRUST
+};
 
-	ctx->always_trust = always_trust;
-}
+static gpointer parent_class;
 
 static const gchar *
 gpg_hash_to_id (CamelCipherContext *context, CamelCipherHash hash)
@@ -237,16 +209,18 @@ 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;
-	gpg->session = session;
-	camel_object_ref (session);
+	gpg->session = g_object_ref (session);
 	gpg->userid_hint = g_hash_table_new (g_str_hash, g_str_equal);
 	gpg->complete = FALSE;
 	gpg->seen_eof1 = TRUE;
@@ -290,21 +264,23 @@ 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) {
-		CamelMimeFilterCharset *filter;
-		CamelStreamFilter *fstream;
+		CamelMimeFilter *filter;
+		CamelStream *fstream;
 
 		gpg->utf8 = FALSE;
 
-		if ((filter = camel_mime_filter_charset_new_convert (charset, "UTF-8"))) {
-			fstream = camel_stream_filter_new_with_stream (stream);
-			camel_stream_filter_add (fstream, (CamelMimeFilter *) filter);
-			camel_object_unref (filter);
-			camel_object_unref (stream);
+		if ((filter = camel_mime_filter_charset_new (charset, "UTF-8"))) {
+			fstream = camel_stream_filter_new (stream);
+			camel_stream_filter_add (
+				CAMEL_STREAM_FILTER (fstream), filter);
+			g_object_unref (filter);
+			g_object_unref (stream);
 
 			stream = (CamelStream *) fstream;
 		}
@@ -371,18 +347,18 @@ gpg_ctx_set_armor (struct _GpgCtx *gpg, gboolean armor)
 static void
 gpg_ctx_set_istream (struct _GpgCtx *gpg, CamelStream *istream)
 {
-	camel_object_ref (istream);
+	g_object_ref (istream);
 	if (gpg->istream)
-		camel_object_unref (gpg->istream);
+		g_object_unref (gpg->istream);
 	gpg->istream = istream;
 }
 
 static void
 gpg_ctx_set_ostream (struct _GpgCtx *gpg, CamelStream *ostream)
 {
-	camel_object_ref (ostream);
+	g_object_ref (ostream);
 	if (gpg->ostream)
-		camel_object_unref (gpg->ostream);
+		g_object_unref (gpg->ostream);
 	gpg->ostream = ostream;
 	gpg->seen_eof1 = FALSE;
 }
@@ -418,7 +394,7 @@ gpg_ctx_free (struct _GpgCtx *gpg)
 		return;
 
 	if (gpg->session)
-		camel_object_unref (gpg->session);
+		g_object_unref (gpg->session);
 
 	g_hash_table_foreach (gpg->userid_hint, userid_hint_free, NULL);
 	g_hash_table_destroy (gpg->userid_hint);
@@ -455,12 +431,12 @@ gpg_ctx_free (struct _GpgCtx *gpg)
 	}
 
 	if (gpg->istream)
-		camel_object_unref (gpg->istream);
+		g_object_unref (gpg->istream);
 
 	if (gpg->ostream)
-		camel_object_unref (gpg->ostream);
+		g_object_unref (gpg->ostream);
 
-	camel_object_unref (gpg->diagnostics);
+	g_object_unref (gpg->diagnostics);
 
 	g_free (gpg);
 }
@@ -1290,6 +1266,7 @@ static gint
 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;
@@ -1299,6 +1276,8 @@ 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,
@@ -1319,14 +1298,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);
+			g_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);
@@ -1367,15 +1346,15 @@ gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash
 	camel_data_wrapper_set_mime_type_field(dw, ct);
 	camel_content_type_unref(ct);
 
-	camel_medium_set_content_object((CamelMedium *)sigpart, dw);
-	camel_object_unref(dw);
+	camel_medium_set_content ((CamelMedium *)sigpart, dw);
+	g_object_unref (dw);
 
 	camel_mime_part_set_description(sigpart, _("This is a digitally signed message part"));
 
 	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);
@@ -1383,11 +1362,11 @@ gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash
 	mps->signature = sigpart;
 	mps->contentraw = istream;
 	camel_stream_reset(istream);
-	camel_object_ref(istream);
+	g_object_ref (istream);
 
-	camel_medium_set_content_object((CamelMedium *)opart, (CamelDataWrapper *)mps);
+	camel_medium_set_content ((CamelMedium *)opart, (CamelDataWrapper *)mps);
 fail:
-	camel_object_unref(ostream);
+	g_object_unref (ostream);
 
 	if (gpg)
 		gpg_ctx_free (gpg);
@@ -1418,7 +1397,7 @@ swrite (CamelMimePart *sigpart)
 			ret = camel_stream_close (ostream);
 	}
 
-	camel_object_unref(ostream);
+	g_object_unref (ostream);
 
 	if (ret == -1) {
 		g_unlink (template);
@@ -1432,6 +1411,7 @@ swrite (CamelMimePart *sigpart)
 static CamelCipherValidity *
 gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *ex)
 {
+	CamelCipherContextClass *class;
 	CamelCipherValidity *validity;
 	const gchar *diagnostics = NULL;
 	struct _GpgCtx *gpg = NULL;
@@ -1440,10 +1420,12 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 	CamelMimePart *sigpart;
 	CamelStream *istream = NULL, *canon_stream;
 	CamelMultipart *mps;
-	CamelStreamFilter *filter;
+	CamelStream *filter;
 	CamelMimeFilter *canon;
 
-	mps = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)ipart);
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+
+	mps = (CamelMultipart *)camel_medium_get_content ((CamelMedium *)ipart);
 	ct = ((CamelDataWrapper *)mps)->mime_type;
 
 	/* Inline signature (using our fake mime type) or PGP/Mime signature */
@@ -1454,7 +1436,7 @@ 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) {
+		    || g_ascii_strcasecmp(tmp, class->sign_protocol) != 0) {
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Cannot verify message signature: Incorrect message format"));
 			return NULL;
@@ -1469,13 +1451,13 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		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_object_unref (istream);
+			g_object_unref (istream);
 			return NULL;
 		}
 	} else if (camel_content_type_is(ct, "application", "x-inlinepgp-signed")) {
 		/* Inline Signed */
 		CamelDataWrapper *content;
-		content = camel_medium_get_content_object ((CamelMedium *) ipart);
+		content = camel_medium_get_content ((CamelMedium *) ipart);
 		istream = camel_stream_mem_new();
 		camel_data_wrapper_decode_to_stream (content, istream);
 		camel_stream_reset(istream);
@@ -1499,7 +1481,7 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 			printf("Writing gpg verify data to '%s'\n", name);
 			camel_stream_write_to_stream(istream, out);
 			camel_stream_reset(istream);
-			camel_object_unref(out);
+			g_object_unref (out);
 		}
 
 		g_free(name);
@@ -1510,7 +1492,7 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 			if (out) {
 				printf("Writing gpg verify signature to '%s'\n", name);
 				camel_data_wrapper_write_to_stream((CamelDataWrapper *)sigpart, out);
-				camel_object_unref(out);
+				g_object_unref (out);
 			}
 			g_free(name);
 		}
@@ -1532,19 +1514,19 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 	canon_stream = camel_stream_mem_new ();
 
 	/* strip trailing white-spaces */
-	filter = camel_stream_filter_new_with_stream (canon_stream);
+	filter = camel_stream_filter_new (canon_stream);
 	canon = camel_mime_filter_canon_new (CAMEL_MIME_FILTER_CANON_CRLF | CAMEL_MIME_FILTER_CANON_STRIP);
-	camel_stream_filter_add (filter, canon);
-	camel_object_unref (canon);
+	camel_stream_filter_add (CAMEL_STREAM_FILTER (filter), canon);
+	g_object_unref (canon);
 
-	camel_stream_write_to_stream (istream, (CamelStream *)filter);
+	camel_stream_write_to_stream (istream, filter);
 
-	camel_object_unref (filter);
+	g_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);
@@ -1594,8 +1576,7 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		g_unlink (sigfile);
 		g_free (sigfile);
 	}
-	camel_object_unref(istream);
-	camel_object_unref (canon_stream);
+	g_object_unref (istream);
 
 	return validity;
 
@@ -1605,7 +1586,7 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		gpg_ctx_free (gpg);
 
 	if (istream)
-		camel_object_unref(istream);
+		g_object_unref (istream);
 
 	if (sigfile) {
 		g_unlink (sigfile);
@@ -1618,6 +1599,7 @@ 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)
 {
+	CamelCipherContextClass *class;
 	CamelGpgContext *ctx = (CamelGpgContext *) context;
 	struct _GpgCtx *gpg;
 	gint i, res = -1;
@@ -1627,6 +1609,8 @@ 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) {
@@ -1635,13 +1619,13 @@ gpg_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipi
 		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]);
@@ -1678,8 +1662,8 @@ gpg_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipi
 	camel_data_wrapper_set_mime_type_field(dw, ct);
 	camel_content_type_unref(ct);
 
-	camel_medium_set_content_object((CamelMedium *)encpart, dw);
-	camel_object_unref(dw);
+	camel_medium_set_content ((CamelMedium *)encpart, dw);
+	g_object_unref (dw);
 
 	camel_mime_part_set_description(encpart, _("This is a digitally encrypted message part"));
 
@@ -1689,33 +1673,33 @@ gpg_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipi
 
 	verpart = camel_mime_part_new();
 	dw = camel_data_wrapper_new();
-	camel_data_wrapper_set_mime_type(dw, context->encrypt_protocol);
+	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_object((CamelMedium *)verpart, dw);
-	camel_object_unref(dw);
+	g_object_unref (vstream);
+	camel_medium_set_content ((CamelMedium *)verpart, dw);
+	g_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);
+	g_object_ref (ipart);
 
 	camel_multipart_add_part((CamelMultipart *)mpe, verpart);
-	camel_object_unref(verpart);
+	g_object_unref (verpart);
 	camel_multipart_add_part((CamelMultipart *)mpe, encpart);
-	camel_object_unref(encpart);
+	g_object_unref (encpart);
 
-	camel_medium_set_content_object((CamelMedium *)opart, (CamelDataWrapper *)mpe);
+	camel_medium_set_content ((CamelMedium *)opart, (CamelDataWrapper *)mpe);
 fail:
 	gpg_ctx_free(gpg);
 fail1:
-	camel_object_unref(istream);
-	camel_object_unref(ostream);
+	g_object_unref (istream);
+	g_object_unref (ostream);
 
 	return res;
 }
@@ -1738,7 +1722,7 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 		return NULL;
 	}
 
-	content = camel_medium_get_content_object((CamelMedium *)ipart);
+	content = camel_medium_get_content ((CamelMedium *)ipart);
 
 	if (!content) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
@@ -1749,15 +1733,15 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 	ct = camel_mime_part_get_content_type((CamelMimePart *)content);
 	/* Encrypted part (using our fake mime type) or PGP/Mime multipart */
 	if (camel_content_type_is(ct, "multipart", "encrypted")) {
-		mp = (CamelMultipart *) camel_medium_get_content_object ((CamelMedium *) ipart);
+		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"));
 			return NULL;
 		}
 
-		content = camel_medium_get_content_object ((CamelMedium *) encrypted);
+		content = camel_medium_get_content ((CamelMedium *) encrypted);
 	} else if (camel_content_type_is(ct, "application", "x-inlinepgp-encrypted")) {
-		content = camel_medium_get_content_object ((CamelMedium *) ipart);
+		content = camel_medium_get_content ((CamelMedium *) ipart);
 	} else {
 		/* Invalid Mimetype */
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
@@ -1772,7 +1756,7 @@ 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);
@@ -1806,7 +1790,7 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 		/* Multipart encrypted - parse a full mime part */
 		rv = camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)opart, ostream);
 
-		dw = camel_medium_get_content_object ((CamelMedium *)opart);
+		dw = camel_medium_get_content ((CamelMedium *)opart);
 		if (!camel_data_wrapper_decode_to_stream (dw, null)) {
 			/* nothing had been decoded from the stream, it doesn't
 			   contain any header, like Content-Type or such, thus
@@ -1814,15 +1798,15 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 			rv = camel_data_wrapper_construct_from_stream (dw, ostream);
 		}
 
-		camel_object_unref (null);
+		g_object_unref (null);
 	} else {
 		/* 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);
 		camel_data_wrapper_set_mime_type(dw, "application/octet-stream");
-		camel_medium_set_content_object((CamelMedium *)opart, dw);
-		camel_object_unref(dw);
+		camel_medium_set_content ((CamelMedium *)opart, dw);
+		g_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");
 	}
@@ -1852,8 +1836,8 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 	}
 
  fail:
-	camel_object_unref(ostream);
-	camel_object_unref(istream);
+	g_object_unref (ostream);
+	g_object_unref (istream);
 	gpg_ctx_free (gpg);
 
 	return valid;
@@ -1865,7 +1849,7 @@ gpg_import_keys (CamelCipherContext *context, CamelStream *istream, CamelExcepti
 	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);
 
@@ -1905,7 +1889,7 @@ gpg_export_keys (CamelCipherContext *context, GPtrArray *keys, CamelStream *ostr
 	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);
@@ -1946,55 +1930,143 @@ fail:
 /* ********************************************************************** */
 
 static void
-camel_gpg_context_class_init (CamelGpgContextClass *klass)
+gpg_context_set_property (GObject *object,
+                          guint property_id,
+                          const GValue *value,
+                          GParamSpec *pspec)
 {
-	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;
+	switch (property_id) {
+		case PROP_ALWAYS_TRUST:
+			camel_gpg_context_set_always_trust (
+				CAMEL_GPG_CONTEXT (object),
+				g_value_get_boolean (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
 static void
-camel_gpg_context_init (CamelGpgContext *context)
+gpg_context_get_property (GObject *object,
+                          guint property_id,
+                          GValue *value,
+                          GParamSpec *pspec)
 {
-	CamelCipherContext *cipher = (CamelCipherContext *) context;
+	switch (property_id) {
+		case PROP_ALWAYS_TRUST:
+			g_value_set_boolean (
+				value,
+				camel_gpg_context_get_always_trust (
+				CAMEL_GPG_CONTEXT (object)));
+			return;
+	}
 
-	context->always_trust = FALSE;
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
 
-	cipher->sign_protocol = "application/pgp-signature";
-	cipher->encrypt_protocol = "application/pgp-encrypted";
-	cipher->key_protocol = "application/pgp-keys";
+static void
+gpg_context_class_init (CamelGpgContextClass *class)
+{
+	GObjectClass *object_class;
+	CamelCipherContextClass *cipher_context_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelGpgContextClass));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = gpg_context_set_property;
+	object_class->get_property = gpg_context_get_property;
+
+	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;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_ALWAYS_TRUST,
+		g_param_spec_boolean (
+			"always-trust",
+			"Always Trust",
+			NULL,
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT));
 }
 
 static void
-camel_gpg_context_finalise (CamelObject *object)
+gpg_context_init (CamelGpgContext *context)
 {
-	;
+	context->priv = CAMEL_GPG_CONTEXT_GET_PRIVATE (context);
 }
 
-CamelType
+GType
 camel_gpg_context_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_cipher_context_get_type (),
-					    "CamelGpgContext",
-					    sizeof (CamelGpgContext),
-					    sizeof (CamelGpgContextClass),
-					    (CamelObjectClassInitFunc) camel_gpg_context_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_gpg_context_init,
-					    (CamelObjectFinalizeFunc) camel_gpg_context_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_CIPHER_CONTEXT,
+			"CamelGpgContext",
+			sizeof (CamelGpgContextClass),
+			(GClassInitFunc) gpg_context_class_init,
+			sizeof (CamelGpgContext),
+			(GInstanceInitFunc) gpg_context_init,
+			0);
 
 	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)
+{
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+
+	return g_object_new (
+		CAMEL_TYPE_GPG_CONTEXT,
+		"session", session, NULL);
+}
+
+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;
+
+	g_object_notify (G_OBJECT (context), "always-trust");
+}
diff --git a/camel/camel-gpg-context.h b/camel/camel-gpg-context.h
index 3c67c28..dc6495b 100644
--- a/camel/camel-gpg-context.h
+++ b/camel/camel-gpg-context.h
@@ -20,38 +20,59 @@
  *
  */
 
-#ifndef __CAMEL_GPG_CONTEXT_H__
-#define __CAMEL_GPG_CONTEXT_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_GPG_CONTEXT_H
+#define CAMEL_GPG_CONTEXT_H
 
 #include <camel/camel-cipher-context.h>
+#include <camel/camel-session.h>
 
-#define CAMEL_GPG_CONTEXT_TYPE     (camel_gpg_context_get_type ())
-#define CAMEL_GPG_CONTEXT(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_GPG_CONTEXT_TYPE, CamelGpgContext))
-#define CAMEL_GPG_CONTEXT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_GPG_CONTEXT_TYPE, CamelGpgContextClass))
-#define CAMEL_IS_GPG_CONTEXT(o)    (CAMEL_CHECK_TYPE((o), CAMEL_GPG_CONTEXT_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_GPG_CONTEXT \
+	(camel_gpg_context_get_type ())
+#define CAMEL_GPG_CONTEXT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_GPG_CONTEXT, CamelGpgContext))
+#define CAMEL_GPG_CONTEXT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_GPG_CONTEXT, CamelGpgContextClass))
+#define CAMEL_IS_GPG_CONTEXT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_GPG_CONTEXT))
+#define CAMEL_IS_GPG_CONTEXT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_GPG_CONTEXT))
+#define CAMEL_GPG_CONTEXT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_GPG_CONTEXT, CamelGpgContextClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelGpgContext CamelGpgContext;
 typedef struct _CamelGpgContextClass CamelGpgContextClass;
+typedef struct _CamelGpgContextPrivate CamelGpgContextPrivate;
 
 struct _CamelGpgContext {
-	CamelCipherContext parent_object;
-
-	gboolean always_trust;
+	CamelCipherContext parent;
+	CamelGpgContextPrivate *priv;
 };
 
 struct _CamelGpgContextClass {
 	CamelCipherContextClass parent_class;
-
 };
 
-CamelType camel_gpg_context_get_type (void);
-
-CamelCipherContext *camel_gpg_context_new (CamelSession *session);
-
-void camel_gpg_context_set_always_trust (CamelGpgContext *ctx, gboolean trust);
+GType		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);
 
 G_END_DECLS
 
-#endif /* __CAMEL_GPG_CONTEXT_H__ */
+#endif /* CAMEL_GPG_CONTEXT_H */
diff --git a/camel/camel-html-parser.c b/camel/camel-html-parser.c
index 4efa277..de6a762 100644
--- a/camel/camel-html-parser.c
+++ b/camel/camel-html-parser.c
@@ -29,23 +29,15 @@
 #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;
+static gpointer parent_class;
 
 /* Parser definitions, see below object code for details */
 
-typedef struct _CamelHTMLParserPrivate CamelHTMLParserPrivate;
-
 struct _CamelHTMLParserPrivate {
 	gchar *inbuf,
 		*inptr,
@@ -63,53 +55,56 @@ 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 (GObject *object)
 {
-	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 = CAMEL_HTML_PARSER (object);
 
-	return type;
+	tokenize_free (parser->priv);
 }
 
 static void
-camel_html_parser_finalize(CamelObject *o)
+html_parser_class_init (CamelHTMLParserClass *class)
 {
-	CamelHTMLParser *f = (CamelHTMLParser *)o;
+	GObjectClass *object_class;
 
-	tokenise_free(f->priv);
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = html_parser_finalize;
+
+	tokenize_setup();
 }
 
 static void
-camel_html_parser_init       (CamelObject *o)
+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)
+GType
+camel_html_parser_get_type (void)
 {
-	camel_html_parser_parent = CAMEL_OBJECT_CLASS (camel_type_get_global_classfuncs (camel_object_get_type ()));
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelHTMLParser",
+			sizeof (CamelHTMLParserClass),
+			(GClassInitFunc) html_parser_class_init,
+			sizeof (CamelHTMLParser),
+			(GInstanceInitFunc) html_parser_init,
+			0);
 
-	tokenise_setup();
+	return type;
 }
 
 /**
@@ -122,8 +117,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 g_object_new (CAMEL_TYPE_HTML_PARSER, NULL);
 }
 
 void camel_html_parser_set_data(CamelHTMLParser *hp, const gchar *start, gint len, gint last)
@@ -137,7 +131,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)
@@ -460,7 +454,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;
 
@@ -472,7 +466,7 @@ static void tokenise_setup(void)
 	}
 }
 
-static CamelHTMLParserPrivate *tokenise_init(void)
+static CamelHTMLParserPrivate *tokenize_init(void)
 {
 	CamelHTMLParserPrivate *p;
 
@@ -487,12 +481,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;
 
@@ -536,7 +530,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-html-parser.h b/camel/camel-html-parser.h
index 2649656..b440b32 100644
--- a/camel/camel-html-parser.h
+++ b/camel/camel-html-parser.h
@@ -25,19 +25,39 @@
  * IT IS SUBJECT TO CHANGE OR MAY VANISH AT ANY TIME
  */
 
-#ifndef _CAMEL_HTML_PARSER_H
-#define _CAMEL_HTML_PARSER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_HTML_PARSER_H
+#define CAMEL_HTML_PARSER_H
 
 #include <camel/camel-object.h>
 
-#define CAMEL_HTML_PARSER(obj)         CAMEL_CHECK_CAST (obj, camel_html_parser_get_type (), CamelHTMLParser)
-#define CAMEL_HTML_PARSER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_html_parser_get_type (), CamelHTMLParserClass)
-#define CAMEL_IS_HTML_PARSER(obj)      CAMEL_CHECK_TYPE (obj, camel_html_parser_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_HTML_PARSER \
+	(camel_html_parser_get_type ())
+#define CAMEL_HTML_PARSER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_HTML_PARSER, CamelHTMLParser))
+#define CAMEL_HTML_PARSER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_HTML_PARSER, CamelHTMLParserClass))
+#define CAMEL_IS_HTML_PARSER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_HTML_PARSER))
+#define CAMEL_IS_HTML_PARSER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_HTML_PARSER))
+#define CAMEL_HTML_PARSER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_HTML_PARSER, CamelHTMLParserClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelHTMLParserClass CamelHTMLParserClass;
 typedef struct _CamelHTMLParser CamelHTMLParser;
+typedef struct _CamelHTMLParserClass CamelHTMLParserClass;
+typedef struct _CamelHTMLParserPrivate CamelHTMLParserPrivate;
 
 /* Parser/tokeniser states */
 typedef enum _camel_html_parser_t {
@@ -59,15 +79,14 @@ typedef enum _camel_html_parser_t {
 
 struct _CamelHTMLParser {
 	CamelObject parent;
-
-	struct _CamelHTMLParserPrivate *priv;
+	CamelHTMLParserPrivate *priv;
 };
 
 struct _CamelHTMLParserClass {
 	CamelObjectClass parent_class;
 };
 
-CamelType		camel_html_parser_get_type	(void);
+GType		camel_html_parser_get_type	(void);
 CamelHTMLParser      *camel_html_parser_new	(void);
 
 void camel_html_parser_set_data(CamelHTMLParser *hp, const gchar *start, gint len, gint last);
@@ -79,4 +98,4 @@ const GPtrArray *camel_html_parser_attr_list(CamelHTMLParser *hp, const GPtrArra
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_HTML_PARSER_H */
+#endif /* CAMEL_HTML_PARSER_H */
diff --git a/camel/camel-http-stream.c b/camel/camel-http-stream.c
index 3d2d5e9..bd54578 100644
--- a/camel/camel-http-stream.c
+++ b/camel/camel-http-stream.c
@@ -45,7 +45,7 @@
 
 #define d(x)
 
-static CamelStreamClass *parent_class = NULL;
+static gpointer parent_class;
 
 static gssize stream_read (CamelStream *stream, gchar *buffer, gsize n);
 static gssize stream_write (CamelStream *stream, const gchar *buffer, gsize n);
@@ -54,56 +54,50 @@ static gint stream_close  (CamelStream *stream);
 static gint stream_reset  (CamelStream *stream);
 
 static void
-camel_http_stream_class_init (CamelHttpStreamClass *camel_http_stream_class)
+http_stream_dispose (GObject *object)
 {
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_http_stream_class);
+	CamelHttpStream *http = CAMEL_HTTP_STREAM (object);
 
-	parent_class = CAMEL_STREAM_CLASS (camel_type_get_global_classfuncs (camel_stream_get_type ()));
+	if (http->parser != NULL) {
+		g_object_unref (http->parser);
+		http->parser = NULL;
+	}
 
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->reset = stream_reset;
-}
+	if (http->content_type != NULL) {
+		camel_content_type_unref (http->content_type);
+		http->content_type = NULL;
+	}
 
-static void
-camel_http_stream_init (gpointer object, gpointer klass)
-{
-	CamelHttpStream *http = CAMEL_HTTP_STREAM (object);
+	if (http->headers != NULL) {
+		camel_header_raw_clear (&http->headers);
+		http->headers = NULL;
+	}
 
-	http->parser = NULL;
-	http->content_type = NULL;
-	http->headers = NULL;
-	http->session = NULL;
-	http->url = NULL;
-	http->proxy = NULL;
-	http->authrealm = NULL;
-	http->authpass = NULL;
-	http->statuscode = 0;
-	http->raw = NULL;
+	if (http->session != NULL) {
+		g_object_unref (http->session);
+		http->session = NULL;
+	}
+
+	if (http->raw != NULL) {
+		g_object_unref (http->raw);
+		http->raw = NULL;
+	}
+
+	if (http->read != NULL) {
+		g_object_unref (http->read);
+		http->read = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_http_stream_finalize (CamelObject *object)
+http_stream_finalize (GObject *object)
 {
 	CamelHttpStream *http = CAMEL_HTTP_STREAM (object);
 
-	if (http->parser)
-		camel_object_unref(http->parser);
-
-	if (http->content_type)
-		camel_content_type_unref (http->content_type);
-
-	if (http->headers)
-		camel_header_raw_clear (&http->headers);
-
-	if (http->session)
-		camel_object_unref(http->session);
-
-	if (http->url)
+	if (http->url != NULL)
 		camel_url_free (http->url);
 
 	if (http->proxy)
@@ -112,27 +106,59 @@ camel_http_stream_finalize (CamelObject *object)
 	g_free (http->authrealm);
 	g_free (http->authpass);
 
-	if (http->raw)
-		camel_object_unref(http->raw);
-	if (http->read)
-		camel_object_unref(http->read);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+http_stream_class_init (CamelHttpStreamClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = http_stream_dispose;
+	object_class->finalize = http_stream_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_read;
+	stream_class->write = stream_write;
+	stream_class->flush = stream_flush;
+	stream_class->close = stream_close;
+	stream_class->reset = stream_reset;
 }
 
-CamelType
+static void
+http_stream_init (CamelHttpStream *http)
+{
+	http->parser = NULL;
+	http->content_type = NULL;
+	http->headers = NULL;
+	http->session = NULL;
+	http->url = NULL;
+	http->proxy = NULL;
+	http->authrealm = NULL;
+	http->authpass = NULL;
+	http->statuscode = 0;
+	http->raw = NULL;
+}
+
+GType
 camel_http_stream_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_stream_get_type (),
-					    "CamelHttpStream",
-					    sizeof (CamelHttpStream),
-					    sizeof (CamelHttpStreamClass),
-					    (CamelObjectClassInitFunc) camel_http_stream_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_http_stream_init,
-					    (CamelObjectFinalizeFunc) camel_http_stream_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelHttpStream",
+			sizeof (CamelHttpStreamClass),
+			(GClassInitFunc) http_stream_class_init,
+			sizeof (CamelHttpStream),
+			(GInstanceInitFunc) http_stream_init,
+			0);
 
 	return type;
 }
@@ -154,11 +180,11 @@ camel_http_stream_new (CamelHttpMethod method, struct _CamelSession *session, Ca
 	g_return_val_if_fail(CAMEL_IS_SESSION(session), NULL);
 	g_return_val_if_fail(url != NULL, NULL);
 
-	stream = CAMEL_HTTP_STREAM (camel_object_new (camel_http_stream_get_type ()));
+	stream = g_object_new (CAMEL_TYPE_HTTP_STREAM, NULL);
 
 	stream->method = method;
 	stream->session = session;
-	camel_object_ref(session);
+	g_object_ref (session);
 
 	str = camel_url_to_string (url, 0);
 	stream->url = camel_url_new (str, NULL);
@@ -202,13 +228,13 @@ http_connect (CamelHttpStream *http, CamelURL *url)
 
 	ai = camel_getaddrinfo(url->host, serv, &hints, NULL);
 	if (ai == NULL) {
-		camel_object_unref (stream);
+		g_object_unref (stream);
 		return NULL;
 	}
 
 	if (camel_tcp_stream_connect (CAMEL_TCP_STREAM (stream), ai) == -1) {
 		errsave = errno;
-		camel_object_unref (stream);
+		g_object_unref (stream);
 		camel_freeaddrinfo(ai);
 		errno = errsave;
 		return NULL;
@@ -226,17 +252,17 @@ static void
 http_disconnect(CamelHttpStream *http)
 {
 	if (http->raw) {
-		camel_object_unref(http->raw);
+		g_object_unref (http->raw);
 		http->raw = NULL;
 	}
 
 	if (http->read) {
-		camel_object_unref(http->read);
+		g_object_unref (http->read);
 		http->read = NULL;
 	}
 
 	if (http->parser) {
-		camel_object_unref(http->parser);
+		g_object_unref (http->parser);
 		http->parser = NULL;
 	}
 }
@@ -288,7 +314,7 @@ http_get_headers (CamelHttpStream *http)
 	gint err;
 
 	if (http->parser)
-		camel_object_unref (http->parser);
+		g_object_unref (http->parser);
 
 	http->parser = camel_mime_parser_new ();
 	camel_mime_parser_init_with_stream (http->parser, http->read);
@@ -332,7 +358,7 @@ http_get_headers (CamelHttpStream *http)
 	err = camel_mime_parser_errno (http->parser);
 
 	if (err != 0) {
-		camel_object_unref (http->parser);
+		g_object_unref (http->parser);
 		http->parser = NULL;
 		goto exception;
 	}
diff --git a/camel/camel-http-stream.h b/camel/camel-http-stream.h
index 7e3703a..77dbc28 100644
--- a/camel/camel-http-stream.h
+++ b/camel/camel-http-stream.h
@@ -20,18 +20,35 @@
  *
  */
 
-#ifndef __CAMEL_HTTP_STREAM_H__
-#define __CAMEL_HTTP_STREAM_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_HTTP_STREAM_H
+#define CAMEL_HTTP_STREAM_H
 
 #include <camel/camel-mime-parser.h>
 #include <camel/camel-mime-utils.h>
 #include <camel/camel-stream.h>
 #include <camel/camel-url.h>
 
-#define CAMEL_HTTP_STREAM_TYPE     (camel_http_stream_get_type ())
-#define CAMEL_HTTP_STREAM(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_HTTP_STREAM_TYPE, CamelHttpStream))
-#define CAMEL_HTTP_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_HTTP_STREAM_TYPE, CamelHttpStreamClass))
-#define CAMEL_IS_HTTP_STREAM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_HTTP_STREAM_TYPE))
+#define CAMEL_TYPE_HTTP_STREAM \
+	(camel_http_stream_get_type ())
+#define CAMEL_HTTP_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_HTTP_STREAM, CamelHttpStream))
+#define CAMEL_HTTP_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_HTTP_STREAM, CamelHttpStreamClass))
+#define CAMEL_IS_HTTP_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_HTTP_STREAM))
+#define CAMEL_IS_HTTP_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_HTTP_STREAM))
+#define CAMEL_HTTP_STREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_HTTP_STREAM, CamelHttpStreamClass))
 
 G_BEGIN_DECLS
 
@@ -46,10 +63,11 @@ typedef enum {
 	/*CAMEL_HTTP_METHOD_CONNECT*/
 } CamelHttpMethod;
 
+typedef struct _CamelHttpStream CamelHttpStream;
 typedef struct _CamelHttpStreamClass CamelHttpStreamClass;
 
 struct _CamelHttpStream {
-	CamelStream parent_object;
+	CamelStream parent;
 
 	CamelMimeParser *parser;
 
@@ -79,8 +97,7 @@ struct _CamelHttpStreamClass {
 	/* Virtual methods */
 };
 
-/* Standard Camel function */
-CamelType camel_http_stream_get_type (void);
+GType camel_http_stream_get_type (void);
 
 /* public methods */
 CamelStream *camel_http_stream_new (CamelHttpMethod method, struct _CamelSession *session, CamelURL *url);
@@ -95,4 +112,4 @@ CamelContentType *camel_http_stream_get_content_type (CamelHttpStream *http_stre
 
 G_END_DECLS
 
-#endif /* __CAMEL_HTTP_STREAM_H__ */
+#endif /* CAMEL_HTTP_STREAM_H */
diff --git a/camel/camel-i18n.h b/camel/camel-i18n.h
index 20b43be..a5f6ca7 100644
--- a/camel/camel-i18n.h
+++ b/camel/camel-i18n.h
@@ -20,10 +20,14 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
-#ifndef __CAMEL_I18N_H__
-#define __CAMEL_I18N_H__
+#ifndef CAMEL_I18N_H
+#define CAMEL_I18N_H
 
 #include <glib.h>
 
@@ -51,6 +55,6 @@
 #    define N_(String) (String)
 #endif
 
-#endif /* __CAMEL_I18N_H__ */
+#endif /* CAMEL_I18N_H */
 
 #endif /* CAMEL_DISABLE_DEPRECATED */
diff --git a/camel/camel-iconv.c b/camel/camel-iconv.c
index 2533d1f..8825f28 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-iconv.h b/camel/camel-iconv.h
index 1199bb5..85c3a36 100644
--- a/camel/camel-iconv.h
+++ b/camel/camel-iconv.h
@@ -20,8 +20,12 @@
  *
  */
 
-#ifndef __CAMEL_ICONV_H__
-#define __CAMEL_ICONV_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_ICONV_H
+#define CAMEL_ICONV_H
 
 #include <sys/types.h>
 #include <iconv.h>
@@ -46,4 +50,4 @@ void		camel_iconv_close		(iconv_t cd);
 
 G_END_DECLS
 
-#endif /* __CAMEL_ICONV_H__ */
+#endif /* CAMEL_ICONV_H */
diff --git a/camel/camel-index-control.c b/camel/camel-index-control.c
index 2594486..d1f9693 100644
--- a/camel/camel-index-control.c
+++ b/camel/camel-index-control.c
@@ -44,10 +44,10 @@ do_compress(gint argc, gchar **argv)
 		if (idx) {
 			printf(" Compressing ...\n");
 			if (camel_index_compress(idx) == -1) {
-				camel_object_unref((CamelObject *)idx);
+				g_object_unref (idx);
 				return 1;
 			}
-			camel_object_unref((CamelObject *)idx);
+			g_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);
+			g_object_unref (idx);
 		} else {
 			printf(" Failed: %s\n", g_strerror (errno));
 			return 1;
@@ -88,7 +88,7 @@ do_info(gint argc, gchar **argv)
 		idx = (CamelIndex *)camel_text_index_new(argv[i], O_RDONLY);
 		if (idx) {
 			camel_text_index_info((CamelTextIndex *)idx);
-			camel_object_unref((CamelObject *)idx);
+			g_object_unref (idx);
 		} else {
 			printf(" Failed: %s\n", g_strerror (errno));
 			return 0;
@@ -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);
+			g_object_unref (idx);
 		} else {
 			printf(" Failed: %s\n", g_strerror (errno));
 			return 0;
@@ -157,7 +157,7 @@ do_perf(gint argc, gchar **argv)
 	const gchar *path = "/home/notzed/evolution/local/Inbox/mbox/cur";
 	struct dirent *d;
 	CamelStream *null, *filter, *stream;
-	CamelMimeFilterIndex *filter_index;
+	CamelMimeFilter *filter_index;
 	gchar *name;
 	CamelIndexName *idn;
 
@@ -175,34 +175,36 @@ do_perf(gint argc, gchar **argv)
 	}
 
 	null = camel_stream_null_new();
-	filter = (CamelStream *)camel_stream_filter_new_with_stream(null);
-	camel_object_unref((CamelObject *)null);
-	filter_index = camel_mime_filter_index_new_index(idx);
-	camel_stream_filter_add((CamelStreamFilter *)filter, (CamelMimeFilter *)filter_index);
+	filter = camel_stream_filter_new (null);
+	g_object_unref (null);
+	filter_index = camel_mime_filter_index_new (idx);
+	camel_stream_filter_add((CamelStreamFilter *)filter, filter_index);
 
 	while ((d = readdir(dir))) {
 		printf("indexing '%s'\n", d->d_name);
 
 		idn = camel_index_add_name(idx, d->d_name);
-		camel_mime_filter_index_set_name(filter_index, idn);
+		camel_mime_filter_index_set_name(
+			CAMEL_MIME_FILTER_INDEX (filter_index), idn);
 		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);
+		g_object_unref (stream);
 		g_free(name);
 
 		camel_index_write_name(idx, idn);
-		camel_object_unref((CamelObject *)idn);
-		camel_mime_filter_index_set_name(filter_index, NULL);
+		g_object_unref (idn);
+		camel_mime_filter_index_set_name(
+			CAMEL_MIME_FILTER_INDEX (filter_index), NULL);
 	}
 
 	closedir(dir);
 
 	camel_index_sync(idx);
-	camel_object_unref((CamelObject *)idx);
+	g_object_unref (idx);
 
-	camel_object_unref((CamelObject *)filter);
-	camel_object_unref((CamelObject *)filter_index);
+	g_object_unref (filter);
+	g_object_unref (filter_index);
 
 	return 0;
 }
diff --git a/camel/camel-index.c b/camel/camel-index.c
index 7671059..ef4ef8d 100644
--- a/camel/camel-index.c
+++ b/camel/camel-index.c
@@ -35,90 +35,103 @@
 
 #define w(x)
 #define io(x)
-#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
+#define d(x) /*(printf ("%s (%d): ", __FILE__, __LINE__),(x))*/
 
 #define CAMEL_INDEX_VERSION (0x01)
 
+#define CAMEL_INDEX_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_INDEX, CamelIndexPrivate))
+
 struct _CamelIndexPrivate {
 	gpointer dummy;
 };
 
-#define _PRIVATE(o) (((CamelIndex *)(o))->priv)
-
-#define CI_CLASS(o) ((CamelIndexClass *)(((CamelObject *)o)->klass))
-
 /* ********************************************************************** */
 /* CamelIndex */
 /* ********************************************************************** */
 
-static CamelObjectClass *camel_index_parent;
+static gpointer index_parent_class;
 
 static void
-camel_index_class_init(CamelIndexClass *klass)
+index_finalize (GObject *object)
 {
-	camel_index_parent = CAMEL_OBJECT_CLASS(camel_type_get_global_classfuncs(camel_object_get_type()));
+	CamelIndex *index = CAMEL_INDEX (object);
+
+	g_free (index->path);
+
+	/* Chain up to parent's finalize () method. */
+	G_OBJECT_CLASS (index_parent_class)->finalize (object);
 }
 
 static void
-camel_index_init(CamelIndex *idx)
+index_class_init (CamelIndexClass *class)
 {
-	struct _CamelIndexPrivate *p;
+	GObjectClass *object_class;
 
-	p = _PRIVATE(idx) = g_malloc0(sizeof(*p));
+	index_parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelIndexPrivate));
 
-	idx->version = CAMEL_INDEX_VERSION;
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = index_finalize;
 }
 
 static void
-camel_index_finalise(CamelIndex *idx)
+index_init (CamelIndex *index)
 {
-	g_free(idx->path);
-	g_free(idx->priv);
+	index->priv = CAMEL_INDEX_GET_PRIVATE (index);
+	index->version = CAMEL_INDEX_VERSION;
 }
 
-CamelType
-camel_index_get_type(void)
+GType
+camel_index_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_object_get_type(), "CamelIndex",
-					   sizeof (CamelIndex),
-					   sizeof (CamelIndexClass),
-					   (CamelObjectClassInitFunc) camel_index_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_index_init,
-					   (CamelObjectFinalizeFunc) camel_index_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelIndex",
+			sizeof (CamelIndexClass),
+			(GClassInitFunc) index_class_init,
+			sizeof (CamelIndex),
+			(GInstanceInitFunc) index_init,
+			0);
 
 	return type;
 }
 
 CamelIndex *
-camel_index_new(const gchar *path, gint flags)
+camel_index_new (const gchar *path, gint flags)
 {
-	CamelIndex *idx = (CamelIndex *)camel_object_new(camel_index_get_type());
+	CamelIndex *idx;
 
-	camel_index_construct(idx, path, flags);
+	idx = g_object_new (CAMEL_TYPE_INDEX, NULL);
+	camel_index_construct (idx, path, flags);
 
 	return idx;
 }
 
 void
-camel_index_construct(CamelIndex *idx, const gchar *path, gint flags)
+camel_index_construct (CamelIndex *idx, const gchar *path, gint flags)
 {
-	g_free(idx->path);
-	idx->path = g_strdup_printf("%s.index", path);
+	g_free (idx->path);
+	idx->path = g_strdup_printf ("%s.index", path);
 	idx->flags = flags;
 }
 
 gint
-camel_index_rename(CamelIndex *idx, const gchar *path)
+camel_index_rename (CamelIndex *idx, const gchar *path)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), -1);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->rename != NULL, -1);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->rename(idx, path);
+		return class->rename (idx, path);
 	else {
 		errno = ENOENT;
 		return -1;
@@ -126,7 +139,7 @@ camel_index_rename(CamelIndex *idx, const gchar *path)
 }
 
 void
-camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm func, gpointer data)
+camel_index_set_normalise (CamelIndex *idx, CamelIndexNorm func, gpointer data)
 {
 	g_return_if_fail (CAMEL_IS_INDEX (idx));
 
@@ -135,12 +148,17 @@ camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm func, gpointer data)
 }
 
 gint
-camel_index_sync(CamelIndex *idx)
+camel_index_sync (CamelIndex *idx)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), -1);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->sync != NULL, -1);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->sync(idx);
+		return class->sync (idx);
 	else {
 		errno = ENOENT;
 		return -1;
@@ -148,12 +166,17 @@ camel_index_sync(CamelIndex *idx)
 }
 
 gint
-camel_index_compress(CamelIndex *idx)
+camel_index_compress (CamelIndex *idx)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), -1);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->compress != NULL, -1);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->compress(idx);
+		return class->compress (idx);
 	else {
 		errno = ENOENT;
 		return -1;
@@ -161,14 +184,18 @@ camel_index_compress(CamelIndex *idx)
 }
 
 gint
-camel_index_delete(CamelIndex *idx)
+camel_index_delete (CamelIndex *idx)
 {
+	CamelIndexClass *class;
 	gint ret;
 
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), -1);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->delete != NULL, -1);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0) {
-		ret = CI_CLASS(idx)->delete(idx);
+		ret = class->delete (idx);
 		idx->state |= CAMEL_INDEX_DELETED;
 	} else {
 		errno = ENOENT;
@@ -179,34 +206,49 @@ camel_index_delete(CamelIndex *idx)
 }
 
 gint
-camel_index_has_name(CamelIndex *idx, const gchar *name)
+camel_index_has_name (CamelIndex *idx, const gchar *name)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), FALSE);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->has_name != NULL, FALSE);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->has_name(idx, name);
+		return class->has_name (idx, name);
 	else
 		return FALSE;
 }
 
 CamelIndexName *
-camel_index_add_name(CamelIndex *idx, const gchar *name)
+camel_index_add_name (CamelIndex *idx, const gchar *name)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), NULL);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->add_name != NULL, NULL);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->add_name(idx, name);
+		return class->add_name (idx, name);
 	else
 		return NULL;
 }
 
 gint
-camel_index_write_name(CamelIndex *idx, CamelIndexName *idn)
+camel_index_write_name (CamelIndex *idx, CamelIndexName *idn)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), -1);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->write_name != NULL, -1);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->write_name(idx, idn);
+		return class->write_name (idx, idn);
 	else {
 		errno = ENOENT;
 		return -1;
@@ -214,65 +256,89 @@ camel_index_write_name(CamelIndex *idx, CamelIndexName *idn)
 }
 
 CamelIndexCursor *
-camel_index_find_name(CamelIndex *idx, const gchar *name)
+camel_index_find_name (CamelIndex *idx, const gchar *name)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), NULL);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->find_name != NULL, NULL);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->find_name(idx, name);
+		return class->find_name (idx, name);
 	else
 		return NULL;
 }
 
 void
-camel_index_delete_name(CamelIndex *idx, const gchar *name)
+camel_index_delete_name (CamelIndex *idx, const gchar *name)
 {
+	CamelIndexClass *class;
+
 	g_return_if_fail (CAMEL_IS_INDEX (idx));
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_if_fail (class->delete_name != NULL);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		CI_CLASS(idx)->delete_name(idx, name);
+		class->delete_name (idx, name);
 }
 
 CamelIndexCursor *
-camel_index_find(CamelIndex *idx, const gchar *word)
+camel_index_find (CamelIndex *idx, const gchar *word)
 {
-	gchar *b = (gchar *)word;
+	CamelIndexClass *class;
 	CamelIndexCursor *ret;
+	gchar *b = (gchar *)word;
 
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), NULL);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->find != NULL, NULL);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) != 0)
 		return NULL;
 
 	if (idx->normalise)
-		b = idx->normalise(idx, word, idx->normalise_data);
+		b = idx->normalise (idx, word, idx->normalise_data);
 
-	ret = CI_CLASS(idx)->find(idx, b);
+	ret = class->find (idx, b);
 
 	if (b != word)
-		g_free(b);
+		g_free (b);
 
 	return ret;
 }
 
 CamelIndexCursor *
-camel_index_words(CamelIndex *idx)
+camel_index_words (CamelIndex *idx)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), NULL);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->words != NULL, NULL);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->words(idx);
+		return class->words (idx);
 	else
 		return NULL;
 }
 
 CamelIndexCursor *
-camel_index_names(CamelIndex *idx)
+camel_index_names (CamelIndex *idx)
 {
+	CamelIndexClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_INDEX (idx), NULL);
 
+	class = CAMEL_INDEX_GET_CLASS (idx);
+	g_return_val_if_fail (class->names != NULL, NULL);
+
 	if ((idx->state & CAMEL_INDEX_DELETED) == 0)
-		return CI_CLASS(idx)->names(idx);
+		return class->names (idx);
 	else
 		return NULL;
 }
@@ -281,141 +347,180 @@ camel_index_names(CamelIndex *idx)
 /* CamelIndexName */
 /* ********************************************************************** */
 
-static CamelObjectClass *camel_index_name_parent;
-
-#define CIN_CLASS(o) ((CamelIndexNameClass *)(((CamelObject *)o)->klass))
+static gpointer index_name_parent_class;
 
 static void
-camel_index_name_class_init(CamelIndexNameClass *klass)
+index_name_dispose (GObject *object)
 {
-	camel_index_name_parent = CAMEL_OBJECT_CLASS(camel_type_get_global_classfuncs(camel_object_get_type()));
-}
+	CamelIndexName *index_name = CAMEL_INDEX_NAME (object);
 
-static void
-camel_index_name_init(CamelIndexName *idn)
-{
+	if (index_name->index != NULL) {
+		g_object_unref (index_name->index);
+		index_name->index = NULL;
+	}
+
+	/* Chain up to parent's dispose () method. */
+	G_OBJECT_CLASS (index_name_parent_class)->dispose (object);
 }
 
 static void
-camel_index_name_finalise(CamelIndexName *idn)
+index_name_class_init (CamelIndexNameClass *class)
 {
-	if (idn->index)
-		camel_object_unref((CamelObject *)idn->index);
+	GObjectClass *object_class;
+
+	index_name_parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = index_name_dispose;
 }
 
-CamelType
-camel_index_name_get_type(void)
+GType
+camel_index_name_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_object_get_type(), "CamelIndexName",
-					   sizeof (CamelIndexName),
-					   sizeof (CamelIndexNameClass),
-					   (CamelObjectClassInitFunc) camel_index_name_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_index_name_init,
-					   (CamelObjectFinalizeFunc) camel_index_name_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelIndexName",
+			sizeof (CamelIndexNameClass),
+			(GClassInitFunc) index_name_class_init,
+			sizeof (CamelIndexName),
+			(GInstanceInitFunc) NULL,
+			0);
 
 	return type;
 }
 
 CamelIndexName *
-camel_index_name_new(CamelIndex *idx, const gchar *name)
+camel_index_name_new (CamelIndex *idx, const gchar *name)
 {
-	CamelIndexName *idn = (CamelIndexName *)camel_object_new(camel_index_name_get_type());
+	CamelIndexName *idn;
 
-	idn->index = idx;
-	camel_object_ref((CamelObject *)idx);
+	idn = g_object_new (CAMEL_TYPE_INDEX_NAME, NULL);
+	idn->index = g_object_ref (idx);
 
 	return idn;
 }
 
 void
-camel_index_name_add_word(CamelIndexName *idn, const gchar *word)
+camel_index_name_add_word (CamelIndexName *idn,
+                           const gchar *word)
 {
+	CamelIndexNameClass *class;
 	gchar *b = (gchar *)word;
 
+	g_return_if_fail (CAMEL_IS_INDEX_NAME (idn));
+
+	class = CAMEL_INDEX_NAME_GET_CLASS (idn);
+	g_return_if_fail (class->add_word != NULL);
+
 	if (idn->index->normalise)
-		b = idn->index->normalise(idn->index, word, idn->index->normalise_data);
+		b = idn->index->normalise (idn->index, word, idn->index->normalise_data);
 
-	CIN_CLASS(idn)->add_word(idn, b);
+	class->add_word (idn, b);
 
 	if (b != word)
-		g_free(b);
+		g_free (b);
 }
 
 gsize
-camel_index_name_add_buffer(CamelIndexName *idn, const gchar *buffer, gsize len)
+camel_index_name_add_buffer (CamelIndexName *idn,
+                             const gchar *buffer,
+                             gsize len)
 {
-	return CIN_CLASS(idn)->add_buffer(idn, buffer, len);
+	CamelIndexNameClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_INDEX_NAME (idn), 0);
+
+	class = CAMEL_INDEX_NAME_GET_CLASS (idn);
+	g_return_val_if_fail (class->add_buffer != NULL, 0);
+
+	return class->add_buffer (idn, buffer, len);
 }
 
 /* ********************************************************************** */
 /* CamelIndexCursor */
 /* ********************************************************************** */
 
-static CamelObjectClass *camel_index_cursor_parent;
-
-#define CIC_CLASS(o) ((CamelIndexCursorClass *)(((CamelObject *)o)->klass))
+static gpointer index_cursor_parent_class;
 
 static void
-camel_index_cursor_class_init(CamelIndexCursorClass *klass)
+index_cursor_dispose (GObject *object)
 {
-	camel_index_cursor_parent = CAMEL_OBJECT_CLASS(camel_type_get_global_classfuncs(camel_object_get_type()));
-}
+	CamelIndexCursor *index_cursor = CAMEL_INDEX_CURSOR (object);
 
-static void
-camel_index_cursor_init(CamelIndexCursor *idc)
-{
+	if (index_cursor->index != NULL) {
+		g_object_unref (index_cursor->index);
+		index_cursor->index = NULL;
+	}
+
+	/* Chain up to parent's dispose () method. */
+	G_OBJECT_CLASS (index_cursor_parent_class)->dispose (object);
 }
 
 static void
-camel_index_cursor_finalise(CamelIndexCursor *idc)
+index_cursor_class_init (CamelIndexCursorClass *class)
 {
-	if (idc->index)
-		camel_object_unref((CamelObject *)idc->index);
+	GObjectClass *object_class;
+
+	index_cursor_parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = index_cursor_dispose;
 }
 
-CamelType
-camel_index_cursor_get_type(void)
+GType
+camel_index_cursor_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_object_get_type(), "CamelIndexCursor",
-					   sizeof (CamelIndexCursor),
-					   sizeof (CamelIndexCursorClass),
-					   (CamelObjectClassInitFunc) camel_index_cursor_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_index_cursor_init,
-					   (CamelObjectFinalizeFunc) camel_index_cursor_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelIndexCursor",
+			sizeof (CamelIndexCursorClass),
+			(GClassInitFunc) index_cursor_class_init,
+			sizeof (CamelIndexCursor),
+			(GInstanceInitFunc) NULL,
+			0);
 
 	return type;
 }
 
 CamelIndexCursor *
-camel_index_cursor_new(CamelIndex *idx, const gchar *name)
+camel_index_cursor_new (CamelIndex *idx, const gchar *name)
 {
-	CamelIndexCursor *idc = (CamelIndexCursor *)camel_object_new(camel_index_cursor_get_type());
+	CamelIndexCursor *idc;
 
-	idc->index = idx;
-	camel_object_ref((CamelObject *)idx);
+	idc = g_object_new (CAMEL_TYPE_INDEX_CURSOR, NULL);
+	idc->index = g_object_ref (idx);
 
 	return idc;
 }
 
 const gchar *
-camel_index_cursor_next(CamelIndexCursor *idc)
+camel_index_cursor_next (CamelIndexCursor *idc)
 {
-	return CIC_CLASS(idc)->next(idc);
+	CamelIndexCursorClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_INDEX_CURSOR (idc), NULL);
+
+	class = CAMEL_INDEX_CURSOR_GET_CLASS (idc);
+	g_return_val_if_fail (class->next != NULL, NULL);
+
+	return class->next (idc);
 }
 
 void
-camel_index_cursor_reset(CamelIndexCursor *idc)
+camel_index_cursor_reset (CamelIndexCursor *idc)
 {
-	CIC_CLASS(idc)->reset(idc);
-}
+	CamelIndexCursorClass *class;
 
+	g_return_if_fail (CAMEL_IS_INDEX_CURSOR (idc));
+
+	class = CAMEL_INDEX_CURSOR_GET_CLASS (idc);
+	g_return_if_fail (class->reset != NULL);
+
+	class->reset (idc);
+}
diff --git a/camel/camel-index.h b/camel/camel-index.h
index 7b074f4..78c6995 100644
--- a/camel/camel-index.h
+++ b/camel/camel-index.h
@@ -18,34 +18,84 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_INDEX_H
-#define _CAMEL_INDEX_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_INDEX_H
+#define CAMEL_INDEX_H
 
 #include <camel/camel-exception.h>
 #include <camel/camel-object.h>
 
-#define CAMEL_INDEX(obj)         CAMEL_CHECK_CAST (obj, camel_index_get_type (), CamelIndex)
-#define CAMEL_INDEX_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_get_type (), CamelIndexClass)
-#define CAMEL_IS_INDEX(obj)      CAMEL_CHECK_TYPE (obj, camel_index_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_INDEX \
+	(camel_index_get_type ())
+#define CAMEL_INDEX(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_INDEX, CamelIndex))
+#define CAMEL_INDEX_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_INDEX, CamelIndexClass))
+#define CAMEL_IS_INDEX(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_INDEX))
+#define CAMEL_IS_INDEX_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_INDEX))
+#define CAMEL_INDEX_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_INDEX, CamelIndexClass))
+
+#define CAMEL_TYPE_INDEX_NAME \
+	(camel_index_name_get_type ())
+#define CAMEL_INDEX_NAME(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_INDEX_NAME, CamelIndexName))
+#define CAMEL_INDEX_NAME_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_INDEX_NAME, CamelIndexNameClass))
+#define CAMEL_IS_INDEX_NAME(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_INDEX_NAME))
+#define CAMEL_IS_INDEX_NAME_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_INDEX_NAME))
+#define CAMEL_INDEX_NAME_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_INDEX_NAME, CamelIndexNameClass))
+
+#define CAMEL_TYPE_INDEX_CURSOR \
+	(camel_index_cursor_get_type ())
+#define CAMEL_INDEX_CURSOR(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_INDEX_CURSOR, CamelIndexCursor))
+#define CAMEL_INDEX_CURSOR_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_INDEX_CURSOR, CamelIndexCursorClass))
+#define CAMEL_IS_INDEX_CURSOR(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_INDEX_CURSOR))
+#define CAMEL_IS_INDEX_CURSOR_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_INDEX_CURSOR))
+#define CAMEL_INDEX_CURSOR_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_INDEX_CURSOR, CamelIndexCursorClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelIndex      CamelIndex;
+typedef struct _CamelIndex CamelIndex;
 typedef struct _CamelIndexClass CamelIndexClass;
+typedef struct _CamelIndexPrivate CamelIndexPrivate;
 
-#define CAMEL_INDEX_NAME(obj)         CAMEL_CHECK_CAST (obj, camel_index_name_get_type (), CamelIndexName)
-#define CAMEL_INDEX_NAME_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_name_get_type (), CamelIndexNameClass)
-#define CAMEL_IS_INDEX_NAME(obj)      CAMEL_CHECK_TYPE (obj, camel_index_name_get_type ())
-
-typedef struct _CamelIndexName      CamelIndexName;
+typedef struct _CamelIndexName CamelIndexName;
 typedef struct _CamelIndexNameClass CamelIndexNameClass;
+typedef struct _CamelIndexNamePrivate CamelIndexNamePrivate;
 
-#define CAMEL_INDEX_CURSOR(obj)         CAMEL_CHECK_CAST (obj, camel_index_cursor_get_type (), CamelIndexCursor)
-#define CAMEL_INDEX_CURSOR_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_index_cursor_get_type (), CamelIndexCursorClass)
-#define CAMEL_IS_INDEX_CURSOR(obj)      CAMEL_CHECK_TYPE (obj, camel_index_cursor_get_type ())
-
-typedef struct _CamelIndexCursor      CamelIndexCursor;
+typedef struct _CamelIndexCursor CamelIndexCursor;
 typedef struct _CamelIndexCursorClass CamelIndexCursorClass;
+typedef struct _CamelIndexCursorPrivate CamelIndexCursorPrivate;
 
 typedef gchar * (*CamelIndexNorm)(CamelIndex *idx, const gchar *word, gpointer data);
 
@@ -53,8 +103,7 @@ typedef gchar * (*CamelIndexNorm)(CamelIndex *idx, const gchar *word, gpointer d
 
 struct _CamelIndexCursor {
 	CamelObject parent;
-
-	struct _CamelIndexCursorPrivate *priv;
+	CamelIndexCursorPrivate *priv;
 
 	CamelIndex *index;
 };
@@ -66,7 +115,7 @@ struct _CamelIndexCursorClass {
 	void         (*reset) (CamelIndexCursor *idc);
 };
 
-CamelType		   camel_index_cursor_get_type(void);
+GType           camel_index_cursor_get_type(void);
 
 CamelIndexCursor  *camel_index_cursor_new(CamelIndex *idx, const gchar *name);
 
@@ -77,8 +126,7 @@ void               camel_index_cursor_reset(CamelIndexCursor *idc);
 
 struct _CamelIndexName {
 	CamelObject parent;
-
-	struct _CamelIndexNamePrivate *priv;
+	CamelIndexNamePrivate *priv;
 
 	CamelIndex *index;
 
@@ -96,7 +144,7 @@ struct _CamelIndexNameClass {
 	gsize (*add_buffer)(CamelIndexName *name, const gchar *buffer, gsize len);
 };
 
-CamelType		   camel_index_name_get_type	(void);
+GType           camel_index_name_get_type	(void);
 
 CamelIndexName    *camel_index_name_new(CamelIndex *idx, const gchar *name);
 
@@ -107,8 +155,7 @@ gsize             camel_index_name_add_buffer(CamelIndexName *name, const gchar
 
 struct _CamelIndex {
 	CamelObject parent;
-
-	struct _CamelIndexPrivate *priv;
+	CamelIndexPrivate *priv;
 
 	gchar *path;
 	guint32 version;
@@ -142,17 +189,17 @@ struct _CamelIndexClass {
 /* flags, stored in 'state', set with set_state */
 #define CAMEL_INDEX_DELETED (1<<0)
 
-CamelType		   camel_index_get_type	(void);
+GType              camel_index_get_type	(void);
 
 CamelIndex        *camel_index_new(const gchar *path, gint flags);
 void               camel_index_construct(CamelIndex *, const gchar *path, gint flags);
-gint		   camel_index_rename(CamelIndex *, const gchar *path);
+gint               camel_index_rename(CamelIndex *, const gchar *path);
 
 void               camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm func, gpointer data);
 
 gint                camel_index_sync(CamelIndex *idx);
 gint                camel_index_compress(CamelIndex *idx);
-gint		   camel_index_delete(CamelIndex *idx);
+gint                camel_index_delete(CamelIndex *idx);
 
 gint                camel_index_has_name(CamelIndex *idx, const gchar *name);
 CamelIndexName    *camel_index_add_name(CamelIndex *idx, const gchar *name);
@@ -166,4 +213,4 @@ CamelIndexCursor  *camel_index_names(CamelIndex *idx);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_INDEX_H */
+#endif /* CAMEL_INDEX_H */
diff --git a/camel/camel-internet-address.c b/camel/camel-internet-address.c
index 34ed78a..68d10ee 100644
--- a/camel/camel-internet-address.c
+++ b/camel/camel-internet-address.c
@@ -26,63 +26,15 @@
 
 #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, const 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 {
 	gchar *name;
 	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 gpointer parent_class;
 
 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, const CamelAddress *source)
+internet_address_cat (CamelAddress *dest, CamelAddress *source)
 {
 	gint i;
 
@@ -254,18 +221,37 @@ internet_cat (CamelAddress *dest, const CamelAddress *source)
 }
 
 static void
-internet_remove	(CamelAddress *a, gint index)
+internet_address_class_init (CamelInternetAddressClass *class)
 {
-	struct _address *addr;
+	CamelAddressClass *address_class;
 
-	if (index < 0 || index >= a->addresses->len)
-		return;
+	parent_class = g_type_class_peek_parent (class);
 
-	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;
+}
+
+GType
+camel_internet_address_get_type(void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_ADDRESS,
+			"CamelInternetAddress",
+			sizeof (CamelInternetAddressClass),
+			(GClassInitFunc) internet_address_class_init,
+			sizeof (CamelInternetAddress),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 /**
@@ -278,8 +264,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 g_object_new (CAMEL_TYPE_INTERNET_ADDRESS, NULL);
 }
 
 /**
diff --git a/camel/camel-internet-address.h b/camel/camel-internet-address.h
index c214c9a..6ea1ce6 100644
--- a/camel/camel-internet-address.h
+++ b/camel/camel-internet-address.h
@@ -19,30 +19,50 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_INTERNET_ADDRESS_H
-#define _CAMEL_INTERNET_ADDRESS_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_INTERNET_ADDRESS_H
+#define CAMEL_INTERNET_ADDRESS_H
 
 #include <camel/camel-address.h>
 
-#define CAMEL_INTERNET_ADDRESS(obj)         CAMEL_CHECK_CAST (obj, camel_internet_address_get_type (), CamelInternetAddress)
-#define CAMEL_INTERNET_ADDRESS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_internet_address_get_type (), CamelInternetAddressClass)
-#define CAMEL_IS_INTERNET_ADDRESS(obj)      CAMEL_CHECK_TYPE (obj, camel_internet_address_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_INTERNET_ADDRESS \
+	(camel_internet_address_get_type ())
+#define CAMEL_INTERNET_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_INTERNET_ADDRESS, CamelInternetAddress))
+#define CAMEL_INTERNET_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_INTERNET_ADDRESS, CamelInternetAddressClass))
+#define CAMEL_IS_INTERNET_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_INTERNET_ADDRESS))
+#define CAMEL_IS_INTERNET_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_INTERNET_ADDRESS))
+#define CAMEL_INTERNET_ADDRESS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_INTERNET_ADDRESS, CamelInternetAddressClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelInternetAddress CamelInternetAddress;
 typedef struct _CamelInternetAddressClass CamelInternetAddressClass;
+typedef struct _CamelInternetAddressPrivate CamelInternetAddressPrivate;
 
 struct _CamelInternetAddress {
 	CamelAddress parent;
-
-	struct _CamelInternetAddressPrivate *priv;
+	CamelInternetAddressPrivate *priv;
 };
 
 struct _CamelInternetAddressClass {
 	CamelAddressClass parent_class;
 };
 
-CamelType		camel_internet_address_get_type	(void);
+GType		camel_internet_address_get_type	(void);
 CamelInternetAddress   *camel_internet_address_new	(void);
 
 gint			camel_internet_address_add	(CamelInternetAddress *addr, const gchar *name, const gchar *address);
@@ -57,4 +77,4 @@ gchar *			camel_internet_address_format_address(const gchar *name, const gchar *
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_INTERNET_ADDRESS_H */
+#endif /* CAMEL_INTERNET_ADDRESS_H */
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-junk-plugin.h b/camel/camel-junk-plugin.h
index 82924f1..da14ec1 100644
--- a/camel/camel-junk-plugin.h
+++ b/camel/camel-junk-plugin.h
@@ -20,8 +20,12 @@
  * USA
  */
 
-#ifndef _CAMEL_JUNK_PLUGIN_H
-#define _CAMEL_JUNK_PLUGIN_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_JUNK_PLUGIN_H
+#define CAMEL_JUNK_PLUGIN_H
 
 #define CAMEL_JUNK_PLUGIN(x) ((CamelJunkPlugin *) x)
 
diff --git a/camel/camel-list-utils.h b/camel/camel-list-utils.h
index a30b1f3..d04ac25 100644
--- a/camel/camel-list-utils.h
+++ b/camel/camel-list-utils.h
@@ -19,8 +19,12 @@
  *
  */
 
-#ifndef _CAMEL_LIST_UTILS_H
-#define _CAMEL_LIST_UTILS_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_LIST_UTILS_H
+#define CAMEL_LIST_UTILS_H
 
 #include <glib.h>
 
diff --git a/camel/camel-lock-client.c b/camel/camel-lock-client.c
index 5c9bf8a..0b5693e 100644
--- a/camel/camel-lock-client.c
+++ b/camel/camel-lock-client.c
@@ -90,7 +90,7 @@ 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;
 
@@ -162,7 +162,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;
 		}
@@ -313,7 +313,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-client.h b/camel/camel-lock-client.h
index a343326..642d7f6 100644
--- a/camel/camel-lock-client.h
+++ b/camel/camel-lock-client.h
@@ -21,8 +21,12 @@
 
 /* defines protocol for lock helper process ipc */
 
-#ifndef _CAMEL_LOCK_CLIENT_H
-#define _CAMEL_LOCK_CLIENT_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_LOCK_CLIENT_H
+#define CAMEL_LOCK_CLIENT_H
 
 #include <camel/camel-exception.h>
 
@@ -33,4 +37,4 @@ gint camel_lock_helper_unlock(gint lockid);
 
 G_END_DECLS
 
-#endif /* !_CAMEL_LOCK_HELPER_H */
+#endif /* !CAMEL_LOCK_HELPER_H */
diff --git a/camel/camel-lock-helper.h b/camel/camel-lock-helper.h
index 4fb495d..e58ace5 100644
--- a/camel/camel-lock-helper.h
+++ b/camel/camel-lock-helper.h
@@ -21,8 +21,12 @@
 
 /* defines protocol for lock helper process ipc */
 
-#ifndef _CAMEL_LOCK_HELPER_H
-#define _CAMEL_LOCK_HELPER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_LOCK_HELPER_H
+#define CAMEL_LOCK_HELPER_H
 
 #include <glib.h>
 
@@ -61,4 +65,4 @@ enum {
 
 G_END_DECLS
 
-#endif /* !_CAMEL_LOCK_HELPER_H */
+#endif /* !CAMEL_LOCK_HELPER_H */
diff --git a/camel/camel-lock.c b/camel/camel-lock.c
index 7ebd3cc..9da38fe 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>
 
diff --git a/camel/camel-lock.h b/camel/camel-lock.h
index 1fa23a1..e5260d6 100644
--- a/camel/camel-lock.h
+++ b/camel/camel-lock.h
@@ -19,8 +19,12 @@
  * USA
  */
 
-#ifndef _CAMEL_LOCK_H
-#define _CAMEL_LOCK_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_LOCK_H
+#define CAMEL_LOCK_H
 
 #include <camel/camel-exception.h>
 
@@ -55,4 +59,4 @@ void camel_unlock_folder(const gchar *path, gint fd);
 
 G_END_DECLS
 
-#endif /* !_CAMEL_LOCK_H */
+#endif /* !CAMEL_LOCK_H */
diff --git a/camel/camel-medium.c b/camel/camel-medium.c
index 5959058..5558c33 100644
--- a/camel/camel-medium.c
+++ b/camel/camel-medium.c
@@ -33,95 +33,159 @@
 
 #define d(x)
 
-static CamelDataWrapperClass *parent_class = NULL;
+#define CAMEL_MEDIUM_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MEDIUM, CamelMediumPrivate))
 
-/* Returns the class for a CamelMedium */
-#define CM_CLASS(so) CAMEL_MEDIUM_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
-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);
+struct _CamelMediumPrivate {
+	/* The content of the medium, as opposed to our parent
+	 * CamelDataWrapper, which wraps both the headers and
+	 * the content. */
+	CamelDataWrapper *content;
+};
 
-static GArray *get_headers (CamelMedium *medium);
-static void free_headers (CamelMedium *medium, GArray *headers);
+enum {
+	PROP_0,
+	PROP_CONTENT
+};
 
-static CamelDataWrapper *get_content_object (CamelMedium *medium);
-static void set_content_object (CamelMedium *medium,
-				CamelDataWrapper *content);
+static void
+medium_set_property (GObject *object,
+                     guint property_id,
+                     const GValue *value,
+                     GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_CONTENT:
+			camel_medium_set_content (
+				CAMEL_MEDIUM (object),
+				g_value_get_object (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
 
 static void
-camel_medium_class_init (CamelMediumClass *camel_medium_class)
+medium_get_property (GObject *object,
+                     guint property_id,
+                     GValue *value,
+                     GParamSpec *pspec)
 {
-	CamelDataWrapperClass *camel_data_wrapper_class =
-		CAMEL_DATA_WRAPPER_CLASS (camel_medium_class);
+	switch (property_id) {
+		case PROP_CONTENT:
+			g_value_set_object (
+				value, camel_medium_get_content (
+				CAMEL_MEDIUM (object)));
+			return;
+	}
 
-	parent_class = CAMEL_DATA_WRAPPER_CLASS (camel_type_get_global_classfuncs (camel_data_wrapper_get_type ()));
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
 
-	/* virtual method overload */
-	camel_data_wrapper_class->is_offline = is_offline;
+static void
+medium_dispose (GObject *object)
+{
+	CamelMediumPrivate *priv;
 
-	/* 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;
+	priv = CAMEL_MEDIUM_GET_PRIVATE (object);
 
-	camel_medium_class->get_headers = get_headers;
-	camel_medium_class->free_headers = free_headers;
+	if (priv->content != NULL) {
+		g_object_unref (priv->content);
+		priv->content = NULL;
+	}
 
-	camel_medium_class->set_content_object = set_content_object;
-	camel_medium_class->get_content_object = get_content_object;
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
-static void
-camel_medium_init (gpointer object, gpointer klass)
+static gboolean
+medium_is_offline (CamelDataWrapper *data_wrapper)
 {
-	CamelMedium *camel_medium = CAMEL_MEDIUM (object);
+	CamelDataWrapper *content;
 
-	camel_medium->content = NULL;
+	content = camel_medium_get_content (CAMEL_MEDIUM (data_wrapper));
+
+	return CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper)->is_offline (data_wrapper) ||
+		camel_data_wrapper_is_offline (content);
 }
 
 static void
-camel_medium_finalize (CamelObject *object)
+medium_set_content (CamelMedium *medium,
+                    CamelDataWrapper *content)
 {
-	CamelMedium *medium = CAMEL_MEDIUM (object);
+	if (content != NULL)
+		g_object_ref (content);
+
+	if (medium->priv->content != NULL)
+		g_object_unref (medium->priv->content);
+
+	medium->priv->content = content;
 
-	if (medium->content)
-		camel_object_unref (medium->content);
+	g_object_notify (G_OBJECT (medium), "content");
 }
 
-CamelType
-camel_medium_get_type (void)
+static CamelDataWrapper *
+medium_get_content (CamelMedium *medium)
 {
-	static CamelType camel_medium_type = CAMEL_INVALID_TYPE;
-
-	if (camel_medium_type == CAMEL_INVALID_TYPE) {
-		camel_medium_type = camel_type_register (CAMEL_DATA_WRAPPER_TYPE, "medium",
-							 sizeof (CamelMedium),
-							 sizeof (CamelMediumClass),
-							 (CamelObjectClassInitFunc) camel_medium_class_init,
-							 NULL,
-							 (CamelObjectInitFunc) camel_medium_init,
-							 (CamelObjectFinalizeFunc) camel_medium_finalize);
-	}
-
-	return camel_medium_type;
+	return medium->priv->content;
 }
 
-static gboolean
-is_offline (CamelDataWrapper *data_wrapper)
+static void
+medium_class_init (CamelMediumClass *class)
 {
-	return parent_class->is_offline (data_wrapper) ||
-		camel_data_wrapper_is_offline (CAMEL_MEDIUM (data_wrapper)->content);
+	GObjectClass *object_class;
+	CamelDataWrapperClass *data_wrapper_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMediumPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = medium_set_property;
+	object_class->get_property = medium_get_property;
+	object_class->dispose = medium_dispose;
+
+	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;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_CONTENT,
+		g_param_spec_object (
+			"content",
+			"Content",
+			NULL,
+			CAMEL_TYPE_DATA_WRAPPER,
+			G_PARAM_READWRITE));
 }
 
 static void
-add_header (CamelMedium *medium, const gchar *name, gconstpointer value)
+medium_init (CamelMedium *medium)
+{
+	medium->priv = CAMEL_MEDIUM_GET_PRIVATE (medium);
+}
+
+GType
+camel_medium_get_type (void)
 {
-	g_warning("No %s::add_header implemented, adding %s", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium)), name);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_DATA_WRAPPER,
+			"CamelMedium",
+			sizeof (CamelMediumClass),
+			(GClassInitFunc) medium_class_init,
+			sizeof (CamelMedium),
+			(GInstanceInitFunc) medium_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -133,19 +197,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 +224,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 +253,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 +282,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 +309,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,22 +329,22 @@ 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_object(CamelMedium *medium)
-{
-	return medium->content;
+	class->free_headers (medium, headers);
 }
 
 /**
- * camel_medium_get_content_object:
+ * camel_medium_get_content:
  * @medium: a #CamelMedium object
  *
  * Gets a data wrapper that represents the content of the medium,
@@ -288,35 +353,38 @@ get_content_object(CamelMedium *medium)
  * Returns: a #CamelDataWrapper containing @medium's content. Can return NULL.
  **/
 CamelDataWrapper *
-camel_medium_get_content_object (CamelMedium *medium)
+camel_medium_get_content (CamelMedium *medium)
 {
+	CamelMediumClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), NULL);
 
-	return CM_CLASS (medium)->get_content_object (medium);
-}
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_val_if_fail (class->get_content != NULL, NULL);
 
-static void
-set_content_object (CamelMedium *medium, CamelDataWrapper *content)
-{
-	if (medium->content)
-		camel_object_unref (medium->content);
-	camel_object_ref (content);
-	medium->content = content;
+	return class->get_content (medium);
 }
 
 /**
- * camel_medium_set_content_object:
+ * camel_medium_set_content:
  * @medium: a #CamelMedium object
  * @content: a #CamelDataWrapper object
  *
  * Sets the content of @medium to be @content.
  **/
 void
-camel_medium_set_content_object (CamelMedium *medium,
-				 CamelDataWrapper *content)
+camel_medium_set_content (CamelMedium *medium,
+                          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_object (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 096d67d..6a04943 100644
--- a/camel/camel-medium.h
+++ b/camel/camel-medium.h
@@ -23,34 +23,51 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MEDIUM_H
-#define CAMEL_MEDIUM_H 1
+#define CAMEL_MEDIUM_H
 
 #include <camel/camel-data-wrapper.h>
 
-#define CAMEL_MEDIUM_TYPE     (camel_medium_get_type ())
-#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))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MEDIUM \
+	(camel_medium_get_type ())
+#define CAMEL_MEDIUM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MEDIUM, CamelMedium))
+#define CAMEL_MEDIUM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MEDIUM, CamelMediumClass))
+#define CAMEL_IS_MEDIUM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MEDIUM))
+#define CAMEL_IS_MEDIUM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MEDIUM))
+#define CAMEL_MEDIUM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MEDIUM, CamelMediumClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMedium CamelMedium;
+typedef struct _CamelMediumClass CamelMediumClass;
+typedef struct _CamelMediumPrivate CamelMediumPrivate;
+
 typedef struct {
 	const gchar *name;
 	const gchar *value;
 } CamelMediumHeader;
 
 struct _CamelMedium {
-	CamelDataWrapper parent_object;
-
-	/* The content of the medium, as opposed to our parent
-	 * CamelDataWrapper, which wraps both the headers and the
-	 * content.
-	 */
-	CamelDataWrapper *content;
+	CamelDataWrapper parent;
+	CamelMediumPrivate *priv;
 };
 
-typedef struct {
+struct _CamelMediumClass {
 	CamelDataWrapperClass parent_class;
 
 	/* Virtual methods */
@@ -62,12 +79,11 @@ typedef struct {
 	GArray * (*get_headers) (CamelMedium *medium);
 	void (*free_headers) (CamelMedium *medium, GArray *headers);
 
-	CamelDataWrapper * (*get_content_object) (CamelMedium *medium);
-	void (*set_content_object) (CamelMedium *medium, CamelDataWrapper *content);
-} CamelMediumClass;
+	CamelDataWrapper * (*get_content) (CamelMedium *medium);
+	void (*set_content) (CamelMedium *medium, CamelDataWrapper *content);
+};
 
-/* Standard Camel function */
-CamelType camel_medium_get_type (void);
+GType camel_medium_get_type (void);
 
 /* Header get/set interface */
 void camel_medium_add_header (CamelMedium *medium, const gchar *name, gconstpointer value);
@@ -79,9 +95,9 @@ GArray *camel_medium_get_headers (CamelMedium *medium);
 void camel_medium_free_headers (CamelMedium *medium, GArray *headers);
 
 /* accessor methods */
-CamelDataWrapper *camel_medium_get_content_object (CamelMedium *medium);
-void camel_medium_set_content_object (CamelMedium *medium,
-				      CamelDataWrapper *content);
+CamelDataWrapper *camel_medium_get_content (CamelMedium *medium);
+void camel_medium_set_content (CamelMedium *medium,
+			       CamelDataWrapper *content);
 
 G_END_DECLS
 
diff --git a/camel/camel-mime-filter-basic.c b/camel/camel-mime-filter-basic.c
index 97bd9e9..b84a10b 100644
--- a/camel/camel-mime-filter-basic.c
+++ b/camel/camel-mime-filter-basic.c
@@ -24,128 +24,117 @@
 #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);
+#define CAMEL_MIME_FILTER_BASIC_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_BASIC, CamelMimeFilterBasicPrivate))
 
-static void camel_mime_filter_basic_class_init (CamelMimeFilterBasicClass *klass);
-static void camel_mime_filter_basic_init       (CamelMimeFilterBasic *obj);
+struct _CamelMimeFilterBasicPrivate {
+	CamelMimeFilterBasicType type;
+	guchar uubuf[60];
+	gint state;
+	gint save;
+};
 
-static CamelMimeFilterClass *camel_mime_filter_basic_parent;
+static gpointer parent_class;
 
+/* here we do all of the basic mime filtering */
 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;
-}
-
-static void
-camel_mime_filter_basic_init (CamelMimeFilterBasic *obj)
-{
-	obj->state = 0;
-	obj->save = 0;
-}
-
-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? */
-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_GET_PRIVATE (mime_filter);
 
-	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 +143,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_GET_PRIVATE (mime_filter);
 
-	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,18 +215,60 @@ donothing:
 	*outprespace = prespace;
 }
 
-/**
- * camel_mime_filter_basic_new:
- *
- * Create a new #CamelMimeFilterBasic object.
- *
- * Returns: a new #CamelMimeFilterBasic object
- **/
-CamelMimeFilterBasic *
-camel_mime_filter_basic_new (void)
+/* should this 'flush' outstanding state/data bytes? */
+static void
+mime_filter_basic_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterBasic *new = CAMEL_MIME_FILTER_BASIC ( camel_object_new (camel_mime_filter_basic_get_type ()));
-	return new;
+	CamelMimeFilterBasicPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_BASIC_GET_PRIVATE (mime_filter);
+
+	switch (priv->type) {
+	case CAMEL_MIME_FILTER_BASIC_QP_ENC:
+		priv->state = -1;
+		break;
+	default:
+		priv->state = 0;
+	}
+	priv->save = 0;
+}
+
+static void
+mime_filter_basic_class_init (CamelMimeFilterBasicClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterBasicPrivate));
+
+	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
+mime_filter_basic_init (CamelMimeFilterBasic *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_BASIC_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_basic_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterBasic",
+			sizeof (CamelMimeFilterBasicClass),
+			(GClassInitFunc) mime_filter_basic_class_init,
+			sizeof (CamelMimeFilterBasic),
+			(GInstanceInitFunc) mime_filter_basic_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -274,10 +279,10 @@ camel_mime_filter_basic_new (void)
  *
  * Returns: a new #CamelMimeFilterBasic object
  **/
-CamelMimeFilterBasic *
-camel_mime_filter_basic_new_type(CamelMimeFilterBasicType type)
+CamelMimeFilter *
+camel_mime_filter_basic_new (CamelMimeFilterBasicType type)
 {
-	CamelMimeFilterBasic *new;
+	CamelMimeFilter *new;
 
 	switch (type) {
 	case CAMEL_MIME_FILTER_BASIC_BASE64_ENC:
@@ -286,15 +291,16 @@ camel_mime_filter_basic_new_type(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();
-		new->type = type;
+		new = g_object_new (CAMEL_TYPE_MIME_FILTER_BASIC, NULL);
+		CAMEL_MIME_FILTER_BASIC (new)->priv->type = type;
 		break;
 	default:
 		g_warning ("Invalid type of CamelMimeFilterBasic requested: %u", type);
 		new = NULL;
 		break;
 	}
-	camel_mime_filter_reset((CamelMimeFilter *)new);
+	camel_mime_filter_reset (new);
+
 	return new;
 }
 
diff --git a/camel/camel-mime-filter-basic.h b/camel/camel-mime-filter-basic.h
index 1a77993..53d1e76 100644
--- a/camel/camel-mime-filter-basic.h
+++ b/camel/camel-mime-filter-basic.h
@@ -19,18 +19,39 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_BASIC_H
-#define _CAMEL_MIME_FILTER_BASIC_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_BASIC_H
+#define CAMEL_MIME_FILTER_BASIC_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_BASIC(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_basic_get_type (), CamelMimeFilterBasic)
-#define CAMEL_MIME_FILTER_BASIC_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_basic_get_type (), CamelMimeFilterBasicClass)
-#define CAMEL_IS_MIME_FILTER_BASIC(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_basic_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_BASIC \
+	(camel_mime_filter_basic_get_type ())
+#define CAMEL_MIME_FILTER_BASIC(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_BASIC, CamelMimeFilterBasic))
+#define CAMEL_MIME_FILTER_BASIC_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_BASIC, CamelMimeFilterBasicClass))
+#define CAMEL_IS_MIME_FILTER_BASIC(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_BASIC))
+#define CAMEL_IS_MIME_FILTER_BASIC_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_BASIC))
+#define CAMEL_MIME_FILTER_BASIC_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_BASIC, CamelMimeFilterBasicClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMimeFilterBasic CamelMimeFilterBasic;
 typedef struct _CamelMimeFilterBasicClass CamelMimeFilterBasicClass;
+typedef struct _CamelMimeFilterBasicPrivate CamelMimeFilterBasicPrivate;
 
 typedef enum {
 	CAMEL_MIME_FILTER_BASIC_BASE64_ENC = 1,
@@ -43,24 +64,17 @@ typedef enum {
 
 struct _CamelMimeFilterBasic {
 	CamelMimeFilter parent;
-
-	struct _CamelMimeFilterBasicPrivate *priv;
-
-	CamelMimeFilterBasicType type;
-
-	guchar uubuf[60];
-	gint state;
-	gint save;
+	CamelMimeFilterBasicPrivate *priv;
 };
 
 struct _CamelMimeFilterBasicClass {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType		camel_mime_filter_basic_get_type	(void);
-CamelMimeFilterBasic      *camel_mime_filter_basic_new	(void);
-CamelMimeFilterBasic      *camel_mime_filter_basic_new_type	(CamelMimeFilterBasicType type);
+GType		camel_mime_filter_basic_get_type(void);
+CamelMimeFilter *
+		camel_mime_filter_basic_new	(CamelMimeFilterBasicType type);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_BASIC_H */
+#endif /* CAMEL_MIME_FILTER_BASIC_H */
diff --git a/camel/camel-mime-filter-bestenc.c b/camel/camel-mime-filter-bestenc.c
index 08930d5..7fe9673 100644
--- a/camel/camel-mime-filter-bestenc.c
+++ b/camel/camel-mime-filter-bestenc.c
@@ -27,78 +27,74 @@
 
 #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);
+#define CAMEL_MIME_FILTER_BESTENC_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_BESTENC, CamelMimeFilterBestencPrivate))
 
-static CamelMimeFilterClass *camel_mime_filter_bestenc_parent;
+struct _CamelMimeFilterBestencPrivate {
 
-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,
-					    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 */
 
-static void
-reset(CamelMimeFilter *mf)
-{
-	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);
-}
+	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 gpointer parent_class;
 
 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_GET_PRIVATE (mime_filter);
+
 	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 +110,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 +159,84 @@ 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_GET_PRIVATE (mime_filter);
+
+	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;
+
+	priv = CAMEL_MIME_FILTER_BESTENC_GET_PRIVATE (mime_filter);
 
-	filter(mf, in, len, prespace, out, outlen, outprespace);
+	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;
 
-	if (f->countline > f->maxline)
-		f->maxline = f->countline;
-	f->countline = 0;
+	camel_charset_init(&priv->charset);
 }
 
 static void
-camel_mime_filter_bestenc_class_init (CamelMimeFilterBestencClass *klass)
+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 ()));
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterBestencPrivate));
 
-	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)
+mime_filter_bestenc_init (CamelMimeFilterBestenc *filter)
 {
-	reset(f);
+	filter->priv = CAMEL_MIME_FILTER_BESTENC_GET_PRIVATE (filter);
+
+	mime_filter_bestenc_reset (CAMEL_MIME_FILTER (filter));
+}
+
+GType
+camel_mime_filter_bestenc_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterBestenc",
+			sizeof (CamelMimeFilterBestencClass),
+			(GClassInitFunc) mime_filter_bestenc_class_init,
+			sizeof (CamelMimeFilterBestenc),
+			(GInstanceInitFunc) mime_filter_bestenc_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -200,11 +247,14 @@ camel_mime_filter_bestenc_init (CamelMimeFilter *f)
  *
  * Returns: a new #CamelMimeFilterBestenc object
  **/
-CamelMimeFilterBestenc *
+CamelMimeFilter *
 camel_mime_filter_bestenc_new (guint flags)
 {
-	CamelMimeFilterBestenc *new = (CamelMimeFilterBestenc *)camel_object_new(camel_mime_filter_bestenc_get_type());
-	new->flags = flags;
+	CamelMimeFilter *new;
+
+	new = g_object_new (CAMEL_TYPE_MIME_FILTER_BESTENC, NULL);
+	CAMEL_MIME_FILTER_BESTENC (new)->priv->flags = flags;
+
 	return new;
 }
 
@@ -219,40 +269,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_GET_PRIVATE (filter);
+
 	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 +316,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 +336,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 +349,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 2fa499a..2171f69 100644
--- a/camel/camel-mime-filter-bestenc.h
+++ b/camel/camel-mime-filter-bestenc.h
@@ -19,20 +19,41 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_BESTENC_H
-#define _CAMEL_MIME_FILTER_BESTENC_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_BESTENC_H
+#define CAMEL_MIME_FILTER_BESTENC_H
 
 #include <camel/camel-mime-filter.h>
 #include <camel/camel-mime-part.h>
 #include <camel/camel-charset-map.h>
 
-#define CAMEL_MIME_FILTER_BESTENC(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_bestenc_get_type (), CamelMimeFilterBestenc)
-#define CAMEL_MIME_FILTER_BESTENC_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_bestenc_get_type (), CamelMimeFilterBestencClass)
-#define CAMEL_IS_MIME_FILTER_BESTENC(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_bestenc_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_BESTENC \
+	(camel_mime_filter_bestenc_get_type ())
+#define CAMEL_MIME_FILTER_BESTENC(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_BESTENC, CamelMimeFilterBestenc))
+#define CAMEL_MIME_FILTER_BESTENC_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_BESTENC, CamelMimeFilterBestencClass))
+#define CAMEL_IS_MIME_FILTER_BESTENC(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_BESTENC))
+#define CAMEL_IS_MIME_FILTER_BESTENC_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_BESTENC))
+#define CAMEL_MIME_FILTER_BESTENC_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_BESTENC, CamelMimeFilterBestencClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMimeFilterBestenc CamelMimeFilterBestenc;
 typedef struct _CamelMimeFilterBestencClass CamelMimeFilterBestencClass;
+typedef struct _CamelMimeFilterBestencPrivate CamelMimeFilterBestencPrivate;
 
 typedef enum _CamelBestencRequired {
 	CAMEL_BESTENC_GET_ENCODING = 1<<0,
@@ -55,39 +76,26 @@ 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 {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType		camel_mime_filter_bestenc_get_type	(void);
-CamelMimeFilterBestenc      *camel_mime_filter_bestenc_new	(guint flags);
-
-CamelTransferEncoding	camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *filter, CamelBestencEncoding required);
-const gchar *		camel_mime_filter_bestenc_get_best_charset(CamelMimeFilterBestenc *filter);
-void			camel_mime_filter_bestenc_set_flags(CamelMimeFilterBestenc *filter, guint flags);
+GType		camel_mime_filter_bestenc_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_bestenc_new	(guint flags);
+CamelTransferEncoding
+		camel_mime_filter_bestenc_get_best_encoding
+						(CamelMimeFilterBestenc *filter,
+						 CamelBestencEncoding required);
+const gchar *	camel_mime_filter_bestenc_get_best_charset
+						(CamelMimeFilterBestenc *filter);
+void		camel_mime_filter_bestenc_set_flags
+						(CamelMimeFilterBestenc *filter,
+						 guint flags);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_BESTENC_H */
+#endif /* CAMEL_MIME_FILTER_BESTENC_H */
diff --git a/camel/camel-mime-filter-canon.c b/camel/camel-mime-filter-canon.c
index ebe9ec6..7894b5f 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);
+#define CAMEL_MIME_FILTER_CANON_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_CANON, CamelMimeFilterCanonPrivate))
 
-static void
-camel_mime_filter_canon_class_init (CamelMimeFilterCanonClass *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_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);
-	}
+struct _CamelMimeFilterCanonPrivate {
+	guint32 flags;
+};
 
-	return type;
-}
+static gpointer parent_class;
 
 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_GET_PRIVATE (mime_filter);
 
 	/* 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,88 @@ 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
+mime_filter_canon_class_init (CamelMimeFilterCanonClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterCanonPrivate));
+
+	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
+mime_filter_canon_init (CamelMimeFilterCanon *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_CANON_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_canon_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER, "CamelMimeFilterCanon",
+			sizeof (CamelMimeFilterCanonClass),
+			(GClassInitFunc) mime_filter_canon_class_init,
+			sizeof (CamelMimeFilterCanon),
+			(GInstanceInitFunc) mime_filter_canon_init,
+			0);
+
+	return type;
+}
+
 /**
  * camel_mime_filter_canon_new:
  * @flags: bitwise flags defining the behaviour of the filter
@@ -189,9 +225,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 = g_object_new (CAMEL_TYPE_MIME_FILTER_CANON, NULL);
+	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 af931d2..8587c7e 100644
--- a/camel/camel-mime-filter-canon.h
+++ b/camel/camel-mime-filter-canon.h
@@ -20,20 +20,39 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_CANON_H
-#define _CAMEL_MIME_FILTER_CANON_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_CANON_H
+#define CAMEL_MIME_FILTER_CANON_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_CANON_TYPE         (camel_mime_filter_canon_get_type ())
-#define CAMEL_MIME_FILTER_CANON(obj)         CAMEL_CHECK_CAST (obj, CAMEL_MIME_FILTER_CANON_TYPE, CamelMimeFilterCanon)
-#define CAMEL_MIME_FILTER_CANON_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, CAMEL_MIME_FILTER_CANON_TYPE, CamelMimeFilterCanonClass)
-#define CAMEL_IS_MIME_FILTER_CANON(obj)      CAMEL_CHECK_TYPE (obj, CAMEL_MIME_FILTER_CANON_TYPE)
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_CANON \
+	(camel_mime_filter_canon_get_type ())
+#define CAMEL_MIME_FILTER_CANON(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_CANON, CamelMimeFilterCanon))
+#define CAMEL_MIME_FILTER_CANON_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_CANON, CamelMimeFilterCanonClass))
+#define CAMEL_IS_MIME_FILTER_CANON(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_CANON))
+#define CAMEL_IS_MIME_FILTER_CANON_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_CANON))
+#define CAMEL_MIME_FILTER_CANON_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_CANON, CamelMimeFilterCanonClass))
 
 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 */
@@ -43,18 +62,17 @@ enum {
 
 struct _CamelMimeFilterCanon {
 	CamelMimeFilter parent;
-
-	guint32 flags;
+	CamelMimeFilterCanonPrivate *priv;
 };
 
 struct _CamelMimeFilterCanonClass {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType camel_mime_filter_canon_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_canon_new(guint32 flags);
+GType		camel_mime_filter_canon_get_type(void);
+CamelMimeFilter *
+		camel_mime_filter_canon_new	(guint32 flags);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_CANON_H */
+#endif /* CAMEL_MIME_FILTER_CANON_H */
diff --git a/camel/camel-mime-filter-charset.c b/camel/camel-mime-filter-charset.c
index b2630c7..92a6c5b 100644
--- a/camel/camel-mime-filter-charset.c
+++ b/camel/camel-mime-filter-charset.c
@@ -30,82 +30,69 @@
 #include "camel-iconv.h"
 #include "camel-mime-filter-charset.h"
 
+#define CAMEL_MIME_FILTER_CHARSET_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_CHARSET, CamelMimeFilterCharsetPrivate))
+
 #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);
-
-static CamelMimeFilterClass *camel_mime_filter_charset_parent;
+struct _CamelMimeFilterCharsetPrivate {
+	iconv_t ic;
+	gchar *from;
+	gchar *to;
+};
 
-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 gpointer parent_class;
 
 static void
-camel_mime_filter_charset_finalize(CamelObject *o)
+mime_filter_charset_finalize (GObject *object)
 {
-	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_GET_PRIVATE (object);
 
-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;
 	}
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 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_GET_PRIVATE (mime_filter);
+
+	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 +101,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 +132,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 +148,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_GET_PRIVATE (mime_filter);
+
+	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 +200,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,38 +217,67 @@ 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;
 
-	camel_mime_filter_charset_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	priv = CAMEL_MIME_FILTER_CHARSET_GET_PRIVATE (mime_filter);
 
-	filter_class->reset = reset;
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	/* 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_init (CamelMimeFilterCharset *obj)
+mime_filter_charset_class_init (CamelMimeFilterCharsetClass *class)
 {
-	obj->ic = (iconv_t)-1;
+	GObjectClass *object_class;
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterCharsetPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = mime_filter_charset_finalize;
+
+	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;
 }
 
-/**
- * camel_mime_filter_charset_new:
- *
- * Create a new #CamelMimeFilterCharset object.
- *
- * Returns: a new #CamelMimeFilterCharset object
- **/
-CamelMimeFilterCharset *
-camel_mime_filter_charset_new (void)
+static void
+mime_filter_charset_init (CamelMimeFilterCharset *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_CHARSET_GET_PRIVATE (filter);
+	filter->priv->ic = (iconv_t) -1;
+}
+
+GType
+camel_mime_filter_charset_get_type (void)
 {
-	return CAMEL_MIME_FILTER_CHARSET (camel_object_new (camel_mime_filter_charset_get_type ()));
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterCharset",
+			sizeof (CamelMimeFilterCharsetClass),
+			(GClassInitFunc) mime_filter_charset_class_init,
+			sizeof (CamelMimeFilterCharset),
+			(GInstanceInitFunc) mime_filter_charset_init,
+			0);
+
+	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
  *
@@ -262,24 +286,27 @@ camel_mime_filter_charset_new (void)
  *
  * Returns: a new #CamelMimeFilterCharset object
  **/
-CamelMimeFilterCharset *
-camel_mime_filter_charset_new_convert (const gchar *from_charset, const gchar *to_charset)
+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 = g_object_new (CAMEL_TYPE_MIME_FILTER_CHARSET, NULL);
+	priv = CAMEL_MIME_FILTER_CHARSET_GET_PRIVATE (new);
 
-	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)",
 			     g_strerror (errno)));
-		camel_object_unref (new);
+		g_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 new;
diff --git a/camel/camel-mime-filter-charset.h b/camel/camel-mime-filter-charset.h
index 1948d07..44d5149 100644
--- a/camel/camel-mime-filter-charset.h
+++ b/camel/camel-mime-filter-charset.h
@@ -19,39 +19,55 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_CHARSET_H
-#define _CAMEL_MIME_FILTER_CHARSET_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_CHARSET_H
+#define CAMEL_MIME_FILTER_CHARSET_H
 
 #include <camel/camel-mime-filter.h>
 #include <iconv.h>
 
-#define CAMEL_MIME_FILTER_CHARSET(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_charset_get_type (), CamelMimeFilterCharset)
-#define CAMEL_MIME_FILTER_CHARSET_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_charset_get_type (), CamelMimeFilterCharsetClass)
-#define CAMEL_IS_MIME_FILTER_CHARSET(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_charset_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_CHARSET \
+	(camel_mime_filter_charset_get_type ())
+#define CAMEL_MIME_FILTER_CHARSET(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_CHARSET, CamelMimeFilterCharset))
+#define CAMEL_MIME_FILTER_CHARSET_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_CHARSET, CamelMimeFilterCharsetClass))
+#define CAMEL_IS_MIME_FILTER_CHARSET(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_CHARSET))
+#define CAMEL_IS_MIME_FILTER_CHARSET_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_CHARSET))
+#define CAMEL_MIME_FILTER_CHARSET_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_CHARSET, CamelMimeFilterCharsetClass))
 
 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 {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType		camel_mime_filter_charset_get_type	(void);
-CamelMimeFilterCharset      *camel_mime_filter_charset_new	(void);
-
-CamelMimeFilterCharset      *camel_mime_filter_charset_new_convert	(const gchar *from_charset, const gchar *to_charset);
+GType		camel_mime_filter_charset_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_charset_new	(const gchar *from_charset,
+						 const gchar *to_charset);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_CHARSET_H */
+#endif /* CAMEL_MIME_FILTER_CHARSET_H */
diff --git a/camel/camel-mime-filter-crlf.c b/camel/camel-mime-filter-crlf.c
index 90c5f0b..48056ea 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);
+#define CAMEL_MIME_FILTER_CRLF_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_CRLF, CamelMimeFilterCRLFPrivate))
 
-static void
-camel_mime_filter_crlf_class_init (CamelMimeFilterCRLFClass *klass)
-{
-	CamelMimeFilterClass *mime_filter_class =
-		(CamelMimeFilterClass *) klass;
-
-	mime_filter_class->filter = filter;
-	mime_filter_class->complete = complete;
-	mime_filter_class->reset = reset;
-}
+struct _CamelMimeFilterCRLFPrivate {
+	CamelMimeFilterCRLFDirection direction;
+	CamelMimeFilterCRLFMode mode;
+	gboolean saw_cr;
+	gboolean saw_lf;
+	gboolean saw_dot;
+};
 
-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;
-}
+static gpointer parent_class;
 
 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_GET_PRIVATE (mime_filter);
+
+	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,93 @@ 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
+mime_filter_crlf_reset (CamelMimeFilter *mime_filter)
+{
+	CamelMimeFilterCRLFPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_CRLF_GET_PRIVATE (mime_filter);
+
+	priv->saw_cr = FALSE;
+	priv->saw_lf = TRUE;
+	priv->saw_dot = FALSE;
+}
+
+static void
+mime_filter_crlf_class_init (CamelMimeFilterCRLFClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterCRLFPrivate));
+
+	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
-reset (CamelMimeFilter *f)
+mime_filter_crlf_init (CamelMimeFilterCRLF *filter)
 {
-	CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f;
+	filter->priv = CAMEL_MIME_FILTER_CRLF_GET_PRIVATE (filter);
 
-	crlf->saw_cr = FALSE;
-	crlf->saw_lf = TRUE;
-	crlf->saw_dot = FALSE;
+	filter->priv->saw_cr = FALSE;
+	filter->priv->saw_lf = TRUE;
+	filter->priv->saw_dot = FALSE;
+}
+
+GType
+camel_mime_filter_crlf_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterCRLF",
+			sizeof (CamelMimeFilterCRLFClass),
+			(GClassInitFunc) mime_filter_crlf_class_init,
+			sizeof (CamelMimeFilterCRLF),
+			(GInstanceInitFunc) mime_filter_crlf_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -170,15 +206,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 = g_object_new (CAMEL_TYPE_MIME_FILTER_CRLF, NULL);
+	priv = CAMEL_MIME_FILTER_CRLF_GET_PRIVATE (filter);
 
-	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 ec1f5a1..810aab7 100644
--- a/camel/camel-mime-filter-crlf.h
+++ b/camel/camel-mime-filter-crlf.h
@@ -20,19 +20,39 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_CRLF_H
-#define _CAMEL_MIME_FILTER_CRLF_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_CRLF_H
+#define CAMEL_MIME_FILTER_CRLF_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_CRLF_TYPE         (camel_mime_filter_crlf_get_type ())
-#define CAMEL_MIME_FILTER_CRLF(obj)         CAMEL_CHECK_CAST (obj, CAMEL_MIME_FILTER_CRLF_TYPE, CamelMimeFilterCRLF)
-#define CAMEL_MIME_FILTER_CRLF_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, CAMEL_MIME_FILTER_CRLF_TYPE, CamelMimeFilterCRLFClass)
-#define CAMEL_IS_MIME_FILTER_CRLF(obj)      CAMEL_CHECK_TYPE (obj, CAMEL_MIME_FILTER_CRLF_TYPE)
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_CRLF \
+	(camel_mime_filter_crlf_get_type ())
+#define CAMEL_MIME_FILTER_CRLF(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_CRLF, CamelMimeFilterCRLF))
+#define CAMEL_MIME_FILTER_CRLF_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_CRLF, CamelMimeFilterCRLFClass))
+#define CAMEL_IS_MIME_FILTER_CRLF(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_CRLF))
+#define CAMEL_IS_MIME_FILTER_CRLF_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_CRLF))
+#define CAMEL_MIME_FILTER_CRLF_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_CRLF, CamelMimeFilterCRLFClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMimeFilterCRLF CamelMimeFilterCRLF;
 typedef struct _CamelMimeFilterCRLFClass CamelMimeFilterCRLFClass;
+typedef struct _CamelMimeFilterCRLFPrivate CamelMimeFilterCRLFPrivate;
 
 typedef enum {
 	CAMEL_MIME_FILTER_CRLF_ENCODE,
@@ -46,22 +66,18 @@ typedef enum {
 
 struct _CamelMimeFilterCRLF {
 	CamelMimeFilter parent;
-
-	CamelMimeFilterCRLFDirection direction;
-	CamelMimeFilterCRLFMode mode;
-	gboolean saw_cr;
-	gboolean saw_lf;
-	gboolean saw_dot;
+	CamelMimeFilterCRLFPrivate *priv;
 };
 
 struct _CamelMimeFilterCRLFClass {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType camel_mime_filter_crlf_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction, CamelMimeFilterCRLFMode mode);
+GType		camel_mime_filter_crlf_get_type	(void);
+CamelMimeFilter *
+		camel_mime_filter_crlf_new	(CamelMimeFilterCRLFDirection direction,
+						 CamelMimeFilterCRLFMode mode);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_CRLF_H */
+#endif /* CAMEL_MIME_FILTER_CRLF_H */
diff --git a/camel/camel-mime-filter-enriched.c b/camel/camel-mime-filter-enriched.c
index 992408a..44ab318 100644
--- a/camel/camel-mime-filter-enriched.c
+++ b/camel/camel-mime-filter-enriched.c
@@ -30,11 +30,20 @@
 #include "camel-mime-filter-enriched.h"
 #include "camel-string-utils.h"
 
+#define CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_ENRICHED, CamelMimeFilterEnrichedPrivate))
+
+struct _CamelMimeFilterEnrichedPrivate {
+	guint32 flags;
+	gint nofill;
+};
+
 /* text/enriched is rfc1896 */
 
 typedef gchar * (*EnrichedParamParser) (const gchar *inptr, gint inlen);
 
-static gchar *param_parse_colour (const gchar *inptr, gint inlen);
+static gchar *param_parse_color (const gchar *inptr, gint inlen);
 static gchar *param_parse_font (const gchar *inptr, gint inlen);
 static gchar *param_parse_lang (const gchar *inptr, gint inlen);
 
@@ -72,7 +81,7 @@ static struct {
 	{ "np",          "<hr>",                FALSE, NULL               },
 	{ "fontfamily",  "<font face=\"%s\">",  TRUE,  param_parse_font   },
 	{ "/fontfamily", "</font>",             FALSE, NULL               },
-	{ "color",       "<font color=\"%s\">", TRUE,  param_parse_colour },
+	{ "color",       "<font color=\"%s\">", TRUE,  param_parse_color },
 	{ "/color",      "</font>",             FALSE, NULL               },
 	{ "lang",        "<span lang=\"%s\">",  TRUE,  param_parse_lang   },
 	{ "/lang",       "</span>",             FALSE, NULL               },
@@ -90,71 +99,7 @@ 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)
-{
-	filter->flags = 0;
-	filter->nofill = 0;
-}
+static gpointer parent_class;
 
 #if 0
 static gboolean
@@ -176,28 +121,28 @@ html_tag_needs_param (const gchar *tag)
 	return strstr (tag, "%s") != NULL;
 }
 
-static const gchar *valid_colours[] = {
+static const gchar *valid_colors[] = {
 	"red", "green", "blue", "yellow", "cyan", "magenta", "black", "white"
 };
 
 static gchar *
-param_parse_colour (const gchar *inptr, gint inlen)
+param_parse_color (const gchar *inptr, gint inlen)
 {
 	const gchar *inend, *end;
 	guint32 rgb = 0;
 	guint v;
 	gint i;
 
-	for (i = 0; i < G_N_ELEMENTS (valid_colours); i++) {
-		if (!g_ascii_strncasecmp (inptr, valid_colours[i], inlen))
-			return g_strdup (valid_colours[i]);
+	for (i = 0; i < G_N_ELEMENTS (valid_colors); i++) {
+		if (!g_ascii_strncasecmp (inptr, valid_colors[i], inlen))
+			return g_strdup (valid_colors[i]);
 	}
 
 	/* check for numeric r/g/b in the format: ####,####,#### */
 	if (inptr[4] != ',' || inptr[9] != ',') {
 		/* okay, mailer must have used a string name that
 		 * rfc1896 did not specify? do some simple scanning
-		 * action, a colour name MUST be [a-zA-Z] */
+		 * action, a color name MUST be [a-zA-Z] */
 		end = inptr;
 		inend = inptr + inlen;
 		while (end < inend && ((*end >= 'a' && *end <= 'z') || (*end >= 'A' && *end <= 'Z')))
@@ -221,7 +166,7 @@ param_parse_colour (const gchar *inptr, gint inlen)
 
  invalid_format:
 
-	/* default colour? */
+	/* default color? */
 	return g_strdup ("black");
 }
 
@@ -269,14 +214,22 @@ 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 *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;
 
+	priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (filter);
+
 	camel_mime_filter_set_size (filter, inlen * 2 + 6, FALSE);
 
 	inptr = in;
@@ -308,9 +261,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 +309,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 +353,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;
@@ -534,25 +487,86 @@ enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize p
 }
 
 static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_enriched_filter (CamelMimeFilter *filter,
+                             const gchar *in,
+                             gsize len,
+                             gsize prespace,
+                             gchar **out,
+                             gsize *outlen,
+                             gsize *outprespace)
 {
-	enriched_to_html (filter, in, len, prespace, out, outlen, outprespace, FALSE);
+	enriched_to_html (
+		filter, in, len, prespace, out, outlen, outprespace, FALSE);
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_enriched_complete (CamelMimeFilter *filter,
+                               const gchar *in,
+                               gsize len,
+                               gsize prespace,
+                               gchar **out,
+                               gsize *outlen,
+                               gsize *outprespace)
 {
-	enriched_to_html (filter, in, len, prespace, out, outlen, outprespace, TRUE);
+	enriched_to_html (
+		filter, in, len, prespace, out, outlen, outprespace, TRUE);
 }
 
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_enriched_reset (CamelMimeFilter *filter)
 {
-	CamelMimeFilterEnriched *enriched = (CamelMimeFilterEnriched *) filter;
+	CamelMimeFilterEnrichedPrivate *priv;
 
-	enriched->nofill = 0;
+	priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (filter);
+
+	priv->nofill = 0;
+}
+
+static void
+mime_filter_enriched_class_init (CamelMimeFilterEnrichedClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+	gint i;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterEnrichedPrivate));
+
+	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
+mime_filter_enriched_init (CamelMimeFilterEnriched *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_enriched_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterEnriched",
+			sizeof (CamelMimeFilterEnrichedClass),
+			(GClassInitFunc) mime_filter_enriched_class_init,
+			sizeof (CamelMimeFilterEnriched),
+			(GInstanceInitFunc) mime_filter_enriched_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -567,12 +581,15 @@ filter_reset (CamelMimeFilter *filter)
 CamelMimeFilter *
 camel_mime_filter_enriched_new (guint32 flags)
 {
-	CamelMimeFilterEnriched *new;
+	CamelMimeFilter *new;
+	CamelMimeFilterEnrichedPrivate *priv;
+
+	new = g_object_new (CAMEL_TYPE_MIME_FILTER_ENRICHED, NULL);
+	priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (new);
 
-	new = (CamelMimeFilterEnriched *) camel_object_new (CAMEL_TYPE_MIME_FILTER_ENRICHED);
-	new->flags = flags;
+	priv->flags = flags;
 
-	return CAMEL_MIME_FILTER (new);
+	return new;
 }
 
 /**
@@ -600,7 +617,7 @@ camel_enriched_to_html(const gchar *in, guint32 flags)
 
 	camel_mime_filter_complete(filter, (gchar *)in, strlen(in), 0, &outbuf, &outlen, &outpre);
 	outbuf = g_strndup (outbuf, outlen);
-	camel_object_unref (filter);
+	g_object_unref (filter);
 
 	return outbuf;
 }
diff --git a/camel/camel-mime-filter-enriched.h b/camel/camel-mime-filter-enriched.h
index e1d2345..eeb5906 100644
--- a/camel/camel-mime-filter-enriched.h
+++ b/camel/camel-mime-filter-enriched.h
@@ -20,15 +20,33 @@
  *
  */
 
-#ifndef __CAMEL_MIME_FILTER_ENRICHED_H__
-#define __CAMEL_MIME_FILTER_ENRICHED_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_ENRICHED_H
+#define CAMEL_MIME_FILTER_ENRICHED_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_TYPE_MIME_FILTER_ENRICHED         (camel_mime_filter_enriched_get_type ())
-#define CAMEL_MIME_FILTER_ENRICHED(obj)         (CAMEL_CHECK_CAST (obj, CAMEL_TYPE_MIME_FILTER_ENRICHED, CamelMimeFilterEnriched))
-#define CAMEL_MIME_FILTER_ENRICHED_CLASS(klass) (CAMEL_CHECK_CLASS_CAST (klass, CAMEL_TYPE_MIME_FILTER_ENRICHED, CamelMimeFilterEnrichedClass))
-#define CAMEL_IS_MIME_FILTER_ENRICHED(obj)      (CAMEL_CHECK_TYPE (obj, CAMEL_TYPE_MIME_FILTER_ENRICHED))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_ENRICHED \
+	(camel_mime_filter_enriched_get_type ())
+#define CAMEL_MIME_FILTER_ENRICHED(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_ENRICHED, CamelMimeFilterEnriched))
+#define CAMEL_MIME_FILTER_ENRICHED_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_ENRICHED, CamelMimeFilterEnrichedClass))
+#define CAMEL_IS_MIME_FILTER_ENRICHED(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_ENRICHED))
+#define CAMEL_IS_MIME_FILTER_ENRICHED_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_ENRICHED))
+#define CAMEL_MIME_FILTER_ENRICHED_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_ENRICHED, CamelMimeFilterEnrichedClass))
 
 #define CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT  (1 << 0)
 
@@ -36,24 +54,23 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterEnriched CamelMimeFilterEnriched;
 typedef struct _CamelMimeFilterEnrichedClass CamelMimeFilterEnrichedClass;
+typedef struct _CamelMimeFilterEnrichedPrivate CamelMimeFilterEnrichedPrivate;
 
 struct _CamelMimeFilterEnriched {
-	CamelMimeFilter parent_object;
-
-	guint32 flags;
-	gint nofill;
+	CamelMimeFilter parent;
+	CamelMimeFilterEnrichedPrivate *priv;
 };
 
 struct _CamelMimeFilterEnrichedClass {
 	CamelMimeFilterClass parent_class;
-
 };
 
-CamelType        camel_mime_filter_enriched_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_enriched_new (guint32 flags);
-gchar *camel_enriched_to_html(const gchar *in, guint32 flags);
+GType		camel_mime_filter_enriched_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_enriched_new	(guint32 flags);
+gchar *		camel_enriched_to_html		(const gchar *in,
+						 guint32 flags);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MIME_FILTER_ENRICHED_H__ */
+#endif /* CAMEL_MIME_FILTER_ENRICHED_H */
diff --git a/camel/camel-mime-filter-from.c b/camel/camel-mime-filter-from.c
index 193cd82..a574555 100644
--- a/camel/camel-mime-filter-from.c
+++ b/camel/camel-mime-filter-from.c
@@ -27,30 +27,17 @@
 
 #include "camel-mime-filter-from.h"
 
-#define d(x)
-
-static void camel_mime_filter_from_class_init (CamelMimeFilterFromClass *klass);
-static void camel_mime_filter_from_init       (CamelMimeFilterFrom *obj);
+#define CAMEL_MIME_FILTER_FROM_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_FROM, CamelMimeFilterFromPrivate))
 
-static CamelMimeFilterClass *camel_mime_filter_from_parent;
+#define d(x)
 
-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);
-	}
+struct _CamelMimeFilterFromPrivate {
+	gint midline;		/* are we between lines? */
+};
 
-	return type;
-}
+static gpointer parent_class;
 
 struct fromnode {
 	struct fromnode *next;
@@ -58,7 +45,13 @@ struct fromnode {
 };
 
 static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_from_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
 {
 	*out = (gchar *) in;
 	*outlen = len;
@@ -67,16 +60,23 @@ complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar
 
 /* 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_GET_PRIVATE (mime_filter);
+
 	inptr = in;
 	inend = inptr+len;
 
@@ -86,18 +86,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 +116,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 +135,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 +150,40 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 }
 
 static void
-camel_mime_filter_from_class_init (CamelMimeFilterFromClass *klass)
+mime_filter_from_class_init (CamelMimeFilterFromClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterClass *mime_filter_class;
 
-	camel_mime_filter_from_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterFromPrivate));
 
-	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)
+mime_filter_from_init (CamelMimeFilterFrom *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_FROM_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_from_get_type (void)
 {
-	;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterFrom",
+			sizeof (CamelMimeFilterFromClass),
+			(GClassInitFunc) mime_filter_from_class_init,
+			sizeof (CamelMimeFilterFrom),
+			(GInstanceInitFunc) mime_filter_from_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -175,11 +193,10 @@ camel_mime_filter_from_init (CamelMimeFilterFrom *obj)
  *
  * Returns: a new #CamelMimeFilterFrom object
  **/
-CamelMimeFilterFrom *
+CamelMimeFilter *
 camel_mime_filter_from_new (void)
 {
-	CamelMimeFilterFrom *new = CAMEL_MIME_FILTER_FROM ( camel_object_new (camel_mime_filter_from_get_type ()));
-	return new;
+	return g_object_new (CAMEL_TYPE_MIME_FILTER_FROM, NULL);
 }
 
 #if 0
diff --git a/camel/camel-mime-filter-from.h b/camel/camel-mime-filter-from.h
index 3ec0f23..34bdee8 100644
--- a/camel/camel-mime-filter-from.h
+++ b/camel/camel-mime-filter-from.h
@@ -19,33 +19,53 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_FROM_H
-#define _CAMEL_MIME_FILTER_FROM_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_FROM_H
+#define CAMEL_MIME_FILTER_FROM_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_FROM(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_from_get_type (), CamelMimeFilterFrom)
-#define CAMEL_MIME_FILTER_FROM_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_from_get_type (), CamelMimeFilterFromClass)
-#define CAMEL_IS_MIME_FILTER_FROM(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_from_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_FROM \
+	(camel_mime_filter_from_get_type ())
+#define CAMEL_MIME_FILTER_FROM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_FROM, CamelMimeFilterFrom))
+#define CAMEL_MIME_FILTER_FROM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_FROM, CamelMimeFilterFromClass))
+#define CAMEL_IS_MIME_FILTER_FROM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_FROM))
+#define CAMEL_IS_MIME_FILTER_FROM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_FROM))
+#define CAMEL_MIME_FILTER_FROM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_FROM, CamelMimeFilterFromClass))
 
 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 {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType		camel_mime_filter_from_get_type	(void);
-CamelMimeFilterFrom      *camel_mime_filter_from_new	(void);
+GType		camel_mime_filter_from_get_type	(void);
+CamelMimeFilter *
+		camel_mime_filter_from_new	(void);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_FROM_H */
+#endif /* CAMEL_MIME_FILTER_FROM_H */
diff --git a/camel/camel-mime-filter-gzip.c b/camel/camel-mime-filter-gzip.c
index edce501..005314d 100644
--- a/camel/camel-mime-filter-gzip.c
+++ b/camel/camel-mime-filter-gzip.c
@@ -31,6 +31,10 @@
 
 #include "camel-mime-filter-gzip.h"
 
+#define CAMEL_MIME_FILTER_GZIP_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_GZIP, CamelMimeFilterGZipPrivate))
+
 /* rfc1952 */
 
 enum {
@@ -78,6 +82,10 @@ typedef union {
 } gzip_state_t;
 
 struct _CamelMimeFilterGZipPrivate {
+
+	CamelMimeFilterGZipMode mode;
+	gint level;
+
 	z_stream *stream;
 
 	gzip_state_t state;
@@ -87,89 +95,32 @@ 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)
-{
-	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 gpointer parent_class;
 
 static void
-gzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	     gchar **out, gsize *outlen, gsize *outprespace, gint flush)
+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_GET_PRIVATE (filter);
+
 	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;
@@ -238,14 +189,21 @@ gzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace
 }
 
 static void
-gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace, gint flush)
+gunzip_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;
 	guint16 need, val;
 	gint retval;
 
+	priv = CAMEL_MIME_FILTER_GZIP_GET_PRIVATE (filter);
+
 	if (!priv->state.unzip.got_hdr) {
 		if (len < 10) {
 			camel_mime_filter_backup (filter, in, len);
@@ -384,46 +342,123 @@ gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 	*outprespace = filter->outpre;
 }
 
+/* should this 'flush' outstanding state/data bytes? */
 static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_gzip_reset (CamelMimeFilter *filter)
 {
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
+	CamelMimeFilterGZipPrivate *priv;
 
-	if (gzip->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+	priv = CAMEL_MIME_FILTER_GZIP_GET_PRIVATE (filter);
+
+	memset (&priv->state, 0, sizeof (priv->state));
+
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+		deflateReset (priv->stream);
+	else
+		inflateReset (priv->stream);
+
+	priv->crc32 = crc32 (0, Z_NULL, 0);
+	priv->isize = 0;
+}
+
+static void
+mime_filter_gzip_filter (CamelMimeFilter *filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlen,
+                         gsize *outprespace)
+{
+	CamelMimeFilterGZipPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_GZIP_GET_PRIVATE (filter);
+
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
 		gzip_filter (filter, in, len, prespace, out, outlen, outprespace, Z_SYNC_FLUSH);
 	else
 		gunzip_filter (filter, in, len, prespace, out, outlen, outprespace, Z_SYNC_FLUSH);
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_gzip_complete (CamelMimeFilter *filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
 {
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
+	CamelMimeFilterGZipPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_GZIP_GET_PRIVATE (filter);
 
-	if (gzip->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
 		gzip_filter (filter, in, len, prespace, out, outlen, outprespace, Z_FULL_FLUSH);
 	else
 		gunzip_filter (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_finalize (GObject *object)
 {
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
-	struct _CamelMimeFilterGZipPrivate *priv = gzip->priv;
+	CamelMimeFilterGZipPrivate *priv;
 
-	memset (&priv->state, 0, sizeof (priv->state));
+	priv = CAMEL_MIME_FILTER_GZIP_GET_PRIVATE (object);
 
-	if (gzip->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
-		deflateReset (priv->stream);
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+		deflateEnd (priv->stream);
 	else
-		inflateReset (priv->stream);
+		inflateEnd (priv->stream);
 
-	priv->crc32 = crc32 (0, Z_NULL, 0);
-	priv->isize = 0;
+	g_free (priv->stream);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+mime_filter_gzip_class_init (CamelMimeFilterGZipClass *class)
+{
+	GObjectClass *object_class;
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterGZipPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = mime_filter_gzip_finalize;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->reset = mime_filter_gzip_reset;
+	mime_filter_class->filter = mime_filter_gzip_filter;
+	mime_filter_class->complete = mime_filter_gzip_complete;
+}
+
+static void
+mime_filter_gzip_init (CamelMimeFilterGZip *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_GZIP_GET_PRIVATE (filter);
+	filter->priv->stream = g_new0 (z_stream, 1);
+	filter->priv->crc32 = crc32 (0, Z_NULL, 0);
+}
+
+GType
+camel_mime_filter_gzip_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterGZip",
+			sizeof (CamelMimeFilterGZipClass),
+			(GClassInitFunc) mime_filter_gzip_class_init,
+			sizeof (CamelMimeFilterGZip),
+			(GInstanceInitFunc) mime_filter_gzip_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -438,22 +473,25 @@ 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 = g_object_new (CAMEL_TYPE_MIME_FILTER_GZIP, NULL);
+	priv = CAMEL_MIME_FILTER_GZIP_GET_PRIVATE (new);
+
+	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);
+		g_object_unref (new);
 		return NULL;
 	}
 
-	return (CamelMimeFilter *) new;
+	return new;
 }
diff --git a/camel/camel-mime-filter-gzip.h b/camel/camel-mime-filter-gzip.h
index e32269a..d7ded75 100644
--- a/camel/camel-mime-filter-gzip.h
+++ b/camel/camel-mime-filter-gzip.h
@@ -20,22 +20,39 @@
  *
  */
 
-#ifndef __CAMEL_MIME_FILTER_GZIP_H__
-#define __CAMEL_MIME_FILTER_GZIP_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_GZIP_H
+#define CAMEL_MIME_FILTER_GZIP_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_TYPE_MIME_FILTER_GZIP            (camel_mime_filter_gzip_get_type ())
-#define CAMEL_MIME_FILTER_GZIP(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_MIME_FILTER_GZIP, CamelMimeFilterGZip))
-#define CAMEL_MIME_FILTER_GZIP_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_MIME_FILTER_GZIP, CamelMimeFilterGZipClass))
-#define CAMEL_IS_MIME_FILTER_GZIP(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_MIME_FILTER_GZIP))
-#define CAMEL_IS_MIME_FILTER_GZIP_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_MIME_FILTER_GZIP))
-#define CAMEL_MIME_FILTER_GZIP_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_MIME_FILTER_GZIP, CamelMimeFilterGZipClass))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_GZIP \
+	(camel_mime_filter_gzip_get_type ())
+#define CAMEL_MIME_FILTER_GZIP(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_GZIP, CamelMimeFilterGZip))
+#define CAMEL_MIME_FILTER_GZIP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_GZIP, CamelMimeFilterGZipClass))
+#define CAMEL_IS_MIME_FILTER_GZIP(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_GZIP))
+#define CAMEL_IS_MIME_FILTER_GZIP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_GZIP))
+#define CAMEL_MIME_FILTER_GZIP_GET_CLASS(obj) \
+	(CAMEL_CHECK_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_GZIP, CamelMimeFilterGZipClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterGZip CamelMimeFilterGZip;
 typedef struct _CamelMimeFilterGZipClass CamelMimeFilterGZipClass;
+typedef struct _CamelMimeFilterGZipPrivate CamelMimeFilterGZipPrivate;
 
 typedef enum {
 	CAMEL_MIME_FILTER_GZIP_MODE_ZIP,
@@ -43,23 +60,19 @@ typedef enum {
 } CamelMimeFilterGZipMode;
 
 struct _CamelMimeFilterGZip {
-	CamelMimeFilter parent_object;
-
-	struct _CamelMimeFilterGZipPrivate *priv;
-
-	CamelMimeFilterGZipMode mode;
-	gint level;
+	CamelMimeFilter parent;
+	CamelMimeFilterGZipPrivate *priv;
 };
 
 struct _CamelMimeFilterGZipClass {
 	CamelMimeFilterClass parent_class;
-
 };
 
-CamelType camel_mime_filter_gzip_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_gzip_new (CamelMimeFilterGZipMode mode, gint level);
+GType		camel_mime_filter_gzip_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_gzip_new	(CamelMimeFilterGZipMode mode,
+						 gint level);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MIME_FILTER_GZIP_H__ */
+#endif /* CAMEL_MIME_FILTER_GZIP_H */
diff --git a/camel/camel-mime-filter-html.c b/camel/camel-mime-filter-html.c
index 4cb0cc9..7d49d38 100644
--- a/camel/camel-mime-filter-html.c
+++ b/camel/camel-mime-filter-html.c
@@ -33,16 +33,16 @@
 
 #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;
+#define CAMEL_MIME_FILTER_HTML_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_HTML, CamelMimeFilterHTMLPrivate))
 
 struct _CamelMimeFilterHTMLPrivate {
 	CamelHTMLParser *ctxt;
 };
 
+static gpointer parent_class;
+
 /* ********************************************************************** */
 
 #if 0
@@ -68,54 +68,18 @@ 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)
+run(CamelMimeFilter *mime_filter, const gchar *in, gsize inlen, gsize prespace, gchar **out, gsize *outlenptr, gsize *outprespace, gint last)
 {
-	CamelMimeFilterHTML *f = (CamelMimeFilterHTML *) mf;
+	CamelMimeFilterHTML *f = (CamelMimeFilterHTML *) mime_filter;
 	camel_html_parser_t state;
 	gchar *outp;
 
 	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);
 	do {
@@ -139,44 +103,109 @@ 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_dispose (GObject *object)
 {
-	run(mf, in, len, prespace, out, outlenptr, outprespace, TRUE);
+	CamelMimeFilterHTMLPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_HTML_GET_PRIVATE (object);
+
+	if (priv->ctxt != NULL) {
+		g_object_unref (priv->ctxt);
+		priv->ctxt = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlenptr, gsize *outprespace)
+mime_filter_html_reset (CamelMimeFilter *mime_filter)
 {
-	run(mf, in, len, prespace, out, outlenptr, outprespace, FALSE);
+	CamelMimeFilterHTMLPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_HTML_GET_PRIVATE (mime_filter);
+
+	g_object_unref (priv->ctxt);
+	priv->ctxt = camel_html_parser_new ();
 }
 
 static void
-reset(CamelMimeFilter *mf)
+mime_filter_html_filter (CamelMimeFilter *mime_filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlenptr,
+                         gsize *outprespace)
 {
-	CamelMimeFilterHTML *f = (CamelMimeFilterHTML *)mf;
+	run (
+		mime_filter, in, len, prespace,
+		out, outlenptr, outprespace, FALSE);
+}
 
-	camel_object_unref((CamelObject *)f->priv->ctxt);
-	f->priv->ctxt = camel_html_parser_new();
+static void
+mime_filter_html_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlenptr,
+                           gsize *outprespace)
+{
+	run (
+		mime_filter, in, len, prespace,
+		out, outlenptr, outprespace, TRUE);
 }
 
 static void
-camel_mime_filter_html_class_init (CamelMimeFilterHTMLClass *klass)
+mime_filter_html_class_init (CamelMimeFilterHTMLClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	GObjectClass *object_class;
+	CamelMimeFilterClass *mime_filter_class;
 
-	camel_mime_filter_html_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterHTMLPrivate));
 
-	filter_class->reset = reset;
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = mime_filter_html_dispose;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->reset = mime_filter_html_reset;
+	mime_filter_class->filter = mime_filter_html_filter;
+	mime_filter_class->complete = mime_filter_html_complete;
+}
+
+static void
+mime_filter_html_init (CamelMimeFilterHTML *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_HTML_GET_PRIVATE (filter);
+	filter->priv->ctxt = camel_html_parser_new ();
+}
+
+GType
+camel_mime_filter_html_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterHTML",
+			sizeof (CamelMimeFilterHTMLClass),
+			(GClassInitFunc) mime_filter_html_class_init,
+			sizeof (CamelMimeFilterHTML),
+			(GInstanceInitFunc) mime_filter_html_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -186,9 +215,8 @@ camel_mime_filter_html_class_init (CamelMimeFilterHTMLClass *klass)
  *
  * Returns: a new #CamelMimeFilterHTML object
  **/
-CamelMimeFilterHTML *
+CamelMimeFilter *
 camel_mime_filter_html_new (void)
 {
-	CamelMimeFilterHTML *new = CAMEL_MIME_FILTER_HTML ( camel_object_new (camel_mime_filter_html_get_type ()));
-	return new;
+	return g_object_new (CAMEL_TYPE_MIME_FILTER_HTML, NULL);
 }
diff --git a/camel/camel-mime-filter-html.h b/camel/camel-mime-filter-html.h
index abe71fe..a3144ca 100644
--- a/camel/camel-mime-filter-html.h
+++ b/camel/camel-mime-filter-html.h
@@ -19,33 +19,53 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_HTML_H
-#define _CAMEL_MIME_FILTER_HTML_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_HTML_H
+#define CAMEL_MIME_FILTER_HTML_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_HTML(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_html_get_type (), CamelMimeFilterHTML)
-#define CAMEL_MIME_FILTER_HTML_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_html_get_type (), CamelMimeFilterHTMLClass)
-#define CAMEL_IS_MIME_FILTER_HTML(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_html_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_HTML \
+	(camel_mime_filter_html_get_type ())
+#define CAMEL_MIME_FILTER_HTML(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_HTML, CamelMimeFilterHTML))
+#define CAMEL_MIME_FILTER_HTML_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_HTML, CamelMimeFilterHTMLClass))
+#define CAMEL_IS_MIME_FILTER_HTML(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_HTML))
+#define CAMEL_IS_MIME_FILTER_HTML_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_HTML))
+#define CAMEL_MIME_FILTER_HTML_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_HTML, CamelMimeFilterHTMLClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMimeFilterHTMLClass CamelMimeFilterHTMLClass;
 typedef struct _CamelMimeFilterHTML CamelMimeFilterHTML;
+typedef struct _CamelMimeFilterHTMLClass CamelMimeFilterHTMLClass;
+typedef struct _CamelMimeFilterHTMLPrivate CamelMimeFilterHTMLPrivate;
 
 struct _CamelMimeFilterHTML {
 	CamelMimeFilter parent;
-
-	struct _CamelMimeFilterHTMLPrivate *priv;
+	CamelMimeFilterHTMLPrivate *priv;
 };
 
 struct _CamelMimeFilterHTMLClass {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType		camel_mime_filter_html_get_type	(void);
-CamelMimeFilterHTML      *camel_mime_filter_html_new	(void);
+GType		camel_mime_filter_html_get_type	(void);
+CamelMimeFilter *
+		camel_mime_filter_html_new	(void);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_HTML_H */
+#endif /* CAMEL_MIME_FILTER_HTML_H */
diff --git a/camel/camel-mime-filter-index.c b/camel/camel-mime-filter-index.c
index 2fd5d38..0c6e3a5 100644
--- a/camel/camel-mime-filter-index.c
+++ b/camel/camel-mime-filter-index.c
@@ -21,50 +21,56 @@
 #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);
+#define CAMEL_MIME_FILTER_INDEX_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_INDEX, CamelMimeFilterIndexPrivate))
 
-static CamelMimeFilterClass *camel_mime_filter_index_parent;
+struct _CamelMimeFilterIndexPrivate {
+	CamelIndex *index;
+	CamelIndexName *name;
+};
 
-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 gpointer parent_class;
 
 static void
-camel_mime_filter_index_finalize(CamelObject *o)
+mime_filter_index_dispose (GObject *object)
 {
-	CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)o;
+	CamelMimeFilterIndexPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_INDEX_GET_PRIVATE (object);
 
-	if (f->name)
-		camel_object_unref((CamelObject *)f->name);
-	camel_object_unref((CamelObject *)f->index);
+	if (priv->name != NULL) {
+		g_object_unref (priv->name);
+		priv->name = NULL;
+	}
+
+	if (priv->index != NULL) {
+		g_object_unref (priv->index);
+		priv->index = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 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_GET_PRIVATE (mime_filter);
 
-	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 +79,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;
+
+	priv = CAMEL_MIME_FILTER_INDEX_GET_PRIVATE (mime_filter);
 
-	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 (priv->name, in, len);
+	camel_index_name_add_buffer (priv->name, NULL, 0);
 
 donothing:
 	*out = (gchar *) in;
@@ -90,48 +105,67 @@ donothing:
 }
 
 static void
-camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass)
+mime_filter_index_class_init (CamelMimeFilterIndexClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	GObjectClass *object_class;
+	CamelMimeFilterClass *mime_filter_class;
 
-	camel_mime_filter_index_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterIndexPrivate));
 
-	/*filter_class->reset = reset;*/
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = mime_filter_index_dispose;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_index_filter;
+	mime_filter_class->complete = mime_filter_index_complete;
 }
 
-/**
- * camel_mime_filter_index_new:
- *
- * Create a new #CamelMimeFilterIndex object
- *
- * Returns: a new #CamelMimeFilterIndex object
- **/
-CamelMimeFilterIndex *
-camel_mime_filter_index_new (void)
+static void
+mime_filter_index_init (CamelMimeFilterIndex *filter)
 {
-	CamelMimeFilterIndex *new = CAMEL_MIME_FILTER_INDEX ( camel_object_new (camel_mime_filter_index_get_type ()));
-	return new;
+	filter->priv = CAMEL_MIME_FILTER_INDEX_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_index_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterIndex",
+			sizeof (CamelMimeFilterIndexClass),
+			(GClassInitFunc) mime_filter_index_class_init,
+			sizeof (CamelMimeFilterIndex),
+			(GInstanceInitFunc) mime_filter_index_init,
+			0);
+
+	return type;
 }
 
 /**
- * camel_mime_filter_index_new_index:
+ * camel_mime_filter_index_new:
  * @index: a #CamelIndex object
  *
  * Create a new #CamelMimeFilterIndex based on @index.
  *
  * Returns: a new #CamelMimeFilterIndex object
  **/
-CamelMimeFilterIndex *
-camel_mime_filter_index_new_index (CamelIndex *index)
+CamelMimeFilter *
+camel_mime_filter_index_new (CamelIndex *index)
 {
-	CamelMimeFilterIndex *new = camel_mime_filter_index_new();
+	CamelMimeFilter *new;
+	CamelMimeFilterIndexPrivate *priv;
+
+	new = g_object_new (CAMEL_TYPE_MIME_FILTER_INDEX, NULL);
 
 	if (new) {
-		new->index = index;
+		priv = CAMEL_MIME_FILTER_INDEX_GET_PRIVATE (new);
+		priv->index = index;
 		if (index)
-			camel_object_ref (index);
+			g_object_ref (index);
 	}
 	return new;
 }
@@ -146,13 +180,20 @@ camel_mime_filter_index_new_index (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)
-		camel_object_ref (name);
+	g_return_if_fail (CAMEL_IS_MIME_FILTER_INDEX (filter));
+
+	if (name != NULL) {
+		g_return_if_fail (CAMEL_IS_INDEX_NAME (name));
+		g_object_ref (name);
+	}
+
+	if (filter->priv->name != NULL)
+		g_object_unref (filter->priv->name);
+
+	filter->priv->name = name;
 }
 
 /**
@@ -163,17 +204,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));
+		g_object_ref (index);
+	}
+
+	if (filter->priv->index) {
 		gchar *out;
 		gsize outlen, outspace;
 
-		camel_mime_filter_complete((CamelMimeFilter *)filter, "", 0, 0, &out, &outlen, &outspace);
-		camel_object_unref (index);
+		camel_mime_filter_complete (
+			CAMEL_MIME_FILTER (filter),
+			"", 0, 0, &out, &outlen, &outspace);
+		g_object_unref (filter->priv->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 a39369f..6cf994c 100644
--- a/camel/camel-mime-filter-index.h
+++ b/camel/camel-mime-filter-index.h
@@ -19,41 +19,61 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_INDEX_H
-#define _CAMEL_MIME_FILTER_INDEX_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
 
+#ifndef CAMEL_MIME_FILTER_INDEX_H
+#define CAMEL_MIME_FILTER_INDEX_H
+
+#include <camel/camel-index.h>
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_INDEX(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_index_get_type (), CamelMimeFilterIndex)
-#define CAMEL_MIME_FILTER_INDEX_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_index_get_type (), CamelMimeFilterIndexClass)
-#define CAMEL_IS_MIME_FILTER_INDEX(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_index_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_INDEX \
+	(camel_mime_filter_index_get_type ())
+#define CAMEL_MIME_FILTER_INDEX(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_INDEX, CamelMimeFilterIndex))
+#define CAMEL_MIME_FILTER_INDEX_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_INDEX, CamelMimeFilterIndexClass))
+#define CAMEL_IS_MIME_FILTER_INDEX(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_INDEX))
+#define CAMEL_IS_MIME_FILTER_INDEX_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_INDEX))
+#define CAMEL_MIME_FILTER_INDEX_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_INDEX, CamelMimeFilterIndexClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMimeFilterIndex CamelMimeFilterIndex;
 typedef struct _CamelMimeFilterIndexClass CamelMimeFilterIndexClass;
+typedef struct _CamelMimeFilterIndexPrivate CamelMimeFilterIndexPrivate;
 
 struct _CamelMimeFilterIndex {
 	CamelMimeFilter parent;
-
-	struct _CamelMimeFilterIndexPrivate *priv;
-
-	struct _CamelIndex *index;
-	struct _CamelIndexName *name;
+	CamelMimeFilterIndexPrivate *priv;
 };
 
 struct _CamelMimeFilterIndexClass {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType		camel_mime_filter_index_get_type	(void);
-CamelMimeFilterIndex      *camel_mime_filter_index_new	(void);
-
-CamelMimeFilterIndex      *camel_mime_filter_index_new_index(struct _CamelIndex *index);
+GType		camel_mime_filter_index_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_index_new	(CamelIndex *index);
 
 /* Set the match name for any indexed words */
-void camel_mime_filter_index_set_name (CamelMimeFilterIndex *filter, struct _CamelIndexName *name);
-void camel_mime_filter_index_set_index (CamelMimeFilterIndex *filter, struct _CamelIndex *index);
+void		camel_mime_filter_index_set_name(CamelMimeFilterIndex *filter,
+						 CamelIndexName *name);
+void		camel_mime_filter_index_set_index
+						(CamelMimeFilterIndex *filter,
+						 CamelIndex *index);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_INDEX_H */
+#endif /* CAMEL_MIME_FILTER_INDEX_H */
diff --git a/camel/camel-mime-filter-linewrap.c b/camel/camel-mime-filter-linewrap.c
index fa767d0..0efb331 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);
+#define CAMEL_MIME_FILTER_LINEWRAP_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_LINEWRAP, CamelMimeFilterLinewrapPrivate))
 
-static void
-camel_mime_filter_linewrap_class_init (CamelMimeFilterLinewrapClass *klass)
-{
-	CamelMimeFilterClass *mime_filter_class =
-		(CamelMimeFilterClass *) klass;
-
-	mime_filter_class->filter = filter;
-	mime_filter_class->complete = complete;
-	mime_filter_class->reset = reset;
-}
+struct _CamelMimeFilterLinewrapPrivate {
+	guint wrap_len;
+	guint max_len;
+	gchar indent;
+	gint nchars;
+	guint32 flags;
+};
 
-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;
-}
+static gpointer parent_class;
 
 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_GET_PRIVATE (mime_filter);
+
+	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,93 @@ 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_GET_PRIVATE (mime_filter);
+
+	priv->nchars = 0;
 }
 
 static void
-reset (CamelMimeFilter *f)
+mime_filter_linewrap_class_init (CamelMimeFilterLinewrapClass *class)
 {
-	CamelMimeFilterLinewrap *linewrap = (CamelMimeFilterLinewrap *)f;
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterLinewrapPrivate));
 
-	linewrap->nchars = 0;
+	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
+mime_filter_linewrap_init (CamelMimeFilterLinewrap *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_LINEWRAP_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_linewrap_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterLinewrap",
+			sizeof (CamelMimeFilterLinewrapClass),
+			(GClassInitFunc) mime_filter_linewrap_class_init,
+			sizeof (CamelMimeFilterLinewrap),
+			(GInstanceInitFunc) mime_filter_linewrap_init,
+			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 = g_object_new (CAMEL_TYPE_MIME_FILTER_LINEWRAP, NULL);
+	priv = CAMEL_MIME_FILTER_LINEWRAP_GET_PRIVATE (filter);
 
-	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);
+	priv->indent = indent_char;
+	priv->wrap_len = preferred_len;
+	priv->max_len = max_len;
+	priv->nchars = 0;
+	priv->flags = flags | (indent_char == 0 ? CAMEL_MIME_FILTER_LINEWRAP_NOINDENT : 0);
 
-	return (CamelMimeFilter *) linewrap;
+	return filter;
 }
diff --git a/camel/camel-mime-filter-linewrap.h b/camel/camel-mime-filter-linewrap.h
index fada920..a9831af 100644
--- a/camel/camel-mime-filter-linewrap.h
+++ b/camel/camel-mime-filter-linewrap.h
@@ -19,15 +19,33 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_LINEWRAP_H
-#define _CAMEL_MIME_FILTER_LINEWRAP_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_LINEWRAP_H
+#define CAMEL_MIME_FILTER_LINEWRAP_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_LINEWRAP_TYPE         (camel_mime_filter_linewrap_get_type ())
-#define CAMEL_MIME_FILTER_LINEWRAP(obj)         CAMEL_CHECK_CAST (obj, CAMEL_MIME_FILTER_LINEWRAP_TYPE, CamelMimeFilterLinewrap)
-#define CAMEL_MIME_FILTER_LINEWRAP_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, CAMEL_MIME_FILTER_LINEWRAP_TYPE, CamelMimeFilterLinewrapClass)
-#define CAMEL_IS_MIME_FILTER_LINEWRAP(obj)      CAMEL_CHECK_TYPE (obj, CAMEL_MIME_FILTER_LINEWRAP_TYPE)
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_LINEWRAP \
+	(camel_mime_filter_linewrap_get_type ())
+#define CAMEL_MIME_FILTER_LINEWRAP(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_LINEWRAP, CamelMimeFilterLinewrap))
+#define CAMEL_MIME_FILTER_LINEWRAP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_LINEWRAP, CamelMimeFilterLinewrapClass))
+#define CAMEL_IS_MIME_FILTER_LINEWRAP(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_LINEWRAP))
+#define CAMEL_IS_MIME_FILTER_LINEWRAP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_LINEWRAP))
+#define CAMEL_MIME_FILTER_LINEWRAP_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_LINEWRAP, CamelMimeFilterLinewrapClass))
 
 G_BEGIN_DECLS
 
@@ -36,26 +54,26 @@ enum {
 	CAMEL_MIME_FILTER_LINEWRAP_WORD     = (1<<1), /* indents on word boundary */
 };
 
+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 {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType camel_mime_filter_linewrap_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_linewrap_new (guint preferred_len, guint max_len, gchar indent_char, guint32 flags);
+GType		camel_mime_filter_linewrap_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_linewrap_new	(guint preferred_len,
+						 guint max_len,
+						 gchar indent_char,
+                                                 guint32 flags);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_LINEWRAP_H */
+#endif /* CAMEL_MIME_FILTER_LINEWRAP_H */
diff --git a/camel/camel-mime-filter-pgp.c b/camel/camel-mime-filter-pgp.c
index d49c10c..d91f4a2 100644
--- a/camel/camel-mime-filter-pgp.c
+++ b/camel/camel-mime-filter-pgp.c
@@ -32,48 +32,9 @@
 
 #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 CAMEL_MIME_FILTER_PGP_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_PGP, CamelMimeFilterPgpPrivate))
 
 #define BEGIN_PGP_SIGNED_MESSAGE "-----BEGIN PGP SIGNED MESSAGE-----"
 #define BEGIN_PGP_SIGNATURE      "-----BEGIN PGP SIGNATURE-----"
@@ -83,20 +44,42 @@ 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 gpointer parent_class;
+
 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_GET_PRIVATE (mime_filter);
+
 	/* 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 +93,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 +105,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 +120,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 +140,94 @@ 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_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
+mime_filter_pgp_complete (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, TRUE);
 }
 
 static void
-filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_pgp_reset (CamelMimeFilter *mime_filter)
 {
-	filter_run (f, in, len, prespace, out, outlen, outprespace, FALSE);
+	CamelMimeFilterPgpPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_PGP_GET_PRIVATE (mime_filter);
+
+	priv->state = PGP_PREFACE;
 }
 
 static void
-complete (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_pgp_class_init (CamelMimeFilterPgpClass *class)
 {
-	filter_run (f, in, len, prespace, out, outlen, outprespace, TRUE);
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterPgpPrivate));
+
+	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)
+mime_filter_pgp_init (CamelMimeFilterPgp *filter)
 {
-	((CamelMimeFilterPgp *) f)->state = PGP_PREFACE;
+	filter->priv = CAMEL_MIME_FILTER_PGP_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_pgp_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterPgp",
+			sizeof (CamelMimeFilterPgpClass),
+			(GClassInitFunc) mime_filter_pgp_class_init,
+			sizeof (CamelMimeFilterPgp),
+			(GInstanceInitFunc) mime_filter_pgp_init,
+			0);
+
+	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 ());
+	return g_object_new (CAMEL_TYPE_MIME_FILTER_PGP, NULL);
 }
diff --git a/camel/camel-mime-filter-pgp.h b/camel/camel-mime-filter-pgp.h
index 852d15c..3c11358 100644
--- a/camel/camel-mime-filter-pgp.h
+++ b/camel/camel-mime-filter-pgp.h
@@ -19,31 +19,53 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_FILTER_PGP_H
-#define _CAMEL_MIME_FILTER_PGP_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_PGP_H
+#define CAMEL_MIME_FILTER_PGP_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_PGP_TYPE         (camel_mime_filter_canon_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)
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_PGP \
+	(camel_mime_filter_pgp_get_type ())
+#define CAMEL_MIME_FILTER_PGP(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_PGP, CamelMimeFilterPgp))
+#define CAMEL_MIME_FILTER_PGP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_PGP, CamelMimeFilterPgpClass))
+#define CAMEL_IS_MIME_FILTER_PGP(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_PGP))
+#define CAMEL_IS_MIME_FILTER_PGP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_PGP))
+#define CAMEL_MIME_FILTER_PGP_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_PGP, CamelMimeFilterPgpClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMimeFilterPgp {
-	CamelMimeFilter filter;
-	gint state;
-} CamelMimeFilterPgp;
+typedef struct _CamelMimeFilterPgp CamelMimeFilterPgp;
+typedef struct _CamelMimeFilterPgpClass CamelMimeFilterPgpClass;
+typedef struct _CamelMimeFilterPgpPrivate CamelMimeFilterPgpPrivate;
 
-typedef struct _CamelMimeFilterPgpClass {
-	CamelMimeFilterClass parent_class;
-} CamelMimeFilterPgpClass;
+struct _CamelMimeFilterPgp {
+	CamelMimeFilter parent;
+	CamelMimeFilterPgpPrivate *priv;
+};
 
-CamelType camel_mime_filter_pgp_get_type (void);
+struct _CamelMimeFilterPgpClass {
+	CamelMimeFilterClass parent_class;
+};
 
-CamelMimeFilter *camel_mime_filter_pgp_new(void);
+GType		camel_mime_filter_pgp_get_type	(void);
+CamelMimeFilter *
+		camel_mime_filter_pgp_new	(void);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_PGP_H */
+#endif /* CAMEL_MIME_FILTER_PGP_H */
diff --git a/camel/camel-mime-filter-progress.c b/camel/camel-mime-filter-progress.c
index b4a41f1..965618a 100644
--- a/camel/camel-mime-filter-progress.c
+++ b/camel/camel-mime-filter-progress.c
@@ -29,63 +29,42 @@
 
 #include "camel-mime-filter-progress.h"
 
+#define CAMEL_MIME_FILTER_PROGRESS_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_PROGRESS, CamelMimeFilterProgressPrivate))
+
 #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);
-
-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);
-	}
+struct _CamelMimeFilterProgressPrivate {
+	CamelOperation *operation;
+	gsize total;
+	gsize count;
+};
 
-	return type;
-}
+static gpointer parent_class;
 
 static void
-camel_mime_filter_progress_finalize (CamelObject *o)
+mime_filter_progress_filter (CamelMimeFilter *filter,
+                             const gchar *in,
+                             gsize len,
+                             gsize prespace,
+                             gchar **out,
+                             gsize *outlen,
+                             gsize *outprespace)
 {
-	;
-}
-
-static void
-camel_mime_filter_progress_init (CamelObject *o)
-{
-	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_GET_PRIVATE (filter);
+	priv->count += len;
 
-	if (progress->count < progress->total)
-		percent = ((double) progress->count * 100.0) / ((double) progress->total);
+	if (priv->count < priv->total)
+		percent = ((double) priv->count * 100.0) / ((double) 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 +72,64 @@ 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
+mime_filter_progress_reset (CamelMimeFilter *mime_filter)
+{
+	CamelMimeFilterProgressPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_PROGRESS_GET_PRIVATE (mime_filter);
+
+	priv->count = 0;
 }
 
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_progress_class_init (CamelMimeFilterProgressClass *class)
 {
-	CamelMimeFilterProgress *progress = (CamelMimeFilterProgress *) filter;
+	CamelMimeFilterClass *mime_filter_class;
 
-	progress->count = 0;
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterProgressPrivate));
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->reset = mime_filter_progress_reset;
+	mime_filter_class->filter = mime_filter_progress_filter;
+	mime_filter_class->complete = mime_filter_progress_complete;
 }
 
 static void
-camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *klass)
+mime_filter_progress_init (CamelMimeFilterProgress *filter)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	filter->priv = CAMEL_MIME_FILTER_PROGRESS_GET_PRIVATE (filter);
+}
 
-	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+GType
+camel_mime_filter_progress_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterProgress",
+			sizeof (CamelMimeFilterProgressClass),
+			(GClassInitFunc) mime_filter_progress_class_init,
+			sizeof (CamelMimeFilterProgress),
+			(GInstanceInitFunc) mime_filter_progress_init,
+			0);
 
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
+	return type;
 }
 
 /**
@@ -130,13 +143,19 @@ camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *klass)
  * Returns: a new #CamelMimeFilter object
  **/
 CamelMimeFilter *
-camel_mime_filter_progress_new (CamelOperation *operation, gsize total)
+camel_mime_filter_progress_new (CamelOperation *operation,
+                                gsize total)
 {
 	CamelMimeFilter *filter;
+	CamelMimeFilterProgressPrivate *priv;
+
+	g_return_val_if_fail (operation != NULL, NULL);
+
+	filter = g_object_new (CAMEL_TYPE_MIME_FILTER_PROGRESS, NULL);
+	priv = CAMEL_MIME_FILTER_PROGRESS_GET_PRIVATE (filter);
 
-	filter = (CamelMimeFilter *) camel_object_new (camel_mime_filter_progress_get_type ());
-	((CamelMimeFilterProgress *) filter)->operation = operation;
-	((CamelMimeFilterProgress *) filter)->total = total;
+	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 7e21b4c..e30c9bc 100644
--- a/camel/camel-mime-filter-progress.h
+++ b/camel/camel-mime-filter-progress.h
@@ -20,38 +20,55 @@
  *
  */
 
-#ifndef __CAMEL_MIME_FILTER_PROGRESS_H__
-#define __CAMEL_MIME_FILTER_PROGRESS_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_PROGRESS_H
+#define CAMEL_MIME_FILTER_PROGRESS_H
 
 #include <camel/camel-operation.h>
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_PROGRESS(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_progress_get_type (), CamelMimeFilterProgress)
-#define CAMEL_MIME_FILTER_PROGRESS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_progress_get_type (), CamelMimeFilterProgressClass)
-#define CAMEL_IS_MIME_FILTER_PROGRESS(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_progress_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_PROGRESS \
+	(camel_mime_filter_progress_get_type ())
+#define CAMEL_MIME_FILTER_PROGRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_PROGRESS, CamelMimeFilterProgress))
+#define CAMEL_MIME_FILTER_PROGRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_PROGRESS, CamelMimeFilterProgressClass))
+#define CAMEL_IS_MIME_FILTER_PROGRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_PROGRESS))
+#define CAMEL_IS_MIME_FILTER_PROGRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_PROGRESS))
+#define CAMEL_MIME_FILTER_PROGRESS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_PROGRESS, CamelMimeFilterProgressClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMimeFilterProgressClass CamelMimeFilterProgressClass;
 typedef struct _CamelMimeFilterProgress CamelMimeFilterProgress;
+typedef struct _CamelMimeFilterProgressClass CamelMimeFilterProgressClass;
+typedef struct _CamelMimeFilterProgressPrivate CamelMimeFilterProgressPrivate;
 
 struct _CamelMimeFilterProgress {
 	CamelMimeFilter parent;
-
-	CamelOperation *operation;
-	gsize total;
-        gsize count;
+	CamelMimeFilterProgressPrivate *priv;
 };
 
 struct _CamelMimeFilterProgressClass {
 	CamelMimeFilterClass parent_class;
-
 };
 
-CamelType camel_mime_filter_progress_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_progress_new (CamelOperation *operation, gsize total);
+GType		camel_mime_filter_progress_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_progress_new	(CamelOperation *operation,
+						 gsize total);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MIME_FILTER_PROGRESS_H__ */
+#endif /* CAMEL_MIME_FILTER_PROGRESS_H */
diff --git a/camel/camel-mime-filter-save.c b/camel/camel-mime-filter-save.c
index 707ea07..fa5aed0 100644
--- a/camel/camel-mime-filter-save.c
+++ b/camel/camel-mime-filter-save.c
@@ -27,89 +27,91 @@
 #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);
+#define CAMEL_MIME_FILTER_SAVE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_SAVE, CamelMimeFilterSavePrivate))
 
-static void
-camel_mime_filter_save_class_init (CamelMimeFilterSaveClass *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_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);
-	}
+struct _CamelMimeFilterSavePrivate {
+	CamelStream *stream;
+};
 
-	return type;
-}
+static gpointer parent_class;
 
 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_GET_PRIVATE (mime_filter);
+
+	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_class_init (CamelMimeFilterSaveClass *class)
 {
-	/* no-op */
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterSavePrivate));
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_save_filter;
+	mime_filter_class->complete = mime_filter_save_complete;
 }
 
-/**
- * camel_mime_filter_save_new:
- *
- * Create a new #CamelMimeFilterSave filter object.
- *
- * Returns: a new #CamelMimeFilterSave object
- **/
-CamelMimeFilter *
-camel_mime_filter_save_new (void)
+static void
+mime_filter_save_init (CamelMimeFilterSave *filter)
 {
-	CamelMimeFilterSave *save = CAMEL_MIME_FILTER_SAVE (camel_object_new (CAMEL_MIME_FILTER_SAVE_TYPE));
+	filter->priv = CAMEL_MIME_FILTER_SAVE_GET_PRIVATE (filter);
+}
 
-	save->stream = camel_stream_mem_new ();
+GType
+camel_mime_filter_save_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterSave",
+			sizeof (CamelMimeFilterSaveClass),
+			(GClassInitFunc) mime_filter_save_class_init,
+			sizeof (CamelMimeFilterSave),
+			(GInstanceInitFunc) mime_filter_save_init,
+			0);
 
-	return (CamelMimeFilter *) save;
+	return type;
 }
 
 /**
- * camel_mime_filter_save_new_with_stream:
+ * camel_mime_filter_save_new:
  * @stream: a #CamelStream object
  *
  * Create a new #CamelMimeFilterSave filter object that will save a
@@ -118,12 +120,21 @@ camel_mime_filter_save_new (void)
  * Returns: a new #CamelMimeFilterSave object
  **/
 CamelMimeFilter *
-camel_mime_filter_save_new_with_stream (CamelStream *stream)
+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 = g_object_new (CAMEL_TYPE_MIME_FILTER_SAVE, NULL);
+	priv = CAMEL_MIME_FILTER_SAVE_GET_PRIVATE (filter);
 
-	save->stream = stream;
-	camel_object_ref (stream);
+	if (stream != NULL)
+		priv->stream = g_object_ref (stream);
+	else
+		priv->stream = camel_stream_mem_new ();
 
-	return (CamelMimeFilter *) save;
+	return filter;
 }
diff --git a/camel/camel-mime-filter-save.h b/camel/camel-mime-filter-save.h
index 2f63c99..4da8213 100644
--- a/camel/camel-mime-filter-save.h
+++ b/camel/camel-mime-filter-save.h
@@ -20,36 +20,54 @@
  *
  */
 
-#ifndef __CAMEL_MIME_FILTER_SAVE_H__
-#define __CAMEL_MIME_FILTER_SAVE_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_SAVE_H
+#define CAMEL_MIME_FILTER_SAVE_H
 
 #include <camel/camel-mime-filter.h>
 #include <camel/camel-seekable-stream.h>
 
-#define CAMEL_MIME_FILTER_SAVE_TYPE         (camel_mime_filter_save_get_type ())
-#define CAMEL_MIME_FILTER_SAVE(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_save_get_type (), CamelMimeFilterSave)
-#define CAMEL_MIME_FILTER_SAVE_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_save_get_type (), CamelMimeFilterSaveClass)
-#define CAMEL_IS_MIME_FILTER_SAVE(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_save_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_SAVE \
+	(camel_mime_filter_save_get_type ())
+#define CAMEL_MIME_FILTER_SAVE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_SAVE, CamelMimeFilterSave))
+#define CAMEL_MIME_FILTER_SAVE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_SAVE, CamelMimeFilterSaveClass))
+#define CAMEL_IS_MIME_FILTER_SAVE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_SAVE))
+#define CAMEL_IS_MIME_FILTER_SAVE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_SAVE))
+#define CAMEL_MIME_FILTER_SAVE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_SAVE, CamelMimeFilterSaveClass))
 
 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 {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType camel_mime_filter_save_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_save_new (void);
-CamelMimeFilter *camel_mime_filter_save_new_with_stream (CamelStream *stream);
+GType		camel_mime_filter_save_get_type	(void);
+CamelMimeFilter *
+		camel_mime_filter_save_new	(CamelStream *stream);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MIME_FILTER_SAVE_H__ */
+#endif /* CAMEL_MIME_FILTER_SAVE_H */
diff --git a/camel/camel-mime-filter-tohtml.c b/camel/camel-mime-filter-tohtml.c
index 93e7be9..0b06614 100644
--- a/camel/camel-mime-filter-tohtml.c
+++ b/camel/camel-mime-filter-tohtml.c
@@ -31,6 +31,21 @@
 #include "camel-url-scanner.h"
 #include "camel-utf8.h"
 
+#define CAMEL_MIME_FILTER_TOHTML_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_TOHTML, CamelMimeFilterToHTMLPrivate))
+
+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 +83,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->colour = 0;
-	filter->column = 0;
-	filter->pre_open = FALSE;
-}
+static gpointer parent_class;
 
 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 +150,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_GET_PRIVATE (mime_filter);
+
 	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 +173,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 +209,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 +223,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_GET_PRIVATE (mime_filter);
+
 	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 +261,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 +281,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 colour depths here */
+				/* FIXME: we could easily support multiple color depths here */
 
-				outptr = check_size (filter, outptr, &outend, 25);
-				outptr += sprintf(outptr, "<font color=\"#%06x\">", (html->colour & 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 +297,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 +322,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,62 +375,123 @@ 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
+mime_filter_tohtml_finalize (GObject *object)
+{
+	CamelMimeFilterToHTMLPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_TOHTML_GET_PRIVATE (object);
+
+	camel_url_scanner_free (priv->scanner);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-filter_filter (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, FALSE);
+	html_convert (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, FALSE);
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_tohtml_complete (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, TRUE);
 }
 
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_tohtml_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterToHTML *html = (CamelMimeFilterToHTML *) filter;
+	CamelMimeFilterToHTMLPrivate *priv;
 
-	html->column = 0;
-	html->pre_open = FALSE;
+	priv = CAMEL_MIME_FILTER_TOHTML_GET_PRIVATE (mime_filter);
+
+	priv->column = 0;
+	priv->pre_open = FALSE;
 }
 
 static void
-camel_mime_filter_tohtml_class_init (CamelMimeFilterToHTMLClass *klass)
+mime_filter_tohtml_class_init (CamelMimeFilterToHTMLClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	GObjectClass *object_class;
+	CamelMimeFilterClass *filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterToHTMLPrivate));
 
-	camel_mime_filter_tohtml_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = mime_filter_tohtml_finalize;
 
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
+	filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	filter_class->filter = mime_filter_tohtml_filter;
+	filter_class->complete = mime_filter_tohtml_complete;
+	filter_class->reset = mime_filter_tohtml_reset;
+}
+
+static void
+mime_filter_tohtml_init (CamelMimeFilterToHTML *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_TOHTML_GET_PRIVATE (filter);
+
+	filter->priv->scanner = camel_url_scanner_new ();
+}
+
+GType
+camel_mime_filter_tohtml_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterToHTML",
+			sizeof (CamelMimeFilterToHTMLClass),
+			(GClassInitFunc) mime_filter_tohtml_class_init,
+			sizeof (CamelMimeFilterToHTML),
+			(GInstanceInitFunc) mime_filter_tohtml_init,
+			0);
+
+	return type;
 }
 
 /**
  * camel_mime_filter_tohtml_new:
  * @flags: bitwise flags defining the behaviour
- * @colour: colour to use when highlighting quoted text
+ * @color: color to use when highlighting quoted text
  *
  * Create a new #CamelMimeFilterToHTML object to convert plain text
  * into HTML.
@@ -444,29 +499,32 @@ camel_mime_filter_tohtml_class_init (CamelMimeFilterToHTMLClass *klass)
  * Returns: a new #CamelMimeFilterToHTML object
  **/
 CamelMimeFilter *
-camel_mime_filter_tohtml_new (guint32 flags, guint32 colour)
+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 = g_object_new (CAMEL_TYPE_MIME_FILTER_TOHTML, NULL);
+	priv = CAMEL_MIME_FILTER_TOHTML_GET_PRIVATE (filter);
 
-	new->flags = flags;
-	new->colour = colour;
+	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;
 }
 
 /**
  * camel_text_to_html:
  * @in: input text
  * @flags: bitwise flags defining the html conversion behaviour
- * @colour: colour to use when syntax highlighting
+ * @color: color to use when syntax highlighting
  *
  * Convert @in from plain text into HTML.
  *
@@ -474,7 +532,7 @@ camel_mime_filter_tohtml_new (guint32 flags, guint32 colour)
  * of @in
  **/
 gchar *
-camel_text_to_html (const gchar *in, guint32 flags, guint32 colour)
+camel_text_to_html (const gchar *in, guint32 flags, guint32 color)
 {
 	CamelMimeFilter *filter;
 	gsize outlen, outpre;
@@ -482,14 +540,14 @@ camel_text_to_html (const gchar *in, guint32 flags, guint32 colour)
 
 	g_return_val_if_fail (in != NULL, NULL);
 
-	filter = camel_mime_filter_tohtml_new (flags, colour);
+	filter = camel_mime_filter_tohtml_new (flags, color);
 
 	camel_mime_filter_complete (filter, (gchar *) in, strlen (in), 0,
 				    &outbuf, &outlen, &outpre);
 
 	outbuf = g_strndup (outbuf, outlen);
 
-	camel_object_unref (filter);
+	g_object_unref (filter);
 
 	return outbuf;
 }
diff --git a/camel/camel-mime-filter-tohtml.h b/camel/camel-mime-filter-tohtml.h
index f485536..836b3f9 100644
--- a/camel/camel-mime-filter-tohtml.h
+++ b/camel/camel-mime-filter-tohtml.h
@@ -20,14 +20,33 @@
  *
  */
 
-#ifndef __CAMEL_MIME_FILTER_TOHTML_H__
-#define __CAMEL_MIME_FILTER_TOHTML_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_TOHTML_H
+#define CAMEL_MIME_FILTER_TOHTML_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_TOHTML(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_tohtml_get_type (), CamelMimeFilterToHTML)
-#define CAMEL_MIME_FILTER_TOHTML_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_tohtml_get_type (), CamelMimeFilterToHTMLClass)
-#define CAMEL_IS_MIME_FILTER_TOHTML(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_tohtml_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_TOHTML \
+	(camel_mime_filter_tohtml_get_type ())
+#define CAMEL_MIME_FILTER_TOHTML(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_TOHTML, CamelMimeFilterToHTML))
+#define CAMEL_MIME_FILTER_TOHTML_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_TOHTML, CamelMimeFilterToHTMLClass))
+#define CAMEL_IS_MIME_FILTER_TOHTML(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_TOHTML))
+#define CAMEL_IS_MIME_FILTER_TOHTML_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_TOHTML))
+#define CAMEL_MIME_FILTER_TOHTML_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_TOHTML, CamelMimeFilterToHTMLClass))
 
 #define CAMEL_MIME_FILTER_TOHTML_PRE               (1 << 0)
 #define CAMEL_MIME_FILTER_TOHTML_CONVERT_NL        (1 << 1)
@@ -42,33 +61,30 @@
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMimeFilterToHTMLClass CamelMimeFilterToHTMLClass;
 typedef struct _CamelMimeFilterToHTML CamelMimeFilterToHTML;
+typedef struct _CamelMimeFilterToHTMLClass CamelMimeFilterToHTMLClass;
+typedef struct _CamelMimeFilterToHTMLPrivate CamelMimeFilterToHTMLPrivate;
 
 struct _CamelMimeFilterToHTML {
 	CamelMimeFilter parent;
-
-	struct _CamelUrlScanner *scanner;
-
-	guint32 flags;
-	guint32 colour;
-
-	guint32 column   : 31;
-	guint32 pre_open : 1;
+	CamelMimeFilterToHTMLPrivate *priv;
 };
 
 struct _CamelMimeFilterToHTMLClass {
 	CamelMimeFilterClass parent_class;
 };
 
-CamelType        camel_mime_filter_tohtml_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_tohtml_new (guint32 flags, guint32 colour);
+GType		camel_mime_filter_tohtml_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_tohtml_new	(guint32 flags,
+						 guint32 color);
 
 /* utility functions to replace e_text_to_html */
 
-gchar *camel_text_to_html (const gchar *in, guint32 flags, guint32 colour);
+gchar *		camel_text_to_html		(const gchar *in,
+						 guint32 flags,
+						 guint32 color);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MIME_FILTER_TOHTML_H__ */
+#endif /* CAMEL_MIME_FILTER_TOHTML_H */
diff --git a/camel/camel-mime-filter-windows.c b/camel/camel-mime-filter-windows.c
index 1a343b4..ad6590a 100644
--- a/camel/camel-mime-filter-windows.c
+++ b/camel/camel-mime-filter-windows.c
@@ -31,60 +31,49 @@
 #include "camel-charset-map.h"
 #include "camel-mime-filter-windows.h"
 
+#define CAMEL_MIME_FILTER_WINDOWS_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_WINDOWS, CamelMimeFilterWindowsPrivate))
+
 #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;
+struct _CamelMimeFilterWindowsPrivate {
+	gboolean is_windows;
+	gchar *claimed_charset;
+};
 
-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;
-}
+static gpointer parent_class;
 
 static void
-camel_mime_filter_windows_finalize (CamelObject *o)
+mime_filter_windows_finalize (GObject *object)
 {
-	CamelMimeFilterWindows *windows = (CamelMimeFilterWindows *) o;
+	CamelMimeFilterWindowsPrivate *priv;
 
-	g_free (windows->claimed_charset);
-}
+	priv = CAMEL_MIME_FILTER_WINDOWS_GET_PRIVATE (object);
 
-static void
-camel_mime_filter_windows_init (CamelObject *o)
-{
-	CamelMimeFilterWindows *windows = (CamelMimeFilterWindows *) o;
+	g_free (priv->claimed_charset);
 
-	windows->is_windows = FALSE;
-	windows->claimed_charset = NULL;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_windows_filter (CamelMimeFilter *mime_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_GET_PRIVATE (mime_filter);
+
+	if (!priv->is_windows) {
 		inptr = (guchar *) in;
 		inend = inptr + len;
 
@@ -93,8 +82,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 +95,68 @@ 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_GET_PRIVATE (mime_filter);
 
-	windows->is_windows = FALSE;
+	priv->is_windows = FALSE;
 }
 
 static void
-camel_mime_filter_windows_class_init (CamelMimeFilterWindowsClass *klass)
+mime_filter_windows_class_init (CamelMimeFilterWindowsClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	GObjectClass *object_class;
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterWindowsPrivate));
 
-	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = mime_filter_windows_finalize;
 
-	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
+mime_filter_windows_init (CamelMimeFilterWindows *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_WINDOWS_GET_PRIVATE (filter);
+}
+
+GType
+camel_mime_filter_windows_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterWindows",
+			sizeof (CamelMimeFilterWindowsClass),
+			(GClassInitFunc) mime_filter_windows_class_init,
+			sizeof (CamelMimeFilterWindows),
+			(GInstanceInitFunc) mime_filter_windows_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -144,15 +171,17 @@ 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 = g_object_new (CAMEL_TYPE_MIME_FILTER_WINDOWS, NULL);
+	priv = CAMEL_MIME_FILTER_WINDOWS_GET_PRIVATE (filter);
 
-	new->claimed_charset = g_strdup (claimed_charset);
+	priv->claimed_charset = g_strdup (claimed_charset);
 
-	return CAMEL_MIME_FILTER (new);
+	return filter;
 }
 
 /**
@@ -171,7 +200,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 +217,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 355946c..62401cd 100644
--- a/camel/camel-mime-filter-windows.h
+++ b/camel/camel-mime-filter-windows.h
@@ -20,39 +20,58 @@
  *
  */
 
-#ifndef __CAMEL_MIME_FILTER_WINDOWS_H__
-#define __CAMEL_MIME_FILTER_WINDOWS_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_WINDOWS_H
+#define CAMEL_MIME_FILTER_WINDOWS_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_WINDOWS(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_windows_get_type (), CamelMimeFilterWindows)
-#define CAMEL_MIME_FILTER_WINDOWS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_windows_get_type (), CamelMimeFilterWindowsClass)
-#define CAMEL_IS_MIME_FILTER_WINDOWS(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_windows_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_WINDOWS \
+	(camel_mime_filter_windows_get_type ())
+#define CAMEL_MIME_FILTER_WINDOWS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_WINDOWS, CamelMimeFilterWindows))
+#define CAMEL_MIME_FILTER_WINDOWS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_WINDOWS, CamelMimeFilterWindowsClass))
+#define CAMEL_IS_MIME_FILTER_WINDOWS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_WINDOWS))
+#define CAMEL_IS_MIME_FILTER_WINDOWS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_WINDOWS))
+#define CAMEL_MIME_FILTER_WINDOWS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_WINDOWS, CamelMimeFilterWindowsClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMimeFilterWindowsClass CamelMimeFilterWindowsClass;
 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 {
 	CamelMimeFilterClass parent_class;
-
 };
 
-CamelType camel_mime_filter_windows_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_windows_new (const gchar *claimed_charset);
-
-gboolean camel_mime_filter_windows_is_windows_charset (CamelMimeFilterWindows *filter);
-const gchar *camel_mime_filter_windows_real_charset (CamelMimeFilterWindows *filter);
+GType		camel_mime_filter_windows_get_type (void);
+CamelMimeFilter *
+		camel_mime_filter_windows_new
+					(const gchar *claimed_charset);
+gboolean	camel_mime_filter_windows_is_windows_charset
+					(CamelMimeFilterWindows *filter);
+const gchar *	camel_mime_filter_windows_real_charset
+					(CamelMimeFilterWindows *filter);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MIME_FILTER_WINDOWS_H__ */
+#endif /* CAMEL_MIME_FILTER_WINDOWS_H */
diff --git a/camel/camel-mime-filter-yenc.c b/camel/camel-mime-filter-yenc.c
index 9434acb..3f81cc5 100644
--- a/camel/camel-mime-filter-yenc.c
+++ b/camel/camel-mime-filter-yenc.c
@@ -28,74 +28,48 @@
 
 #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);
+#define CAMEL_MIME_FILTER_YENC_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER_YENC, 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);
+struct _CamelMimeFilterYencPrivate {
 
-static CamelMimeFilterClass *parent_class = NULL;
+	CamelMimeFilterYencDirection direction;
 
-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;
-}
-
-static void
-camel_mime_filter_yenc_class_init (CamelMimeFilterYencClass *klass)
-{
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	gint part;
 
-	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;
-}
+	gint state;
+	guint32 pcrc;
+	guint32 crc;
+};
 
-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;
-}
+static gpointer parent_class;
 
 /* 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)
+mime_filter_yenc_filter (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_GET_PRIVATE (mime_filter);
+
+	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_step ((const guchar *) in, len, (guchar *) filter->outbuf, &yenc->state,
-					     &yenc->pcrc, &yenc->crc);
+		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 (!(yenc->state & CAMEL_MIME_YDECODE_STATE_DECODE)) {
+		if (!(priv->state & CAMEL_MIME_YDECODE_STATE_DECODE)) {
 			const gchar *inptr, *inend;
 			gsize left;
 
@@ -103,25 +77,25 @@ filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 			inend = inptr + len;
 
 			/* we cannot start decoding until we have found an =ybegin line */
-			if (!(yenc->state & CAMEL_MIME_YDECODE_STATE_BEGIN)) {
+			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 (filter, inptr, 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++;
-							yenc->state |= CAMEL_MIME_YDECODE_STATE_BEGIN;
+							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 (filter, in, left);
+							camel_mime_filter_backup (mime_filter, in, left);
 						}
 						break;
 					}
@@ -136,32 +110,32 @@ filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 			}
 
 			left = inend - inptr;
-			if ((yenc->state & CAMEL_MIME_YDECODE_STATE_BEGIN) && left > 0) {
+			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 (filter, inptr, 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_PART | CAMEL_MIME_YDECODE_STATE_DECODE;
+						priv->state |= CAMEL_MIME_YDECODE_STATE_PART | CAMEL_MIME_YDECODE_STATE_DECODE;
 						in = inptr;
 						len = inend - in;
 					} else {
-						camel_mime_filter_backup (filter, in, left);
+						camel_mime_filter_backup (mime_filter, in, left);
 					}
 				} else {
 					/* guess it doesn't have a =ypart line */
-					yenc->state |= CAMEL_MIME_YDECODE_STATE_DECODE;
+					priv->state |= CAMEL_MIME_YDECODE_STATE_DECODE;
 				}
 			}
 		}
 
-		if ((yenc->state & CAMEL_MIME_YDECODE_STATE_DECODE) && !(yenc->state & CAMEL_MIME_YDECODE_STATE_END)) {
+		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 (filter, len + 3, FALSE);
-			newlen = camel_ydecode_step ((const guchar *) in, len, (guchar *) filter->outbuf, &yenc->state, &yenc->pcrc, &yenc->crc);
+			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;
@@ -169,32 +143,39 @@ filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 		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_GET_PRIVATE (mime_filter);
+
+	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);
+		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 ((yenc->state & CAMEL_MIME_YDECODE_STATE_DECODE) && !(yenc->state & CAMEL_MIME_YDECODE_STATE_END)) {
+		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 (filter, len + 3, FALSE);
-			newlen = camel_ydecode_step ((const guchar *) in, len, (guchar *) filter->outbuf, &yenc->state,
-						      &yenc->pcrc, &yenc->crc);
+			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;
@@ -202,27 +183,71 @@ filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize pres
 		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 *mime_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_GET_PRIVATE (mime_filter);
+
+	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
+mime_filter_yenc_class_init (CamelMimeFilterYencClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterYencPrivate));
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->reset = mime_filter_yenc_reset;
+	mime_filter_class->filter = mime_filter_yenc_filter;
+	mime_filter_class->complete = mime_filter_yenc_complete;
+}
+
+static void
+mime_filter_yenc_init (CamelMimeFilterYenc *filter)
+{
+	filter->priv = CAMEL_MIME_FILTER_YENC_GET_PRIVATE (filter);
+
+	filter->priv->part = 0;
+	filter->priv->pcrc = CAMEL_MIME_YENCODE_CRC_INIT;
+	filter->priv->crc = CAMEL_MIME_YENCODE_CRC_INIT;
+}
+
+GType
+camel_mime_filter_yenc_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_FILTER,
+			"CamelMimeFilterYenc",
+			sizeof (CamelMimeFilterYencClass),
+			(GClassInitFunc) mime_filter_yenc_class_init,
+			sizeof (CamelMimeFilterYenc),
+			(GInstanceInitFunc) mime_filter_yenc_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -236,23 +261,26 @@ filter_reset (CamelMimeFilter *filter)
 CamelMimeFilter *
 camel_mime_filter_yenc_new (CamelMimeFilterYencDirection direction)
 {
-	CamelMimeFilterYenc *new;
+	CamelMimeFilter *filter;
+	CamelMimeFilterYencPrivate *priv;
 
-	new = (CamelMimeFilterYenc *) camel_object_new (CAMEL_TYPE_MIME_FILTER_YENC);
-	new->direction = direction;
+	filter = g_object_new (CAMEL_TYPE_MIME_FILTER_YENC, NULL);
+	priv = CAMEL_MIME_FILTER_YENC_GET_PRIVATE (filter);
+
+	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 +295,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,31 +310,8 @@ camel_mime_filter_yenc_set_crc (CamelMimeFilterYenc *yenc, guint32 crc)
 {
 	g_return_if_fail (CAMEL_IS_MIME_FILTER_YENC (yenc));
 
-	yenc->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;
+	yenc->priv->crc = crc;
 }
-#endif
 
 /**
  * camel_mime_filter_yenc_get_pcrc:
@@ -321,7 +326,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 +342,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 4a3ade1..8e36ebc 100644
--- a/camel/camel-mime-filter-yenc.h
+++ b/camel/camel-mime-filter-yenc.h
@@ -20,22 +20,39 @@
  *
  */
 
-#ifndef __CAMEL_MIME_FILTER_YENC_H__
-#define __CAMEL_MIME_FILTER_YENC_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_YENC_H
+#define CAMEL_MIME_FILTER_YENC_H
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_TYPE_MIME_FILTER_YENC            (camel_mime_filter_yenc_get_type ())
-#define CAMEL_MIME_FILTER_YENC(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_MIME_FILTER_YENC, CamelMimeFilterYenc))
-#define CAMEL_MIME_FILTER_YENC_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_MIME_FILTER_YENC, CamelMimeFilterYencClass))
-#define CAMEL_IS_MIME_FILTER_YENC(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_MIME_FILTER_YENC))
-#define CAMEL_IS_MIME_FILTER_YENC_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_MIME_FILTER_YENC))
-#define CAMEL_MIME_FILTER_YENC_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_MIME_FILTER_YENC, CamelMimeFilterYencClass))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER_YENC \
+	(camel_mime_filter_yenc_get_type ())
+#define CAMEL_MIME_FILTER_YENC(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_FILTER_YENC, CamelMimeFilterYenc))
+#define CAMEL_MIME_FILTER_YENC_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER_YENC, CamelMimeFilterYencClass))
+#define CAMEL_IS_MIME_FILTER_YENC(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER_YENC))
+#define CAMEL_IS_MIME_FILTER_YENC_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER_YENC))
+#define CAMEL_MIME_FILTER_YENC_GET_CLASS(obj) \
+	(CAMEL_CHECK_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER_YENC, CamelMimeFilterYencClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterYenc CamelMimeFilterYenc;
 typedef struct _CamelMimeFilterYencClass CamelMimeFilterYencClass;
+typedef struct _CamelMimeFilterYencPrivate CamelMimeFilterYencPrivate;
 
 typedef enum {
 	CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE,
@@ -62,40 +79,43 @@ typedef enum {
 #define CAMEL_MIME_YENCODE_CRC_FINAL(crc) (~crc)
 
 struct _CamelMimeFilterYenc {
-	CamelMimeFilter parent_object;
-
-	CamelMimeFilterYencDirection direction;
-
-	gint part;
-
-	gint state;
-	guint32 pcrc;
-	guint32 crc;
+	CamelMimeFilter parent;
+	CamelMimeFilterYencPrivate *priv;
 };
 
 struct _CamelMimeFilterYencClass {
 	CamelMimeFilterClass parent_class;
-
 };
 
-CamelType camel_mime_filter_yenc_get_type (void);
-
-CamelMimeFilter *camel_mime_filter_yenc_new (CamelMimeFilterYencDirection direction);
-
-void camel_mime_filter_yenc_set_state (CamelMimeFilterYenc *yenc, gint state);
-void camel_mime_filter_yenc_set_crc (CamelMimeFilterYenc *yenc, guint32 crc);
-
-/*int     camel_mime_filter_yenc_get_part (CamelMimeFilterYenc *yenc);*/
-guint32 camel_mime_filter_yenc_get_pcrc (CamelMimeFilterYenc *yenc);
-guint32 camel_mime_filter_yenc_get_crc (CamelMimeFilterYenc *yenc);
-
-gsize camel_ydecode_step  (const guchar *in, gsize inlen, guchar *out,
-			    gint *state, guint32 *pcrc, guint32 *crc);
-gsize camel_yencode_step  (const guchar *in, gsize inlen, guchar *out,
-			    gint *state, guint32 *pcrc, guint32 *crc);
-gsize camel_yencode_close (const guchar *in, gsize inlen, guchar *out,
-			    gint *state, guint32 *pcrc, guint32 *crc);
+GType		camel_mime_filter_yenc_get_type	(void);
+CamelMimeFilter *
+		camel_mime_filter_yenc_new	(CamelMimeFilterYencDirection direction);
+void		camel_mime_filter_yenc_set_state(CamelMimeFilterYenc *yenc,
+						 gint state);
+void		camel_mime_filter_yenc_set_crc	(CamelMimeFilterYenc *yenc,
+						 guint32 crc);
+guint32		camel_mime_filter_yenc_get_pcrc	(CamelMimeFilterYenc *yenc);
+guint32		camel_mime_filter_yenc_get_crc	(CamelMimeFilterYenc *yenc);
+
+gsize		camel_ydecode_step		(const guchar *in,
+						 gsize inlen,
+						 guchar *out,
+						 gint *state,
+						 guint32 *pcrc,
+						 guint32 *crc);
+gsize		camel_yencode_step		(const guchar *in,
+						 gsize inlen,
+						 guchar *out,
+						 gint *state,
+						 guint32 *pcrc,
+						 guint32 *crc);
+gsize		camel_yencode_close		(const guchar *in,
+						 gsize inlen,
+						 guchar *out,
+						 gint *state,
+						 guint32 *pcrc,
+						 guint32 *crc);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MIME_FILTER_YENC_H__ */
+#endif /* CAMEL_MIME_FILTER_YENC_H */
diff --git a/camel/camel-mime-filter.c b/camel/camel-mime-filter.c
index af4e090..4cf4fab 100644
--- a/camel/camel-mime-filter.c
+++ b/camel/camel-mime-filter.c
@@ -29,6 +29,10 @@
 #include <mcheck.h>
 #endif
 
+#define CAMEL_MIME_FILTER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_FILTER, CamelMimeFilterPrivate))
+
 struct _CamelMimeFilterPrivate {
 	gchar *inbuf;
 	gsize inlen;
@@ -36,71 +40,80 @@ 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 gpointer parent_class;
 
 static void
-camel_mime_filter_class_init (CamelMimeFilterClass *klass)
+mime_filter_finalize (GObject *object)
 {
-	camel_mime_filter_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
+	CamelMimeFilter *mime_filter;
+
+	mime_filter = CAMEL_MIME_FILTER (object);
+
+	g_free (mime_filter->outreal);
+	g_free (mime_filter->backbuf);
+	g_free (mime_filter->priv->inbuf);
 
-	klass->complete = complete;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 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;
-
-	obj->backbuf = NULL;
-	obj->backsize = 0;
-	obj->backlen = 0;
-
-	_PRIVATE(obj) = g_malloc0(sizeof(*obj->priv));
+	/* default - do nothing */
 }
 
 static void
-camel_mime_filter_finalize(CamelObject *o)
+mime_filter_class_init (CamelMimeFilterClass *class)
 {
-	CamelMimeFilter *f = (CamelMimeFilter *)o;
-	struct _CamelMimeFilterPrivate *p = _PRIVATE(f);
+	GObjectClass *object_class;
 
-	g_free(f->outreal);
-	g_free(f->backbuf);
-	g_free(p->inbuf);
-	g_free(p);
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimeFilterPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = mime_filter_finalize;
+
+	class->complete = mime_filter_complete;
 }
 
-CamelType
-camel_mime_filter_get_type (void)
+static void
+mime_filter_init (CamelMimeFilter *mime_filter)
 {
-	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",
-							      sizeof (CamelMimeFilter),
-							      sizeof (CamelMimeFilterClass),
-							      (CamelObjectClassInitFunc) camel_mime_filter_class_init,
-							      NULL,
-							      (CamelObjectInitFunc) camel_mime_filter_init,
-							      (CamelObjectFinalizeFunc) camel_mime_filter_finalize);
-	}
+	mime_filter->priv = CAMEL_MIME_FILTER_GET_PRIVATE (mime_filter);
+
+	mime_filter->outreal = NULL;
+	mime_filter->outbuf = NULL;
+	mime_filter->outsize = 0;
 
-	return camel_mime_filter_type;
+	mime_filter->backbuf = NULL;
+	mime_filter->backsize = 0;
+	mime_filter->backlen = 0;
 }
 
-static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+GType
+camel_mime_filter_get_type (void)
 {
-	/* default - do nothing */
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelMimeFilter",
+			sizeof (CamelMimeFilterClass),
+			(GClassInitFunc) mime_filter_class_init,
+			sizeof (CamelMimeFilter),
+			(GInstanceInitFunc) mime_filter_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -113,8 +126,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 g_object_new (CAMEL_TYPE_MIME_FILTER, NULL);
 }
 
 #ifdef MALLOC_CHECK
@@ -158,7 +170,7 @@ static void filter_run(CamelMimeFilter *f,
 	*/
 	if (prespace < f->backlen) {
 		gint newlen = len+prespace+f->backlen;
-		p = _PRIVATE(f);
+		p = CAMEL_MIME_FILTER_GET_PRIVATE(f);
 		if (p->inlen < newlen) {
 			/* NOTE: g_realloc copies data, we dont need that (slower) */
 			g_free(p->inbuf);
@@ -209,13 +221,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 +259,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 +286,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 4849829..63650ba 100644
--- a/camel/camel-mime-filter.h
+++ b/camel/camel-mime-filter.h
@@ -21,25 +21,44 @@
 
 /* Abstract class for non-copying filters */
 
-#ifndef _CAMEL_MIME_FILTER_H
-#define _CAMEL_MIME_FILTER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_FILTER_H
+#define CAMEL_MIME_FILTER_H
 
 #include <sys/types.h>
 #include <camel/camel-object.h>
 
-#define CAMEL_MIME_FILTER_TYPE         (camel_mime_filter_get_type ())
-#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 ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_FILTER \
+	(camel_mime_filter_get_type ())
+#define CAMEL_MIME_FILTER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj),  CAMEL_TYPE_MIME_FILTER, CamelMimeFilter))
+#define CAMEL_MIME_FILTER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_FILTER, CamelMimeFilterClass))
+#define CAMEL_IS_MIME_FILTER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_FILTER))
+#define CAMEL_IS_MIME_FILTER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_FILTER))
+#define CAMEL_MIME_FILTER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_FILTER, CamelMimeFilterClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMimeFilter CamelMimeFilter;
 typedef struct _CamelMimeFilterClass CamelMimeFilterClass;
+typedef struct _CamelMimeFilterPrivate CamelMimeFilterPrivate;
 
 struct _CamelMimeFilter {
 	CamelObject parent;
-
-	struct _CamelMimeFilterPrivate *priv;
+	CamelMimeFilterPrivate *priv;
 
 	gchar *outreal;		/* real malloc'd buffer */
 	gchar *outbuf;		/* first 'writable' position allowed (outreal + outpre) */
@@ -55,35 +74,52 @@ struct _CamelMimeFilter {
 struct _CamelMimeFilterClass {
 	CamelObjectClass parent_class;
 
-	/* virtual functions */
-	void (*filter)(CamelMimeFilter *f,
-		       const gchar *in, gsize len, gsize prespace,
-		       gchar **out, gsize *outlen, gsize *outprespace);
-	void (*complete)(CamelMimeFilter *f,
-			 const gchar *in, gsize len, gsize prespace,
-			 gchar **out, gsize *outlen, gsize *outprespace);
-	void (*reset)(CamelMimeFilter *f);
+	void		(*filter)		(CamelMimeFilter *filter,
+						 const gchar *in,
+						 gsize len,
+						 gsize prespace,
+						 gchar **out,
+						 gsize *outlen,
+						 gsize *outprespace);
+	void		(*complete)		(CamelMimeFilter *filter,
+						 const gchar *in,
+						 gsize len,
+						 gsize prespace,
+						 gchar **out,
+						 gsize *outlen,
+						 gsize *outprespace);
+	void		(*reset)		(CamelMimeFilter *filter);
 };
 
-CamelType	      camel_mime_filter_get_type	(void);
-CamelMimeFilter      *camel_mime_filter_new	(void);
-
-void camel_mime_filter_filter(CamelMimeFilter *filter,
-			      const gchar *in, gsize len, gsize prespace,
-			      gchar **out, gsize *outlen, gsize *outprespace);
-
-void camel_mime_filter_complete(CamelMimeFilter *filter,
-				const gchar *in, gsize len, gsize prespace,
-				gchar **out, gsize *outlen, gsize *outprespace);
-
-void camel_mime_filter_reset(CamelMimeFilter *filter);
+GType		camel_mime_filter_get_type	(void);
+CamelMimeFilter *
+		camel_mime_filter_new		(void);
+void		camel_mime_filter_filter	(CamelMimeFilter *filter,
+						 const gchar *in,
+						 gsize len,
+						 gsize prespace,
+						 gchar **out,
+						 gsize *outlen,
+						 gsize *outprespace);
+void		camel_mime_filter_complete	(CamelMimeFilter *filter,
+						 const gchar *in,
+						 gsize len,
+						 gsize prespace,
+						 gchar **out,
+						 gsize *outlen,
+						 gsize *outprespace);
+void		camel_mime_filter_reset		(CamelMimeFilter *filter);
 
 /* sets/returns number of bytes backed up on the input */
-void camel_mime_filter_backup(CamelMimeFilter *filter, const gchar *data, gsize length);
+void		camel_mime_filter_backup	(CamelMimeFilter *filter,
+						 const gchar *data,
+						 gsize length);
 
 /* ensure this much size available for filter output */
-void camel_mime_filter_set_size(CamelMimeFilter *filter, gsize size, gint keep);
+void		camel_mime_filter_set_size	(CamelMimeFilter *filter,
+						 gsize size,
+						 gint keep);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_FILTER_H */
+#endif /* CAMEL_MIME_FILTER_H */
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 578bb6a..b6fa193 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -80,14 +80,13 @@ static const gchar *header_names[] = {
 	"Bcc", "Resent-Bcc", "Date", "Message-ID", NULL
 };
 
-static GHashTable *header_name_table;
-
-static CamelMimePartClass *parent_class = NULL;
-
 static const gchar *recipient_names[] = {
 	"To", "Cc", "Bcc", "Resent-To", "Resent-Cc", "Resent-Bcc", NULL
 };
 
+static gpointer parent_class;
+static GHashTable *header_name_table;
+
 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);
@@ -95,50 +94,89 @@ 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);
 
-/* 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))
+static void
+mime_message_dispose (GObject *object)
+{
+	CamelMimeMessage *message = CAMEL_MIME_MESSAGE (object);
+
+	if (message->reply_to != NULL) {
+		g_object_unref (message->reply_to);
+		message->reply_to = NULL;
+	}
+
+	if (message->from != NULL) {
+		g_object_unref (message->from);
+		message->from = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
 
 static void
-camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class)
+mime_message_finalize (GObject *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;
+	g_hash_table_foreach (message->recipients, unref_recipient, NULL);
+	g_hash_table_destroy (message->recipients);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+mime_message_class_init (CamelMimeMessageClass *class)
+{
+	GObjectClass *object_class;
+	CamelDataWrapperClass *data_wrapper_class;
+	CamelMimePartClass *mime_part_class;
+	CamelMediumClass *medium_class;
+	gint ii;
 
-	camel_medium_class->add_header = add_header;
-	camel_medium_class->set_header = set_header;
-	camel_medium_class->remove_header = remove_header;
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = mime_message_dispose;
+	object_class->finalize = mime_message_finalize;
+
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->write_to_stream = write_to_stream;
+	data_wrapper_class->decode_to_stream = write_to_stream;
+
+	medium_class = CAMEL_MEDIUM_CLASS (class);
+	medium_class->add_header = add_header;
+	medium_class->set_header = set_header;
+	medium_class->remove_header = remove_header;
+
+	mime_part_class = CAMEL_MIME_PART_CLASS (class);
+	mime_part_class->construct_from_parser = 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));
 
-	camel_mime_part_class->construct_from_parser = construct_from_parser;
 }
 
 static void
-camel_mime_message_init (gpointer object, gpointer klass)
+mime_message_init (CamelMimeMessage *mime_message)
 {
-	CamelMimeMessage *mime_message = (CamelMimeMessage *)object;
-	gint i;
+	gint ii;
 
-	mime_message->recipients =  g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
-	for (i=0;recipient_names[i];i++) {
+	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,47 +190,28 @@ 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
+GType
 camel_mime_message_get_type (void)
 {
-	static CamelType camel_mime_message_type = CAMEL_INVALID_TYPE;
-
-	if (camel_mime_message_type == CAMEL_INVALID_TYPE)	{
-		camel_mime_message_type = camel_type_register (camel_mime_part_get_type(), "CamelMimeMessage",
-							       sizeof (CamelMimeMessage),
-							       sizeof (CamelMimeMessageClass),
-							       (CamelObjectClassInitFunc) camel_mime_message_class_init,
-							       NULL,
-							       (CamelObjectInitFunc) camel_mime_message_init,
-							       (CamelObjectFinalizeFunc) camel_mime_message_finalize);
-	}
-
-	return camel_mime_message_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MIME_PART,
+			"CamelMimeMessage",
+			sizeof (CamelMimeMessageClass),
+			(GClassInitFunc) mime_message_class_init,
+			sizeof (CamelMimeMessage),
+			(GInstanceInitFunc) mime_message_init,
+			0);
+
+	return type;
 }
 
 static void
 unref_recipient (gpointer key, gpointer value, gpointer user_data)
 {
-	camel_object_unref (value);
+	g_object_unref (value);
 }
 
 /**
@@ -205,10 +224,7 @@ unref_recipient (gpointer key, gpointer value, gpointer user_data)
 CamelMimeMessage *
 camel_mime_message_new (void)
 {
-	CamelMimeMessage *mime_message;
-	mime_message = CAMEL_MIME_MESSAGE (camel_object_new (CAMEL_MIME_MESSAGE_TYPE));
-
-	return mime_message;
+	return g_object_new (CAMEL_TYPE_MIME_MESSAGE, NULL);
 }
 
 /* **** Date: */
@@ -353,7 +369,7 @@ camel_mime_message_set_reply_to (CamelMimeMessage *msg, const CamelInternetAddre
 	g_assert(msg);
 
 	if (msg->reply_to) {
-		camel_object_unref ((CamelObject *)msg->reply_to);
+		g_object_unref (msg->reply_to);
 		msg->reply_to = NULL;
 	}
 
@@ -453,7 +469,7 @@ camel_mime_message_set_from (CamelMimeMessage *msg, const CamelInternetAddress *
 	g_assert(msg);
 
 	if (msg->from) {
-		camel_object_unref((CamelObject *)msg->from);
+		g_object_unref (msg->from);
 		msg->from = NULL;
 	}
 
@@ -517,7 +533,7 @@ camel_mime_message_set_recipients(CamelMimeMessage *mime_message, const gchar *t
 	}
 
 	/* note this does copy, and not append (cat) */
-	camel_address_copy ((CamelAddress *)addr, (const CamelAddress *)r);
+	camel_address_copy ((CamelAddress *)addr, (CamelAddress *)r);
 
 	/* and sync our headers */
 	text = camel_address_encode (CAMEL_ADDRESS (addr));
@@ -663,10 +679,10 @@ process_header (CamelMedium *medium, const gchar *name, const gchar *value)
 		addr = camel_internet_address_new();
 		unfolded = camel_header_unfold (value);
 		if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) {
-			camel_object_unref(addr);
+			g_object_unref (addr);
 		} else {
 			if (message->from)
-				camel_object_unref(message->from);
+				g_object_unref (message->from);
 			message->from = addr;
 		}
 		g_free (unfolded);
@@ -675,10 +691,10 @@ process_header (CamelMedium *medium, const gchar *name, const gchar *value)
 		addr = camel_internet_address_new();
 		unfolded = camel_header_unfold (value);
 		if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) {
-			camel_object_unref(addr);
+			g_object_unref (addr);
 		} else {
 			if (message->reply_to)
-				camel_object_unref(message->reply_to);
+				g_object_unref (message->reply_to);
 			message->reply_to = addr;
 		}
 		g_free (unfolded);
@@ -736,7 +752,7 @@ 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);
+	CAMEL_MEDIUM_CLASS (parent_class)->set_header (medium, name, value);
 }
 
 static void
@@ -744,16 +760,16 @@ 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);
+		CAMEL_MEDIUM_CLASS (parent_class)->set_header (medium, name, value);
 	else
-		parent_class->parent_class.add_header (medium, name, value);
+		CAMEL_MEDIUM_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);
+	CAMEL_MEDIUM_CLASS (parent_class)->remove_header (medium, name);
 }
 
 typedef gboolean (*CamelPartFunc)(CamelMimeMessage *, CamelMimePart *, gpointer data);
@@ -768,7 +784,7 @@ message_foreach_part_rec (CamelMimeMessage *msg, CamelMimePart *part, CamelPartF
 	if (callback (msg, part, data) == FALSE)
 		return FALSE;
 
-	containee = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+	containee = camel_medium_get_content (CAMEL_MEDIUM (part));
 
 	if (containee == NULL)
 		return go;
@@ -832,12 +848,12 @@ camel_mime_message_has_8bit_parts (CamelMimeMessage *msg)
 static CamelTransferEncoding
 find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBestencEncoding enctype, gchar **charsetp)
 {
-	CamelMimeFilterCharset *charenc = NULL;
+	CamelMimeFilter *charenc = NULL;
 	CamelTransferEncoding encoding;
-	CamelMimeFilterBestenc *bestenc;
+	CamelMimeFilter *bestenc;
 	guint flags, callerflags;
 	CamelDataWrapper *content;
-	CamelStreamFilter *filter;
+	CamelStream *filter;
 	const gchar *charsetin = NULL;
 	gchar *charset = NULL;
 	CamelStream *null;
@@ -850,7 +866,7 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
 
 	d(printf("starting to check part\n"));
 
-	content = camel_medium_get_content_object ((CamelMedium *)part);
+	content = camel_medium_get_content ((CamelMedium *)part);
 	if (content == NULL) {
 		/* charset might not be right here, but it'll get the right stuff
 		   if it is ever set */
@@ -874,30 +890,32 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
 
 	/* first a null stream, so any filtering is thrown away; we only want the sideeffects */
 	null = (CamelStream *)camel_stream_null_new ();
-	filter = camel_stream_filter_new_with_stream (null);
+	filter = camel_stream_filter_new (null);
 
 	/* if we're looking for the best charset, then we need to convert to UTF-8 */
 	if (istext && (required & CAMEL_BESTENC_GET_CHARSET) != 0
 	    && (charsetin = camel_content_type_param (content->mime_type, "charset"))) {
-		charenc = camel_mime_filter_charset_new_convert (charsetin, "UTF-8");
+		charenc = camel_mime_filter_charset_new (charsetin, "UTF-8");
 		if (charenc != NULL)
-			idc = camel_stream_filter_add (filter, (CamelMimeFilter *)charenc);
+			idc = camel_stream_filter_add (
+				CAMEL_STREAM_FILTER (filter), charenc);
 		charsetin = NULL;
 	}
 
 	bestenc = camel_mime_filter_bestenc_new (flags);
-	idb = camel_stream_filter_add (filter, (CamelMimeFilter *)bestenc);
+	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_stream_filter_remove (filter, idb);
+	camel_data_wrapper_decode_to_stream (content, filter);
+	camel_stream_filter_remove (CAMEL_STREAM_FILTER (filter), idb);
 	if (idc != -1) {
-		camel_stream_filter_remove (filter, idc);
-		camel_object_unref (charenc);
+		camel_stream_filter_remove (CAMEL_STREAM_FILTER (filter), idc);
+		g_object_unref (charenc);
 		charenc = NULL;
 	}
 
 	if (istext && (required & CAMEL_BESTENC_GET_CHARSET) != 0) {
-		charsetin = camel_mime_filter_bestenc_get_best_charset (bestenc);
+		charsetin = camel_mime_filter_bestenc_get_best_charset (
+			CAMEL_MIME_FILTER_BESTENC (bestenc));
 		d(printf("best charset = %s\n", charsetin ? charsetin : "(null)"));
 		charset = g_strdup (charsetin);
 
@@ -914,29 +932,34 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
 		   a charset conversion filter as well, and then re-add the bestenc to filter the
 		   result to find the best encoding to use as well */
 
-		charenc = camel_mime_filter_charset_new_convert (charsetin, charset);
+		charenc = camel_mime_filter_charset_new (charsetin, charset);
 		if (charenc != NULL) {
 			/* otherwise, try another pass, converting to the real charset */
 
-			camel_mime_filter_reset ((CamelMimeFilter *)bestenc);
-			camel_mime_filter_bestenc_set_flags (bestenc, CAMEL_BESTENC_GET_ENCODING |
-							     CAMEL_BESTENC_LF_IS_CRLF | callerflags);
+			camel_mime_filter_reset (bestenc);
+			camel_mime_filter_bestenc_set_flags (
+				CAMEL_MIME_FILTER_BESTENC (bestenc),
+				CAMEL_BESTENC_GET_ENCODING |
+				CAMEL_BESTENC_LF_IS_CRLF | callerflags);
 
-			camel_stream_filter_add (filter, (CamelMimeFilter *)charenc);
-			camel_stream_filter_add (filter, (CamelMimeFilter *)bestenc);
+			camel_stream_filter_add (
+				CAMEL_STREAM_FILTER (filter), charenc);
+			camel_stream_filter_add (
+				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);
+			g_object_unref (charenc);
 		}
 	}
 
-	encoding = camel_mime_filter_bestenc_get_best_encoding (bestenc, enctype);
+	encoding = camel_mime_filter_bestenc_get_best_encoding (
+		CAMEL_MIME_FILTER_BESTENC (bestenc), enctype);
 
-	camel_object_unref (filter);
-	camel_object_unref (bestenc);
-	camel_object_unref (null);
+	g_object_unref (filter);
+	g_object_unref (bestenc);
+	g_object_unref (null);
 
 	d(printf("done, best encoding = %d\n", encoding));
 
@@ -961,7 +984,7 @@ best_encoding (CamelMimeMessage *msg, CamelMimePart *part, gpointer datap)
 	CamelDataWrapper *wrapper;
 	gchar *charset;
 
-	wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+	wrapper = camel_medium_get_content (CAMEL_MEDIUM (part));
 	if (!wrapper)
 		return FALSE;
 
@@ -1052,7 +1075,7 @@ check_content_id (CamelMimeMessage *message, CamelMimePart *part, gpointer data)
 	found = content_id && !strcmp (content_id, check->content_id) ? TRUE : FALSE;
 	if (found) {
 		check->part = part;
-		camel_object_ref (part);
+		g_object_ref (part);
 	}
 
 	return !found;
@@ -1105,7 +1128,7 @@ static const gchar tz_days[][4] = {
 gchar *
 camel_mime_message_build_mbox_from (CamelMimeMessage *message)
 {
-	struct _camel_header_raw *header = ((CamelMimePart *)message)->headers;
+	struct _camel_header_raw *header;
 	GString *out = g_string_new("From ");
 	gchar *ret;
 	const gchar *tmp;
@@ -1113,6 +1136,8 @@ camel_mime_message_build_mbox_from (CamelMimeMessage *message)
 	gint offset;
 	struct tm tm;
 
+	header = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (message));
+
 	tmp = camel_header_raw_find (&header, "Sender", NULL);
 	if (tmp == NULL)
 		tmp = camel_header_raw_find (&header, "From", NULL);
@@ -1211,15 +1236,15 @@ cmm_dump_rec(CamelMimeMessage *msg, CamelMimePart *part, gint body, gint depth)
 	memset(s, ' ', depth);
 	s[depth] = 0;
 	/* yes this leaks, so what its only debug stuff */
-	printf("%sclass: %s\n", s, ((CamelObject *)part)->klass->name);
+	printf("%sclass: %s\n", s, G_OBJECT_TYPE_NAME (part));
 	printf("%smime-type: %s\n", s, camel_content_type_format(((CamelDataWrapper *)part)->mime_type));
 
-	containee = camel_medium_get_content_object((CamelMedium *)part);
+	containee = camel_medium_get_content ((CamelMedium *)part);
 
 	if (containee == NULL)
 		return;
 
-	printf("%scontent class: %s\n", s, ((CamelObject *)containee)->klass->name);
+	printf("%scontent class: %s\n", s, G_OBJECT_TYPE_NAME (containee));
 	printf("%scontent mime-type: %s\n", s, camel_content_type_format(((CamelDataWrapper *)containee)->mime_type));
 
 	/* using the object types is more accurate than using the mime/types */
diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h
index 6016f89..55b7a64 100644
--- a/camel/camel-mime-message.h
+++ b/camel/camel-mime-message.h
@@ -21,14 +21,37 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MIME_MESSAGE_H
-#define CAMEL_MIME_MESSAGE_H 1
+#define CAMEL_MIME_MESSAGE_H
 
 #include <camel/camel-mime-part.h>
 #include <camel/camel-mime-utils.h>
 #include <camel/camel-internet-address.h>
 #include <camel/camel-mime-filter-bestenc.h>
 
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_MESSAGE \
+	(camel_mime_message_get_type ())
+#define CAMEL_MIME_MESSAGE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_MESSAGE, CamelMimeMessage))
+#define CAMEL_MIME_MESSAGE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_MESSAGE, CamelMimeMessageClass))
+#define CAMEL_IS_MIME_MESSAGE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_MESSAGE))
+#define CAMEL_IS_MIME_MESSAGE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_MESSAGE))
+#define CAMEL_MIME_MESSAGE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_MESSAGE, CamelMimeMessageClass))
+
 #define CAMEL_RECIPIENT_TYPE_TO "To"
 #define CAMEL_RECIPIENT_TYPE_CC "Cc"
 #define CAMEL_RECIPIENT_TYPE_BCC "Bcc"
@@ -37,19 +60,16 @@
 #define CAMEL_RECIPIENT_TYPE_RESENT_CC "Resent-Cc"
 #define CAMEL_RECIPIENT_TYPE_RESENT_BCC "Resent-Bcc"
 
-#define CAMEL_MIME_MESSAGE_TYPE     (camel_mime_message_get_type ())
-#define CAMEL_MIME_MESSAGE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MIME_MESSAGE_TYPE, CamelMimeMessage))
-#define CAMEL_MIME_MESSAGE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MIME_MESSAGE_TYPE, CamelMimeMessageClass))
-#define CAMEL_IS_MIME_MESSAGE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MIME_MESSAGE_TYPE))
-
 /* specify local time */
 #define CAMEL_MESSAGE_DATE_CURRENT (~0)
 
 G_BEGIN_DECLS
 
-struct _CamelMimeMessage
-{
-	CamelMimePart parent_object;
+typedef struct _CamelMimeMessage CamelMimeMessage;
+typedef struct _CamelMimeMessageClass CamelMimeMessageClass;
+
+struct _CamelMimeMessage {
+	CamelMimePart parent;
 
 	/* header fields */
 	time_t date;
@@ -69,15 +89,11 @@ struct _CamelMimeMessage
 	GHashTable *recipients;	/* hash table of CamelInternetAddress's */
 };
 
-typedef struct {
+struct _CamelMimeMessageClass {
 	CamelMimePartClass parent_class;
+};
 
-	/* Virtual methods */
-
-} CamelMimeMessageClass;
-
-/* Standard Camel function */
-CamelType                   camel_mime_message_get_type           (void);
+GType                   camel_mime_message_get_type           (void);
 
 /* public methods */
 CamelMimeMessage           *camel_mime_message_new                (void);
diff --git a/camel/camel-mime-parser.c b/camel/camel-mime-parser.c
index e851ee7..d528234 100644
--- a/camel/camel-mime-parser.c
+++ b/camel/camel-mime-parser.c
@@ -33,8 +33,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
-
 #include <libedataserver/e-memory.h>
 
 #include "camel-mime-filter.h"
@@ -163,8 +161,8 @@ static void folder_push_part(struct _header_scan_state *s, struct _header_scan_s
 static void header_append_mempool(struct _header_scan_state *s, struct _header_scan_stack *h, gchar *header, gint offset);
 #endif
 
-static void camel_mime_parser_class_init (CamelMimeParserClass *klass);
-static void camel_mime_parser_init       (CamelMimeParser *obj);
+static void mime_parser_class_init (CamelMimeParserClass *class);
+static void mime_parser_init       (CamelMimeParser *obj);
 
 #if d(!)0
 static gchar *states[] = {
@@ -188,47 +186,54 @@ static gchar *states[] = {
 };
 #endif
 
-static CamelObjectClass *camel_mime_parser_parent;
+static gpointer parent_class;
 
 static void
-camel_mime_parser_class_init (CamelMimeParserClass *klass)
+mime_parser_finalize (GObject *object)
 {
-	camel_mime_parser_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
+	struct _header_scan_state *s = _PRIVATE (object);
+
+#ifdef PURIFY
+	purify_watch_remove_all();
+#endif
+
+	folder_scan_close(s);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_mime_parser_init (CamelMimeParser *obj)
+mime_parser_class_init (CamelMimeParserClass *class)
 {
-	struct _header_scan_state *s;
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
 
-	s = folder_scan_init();
-	_PRIVATE(obj) = s;
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = mime_parser_finalize;
 }
 
 static void
-camel_mime_parser_finalise(CamelObject *o)
+mime_parser_init (CamelMimeParser *parser)
 {
-	struct _header_scan_state *s = _PRIVATE(o);
-#ifdef PURIFY
-	purify_watch_remove_all();
-#endif
-	folder_scan_close(s);
+	parser->priv = folder_scan_init();
 }
 
-CamelType
+GType
 camel_mime_parser_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (), "CamelMimeParser",
-					    sizeof (CamelMimeParser),
-					    sizeof (CamelMimeParserClass),
-					    (CamelObjectClassInitFunc) camel_mime_parser_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_parser_init,
-					    (CamelObjectFinalizeFunc) camel_mime_parser_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelMimeParser",
+			sizeof (CamelMimeParserClass),
+			(GClassInitFunc) mime_parser_class_init,
+			sizeof (CamelMimeParser),
+			(GInstanceInitFunc) mime_parser_init,
+			0);
 
 	return type;
 }
@@ -243,8 +248,7 @@ camel_mime_parser_get_type (void)
 CamelMimeParser *
 camel_mime_parser_new (void)
 {
-	CamelMimeParser *new = CAMEL_MIME_PARSER ( camel_object_new (camel_mime_parser_get_type ()));
-	return new;
+	return g_object_new (CAMEL_TYPE_MIME_PARSER, NULL);
 }
 
 /**
@@ -275,7 +279,7 @@ camel_mime_parser_filter_add(CamelMimeParser *m, CamelMimeFilter *mf)
 	if (s->filterid == -1)
 		s->filterid++;
 	new->next = NULL;
-	camel_object_ref((CamelObject *)mf);
+	g_object_ref (mf);
 
 	/* yes, this is correct, since 'next' is the first element of the struct */
 	f = (struct _header_scan_filter *)&s->filters;
@@ -303,7 +307,7 @@ camel_mime_parser_filter_remove(CamelMimeParser *m, gint id)
 	while (f && f->next) {
 		old = f->next;
 		if (old->id == id) {
-			camel_object_unref((CamelObject *)old->filter);
+			g_object_unref (old->filter);
 			f->next = old->next;
 			g_free(old);
 			/* there should only be a single matching id, but
@@ -1413,7 +1417,7 @@ folder_scan_close(struct _header_scan_state *s)
 	if (s->fd != -1)
 		close(s->fd);
 	if (s->stream) {
-		camel_object_unref((CamelObject *)s->stream);
+		g_object_unref (s->stream);
 	}
 	g_free(s);
 }
@@ -1484,7 +1488,7 @@ folder_scan_reset(struct _header_scan_state *s)
 		s->fd = -1;
 	}
 	if (s->stream) {
-		camel_object_unref((CamelObject *)s->stream);
+		g_object_unref (s->stream);
 		s->stream = NULL;
 	}
 	s->ioerrno = 0;
@@ -1505,7 +1509,7 @@ folder_scan_init_with_stream(struct _header_scan_state *s, CamelStream *stream)
 {
 	folder_scan_reset(s);
 	s->stream = stream;
-	camel_object_ref((CamelObject *)stream);
+	g_object_ref (stream);
 
 	return 0;
 }
@@ -1664,7 +1668,7 @@ tail_recurse:
 				while (f) {
 					camel_mime_filter_filter(f->filter, *databuffer, *datalength, presize,
 								 databuffer, datalength, &presize);
-					d(printf("Filtered content (%s): '", ((CamelObject *)f->filter)->klass->name));
+					d(printf("Filtered content (%s): '", ((CamelObject *)f->filter)->class->name));
 					d(fwrite(*databuffer, sizeof(gchar), *datalength, stdout));
 					d(printf("'\n"));
 					f = f->next;
diff --git a/camel/camel-mime-parser.h b/camel/camel-mime-parser.h
index c078712..232b407 100644
--- a/camel/camel-mime-parser.h
+++ b/camel/camel-mime-parser.h
@@ -19,8 +19,12 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_PARSER_H
-#define _CAMEL_MIME_PARSER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_PARSER_H
+#define CAMEL_MIME_PARSER_H
 
 #include <camel/camel-object.h>
 
@@ -28,13 +32,30 @@
 #include <camel/camel-mime-filter.h>
 #include <camel/camel-stream.h>
 
-#define CAMEL_MIME_PARSER(obj)         CAMEL_CHECK_CAST (obj, camel_mime_parser_get_type (), CamelMimeParser)
-#define CAMEL_MIME_PARSER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_parser_get_type (), CamelMimeParserClass)
-#define CAMEL_IS_MIME_PARSER(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_parser_get_type ())
+/* Stardard GObject macros */
+#define CAMEL_TYPE_MIME_PARSER \
+	(camel_mime_parser_get_type ())
+#define CAMEL_MIME_PARSER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_PARSER, CamelMimeParser))
+#define CAMEL_MIME_PARSER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_PARSER, CamelMimeParserClass))
+#define CAMEL_IS_MIME_PARSER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_PARSER))
+#define CAMEL_IS_MIME_PARSER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_PARSER))
+#define CAMEL_MIME_PARSER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_PARSER, CamelMimeParserClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMimeParser CamelMimeParser;
 typedef struct _CamelMimeParserClass CamelMimeParserClass;
+typedef struct _CamelMimeParserPrivate CamelMimeParserPrivate;
 
 /* NOTE: if you add more states, you may need to bump the
    start of the END tags to 16 or 32, etc - so they are
@@ -63,8 +84,7 @@ typedef enum _camel_mime_parser_state_t {
 
 struct _CamelMimeParser {
 	CamelObject parent;
-
-	struct _CamelMimeParserPrivate *priv;
+	CamelMimeParserPrivate *priv;
 };
 
 struct _CamelMimeParserClass {
@@ -75,7 +95,7 @@ struct _CamelMimeParserClass {
 	void (*content) (CamelMimeParser *parser);
 };
 
-CamelType camel_mime_parser_get_type (void);
+GType camel_mime_parser_get_type (void);
 CamelMimeParser *camel_mime_parser_new (void);
 
 /* quick-fix for parser not erroring, we can find out if it had an error afterwards */
@@ -139,4 +159,4 @@ off_t camel_mime_parser_tell_start_boundary(CamelMimeParser *parser);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_PARSER_H */
+#endif /* CAMEL_MIME_PARSER_H */
diff --git a/camel/camel-mime-part-utils.c b/camel/camel-mime-part-utils.c
index ff27bf1..e79c978 100644
--- a/camel/camel-mime-part-utils.c
+++ b/camel/camel-mime-part-utils.c
@@ -75,7 +75,7 @@ simple_data_wrapper_construct_from_parser (CamelDataWrapper *dw, CamelMimeParser
 
 	mem = camel_stream_mem_new_with_byte_array (buffer);
 	camel_data_wrapper_construct_from_stream (dw, mem);
-	camel_object_unref (mem);
+	g_object_unref (mem);
 }
 
 /* This replaces the data wrapper repository ... and/or could be replaced by it? */
@@ -132,8 +132,8 @@ camel_mime_part_construct_content_from_parser (CamelMimePart *dw, CamelMimeParse
 
 		/* would you believe you have to set this BEFORE you set the content object???  oh my god !!!! */
 		camel_data_wrapper_set_mime_type_field (content, camel_mime_part_get_content_type (dw));
-		camel_medium_set_content_object ((CamelMedium *)dw, content);
-		camel_object_unref (content);
+		camel_medium_set_content ((CamelMedium *)dw, content);
+		g_object_unref (content);
 	}
 
 	g_free (encoding);
@@ -145,10 +145,10 @@ camel_mime_message_build_preview (CamelMimePart *msg, CamelMessageInfo *info)
 	CamelDataWrapper *dw;
 	gboolean got_plain = FALSE;
 
-	dw = camel_medium_get_content_object((CamelMedium *)msg);
+	dw = camel_medium_get_content ((CamelMedium *)msg);
 	if (camel_content_type_is (dw->mime_type, "multipart", "*")) {
 		gint i, nparts;
-		CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)msg);
+		CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content ((CamelMedium *)msg);
 
 		if (!CAMEL_IS_MULTIPART(mp))
 			g_assert (0);
@@ -204,9 +204,9 @@ camel_mime_message_build_preview (CamelMimePart *msg, CamelMessageInfo *info)
 			((CamelMessageInfoBase *) info)->preview = camel_utf8_make_valid(str->str);
 			g_string_free(str, TRUE);
 
-			camel_object_unref (bstream);
+			g_object_unref (bstream);
 		}
-		camel_object_unref (mstream);
+		g_object_unref (mstream);
 		return TRUE;
 	}
 
diff --git a/camel/camel-mime-part-utils.h b/camel/camel-mime-part-utils.h
index 45a5a6e..6691c9e 100644
--- a/camel/camel-mime-part-utils.h
+++ b/camel/camel-mime-part-utils.h
@@ -23,8 +23,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MIME_PART_UTILS_H
-#define CAMEL_MIME_PART_UTILS_H 1
+#define CAMEL_MIME_PART_UTILS_H
 
 #include <camel/camel-mime-part.h>
 #include <camel/camel-folder-summary.h>
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index 51eba22..a1389c2 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -49,6 +49,34 @@
 
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
 
+#define CAMEL_MIME_PART_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MIME_PART, CamelMimePartPrivate))
+
+struct _CamelMimePartPrivate {
+
+	struct _camel_header_raw *headers;  /* mime headers */
+
+	/* TODO: these should be in a camelcontentinfo */
+	gchar *description;
+	CamelContentDisposition *disposition;
+	gchar *content_id;
+	gchar *content_md5;
+	gchar *content_location;
+	GList *content_languages;
+	CamelTransferEncoding encoding;
+};
+
+enum {
+	PROP_0,
+	PROP_CONTENT_ID,
+	PROP_CONTENT_LOCATION,
+	PROP_CONTENT_MD5,
+	PROP_DESCRIPTION,
+	PROP_DISPOSITION,
+	PROP_FILENAME
+};
+
 typedef enum {
 	HEADER_UNKNOWN,
 	HEADER_DESCRIPTION,
@@ -64,12 +92,7 @@ typedef enum {
 static GHashTable *header_name_table;
 static GHashTable *header_formatted_table;
 
-static CamelMediumClass *parent_class=NULL;
-
-/* Returns the class for a CamelMimePart */
-#define CMP_CLASS(so) CAMEL_MIME_PART_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))
+static gpointer parent_class;
 
 /* from CamelDataWrapper */
 static gssize         write_to_stream                 (CamelDataWrapper *dw, CamelStream *stream);
@@ -83,7 +106,7 @@ static const void     *get_header                      (CamelMedium *medium, con
 static GArray         *get_headers                     (CamelMedium *medium);
 static void            free_headers                    (CamelMedium *medium, GArray *headers);
 
-static void            set_content_object              (CamelMedium *medium, CamelDataWrapper *content);
+static void            set_content                     (CamelMedium *medium, CamelDataWrapper *content);
 
 /* from camel mime parser */
 static gint             construct_from_parser           (CamelMimePart *mime_part, CamelMimeParser *mp);
@@ -159,77 +182,208 @@ init_header_name_table(void)
 }
 
 static void
-camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class)
+mime_part_set_property (GObject *object,
+                        guint property_id,
+                        const GValue *value,
+                        GParamSpec *pspec)
 {
-	CamelMediumClass *camel_medium_class = CAMEL_MEDIUM_CLASS (camel_mime_part_class);
-	CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (camel_mime_part_class);
-
-	parent_class = CAMEL_MEDIUM_CLASS (camel_type_get_global_classfuncs (camel_medium_get_type ()));
-	init_header_name_table();
+	switch (property_id) {
+		case PROP_CONTENT_ID:
+			camel_mime_part_set_content_id (
+				CAMEL_MIME_PART (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_CONTENT_MD5:
+			camel_mime_part_set_content_md5 (
+				CAMEL_MIME_PART (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_CONTENT_LOCATION:
+			camel_mime_part_set_content_location (
+				CAMEL_MIME_PART (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_DESCRIPTION:
+			camel_mime_part_set_description (
+				CAMEL_MIME_PART (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_DISPOSITION:
+			camel_mime_part_set_disposition (
+				CAMEL_MIME_PART (object),
+				g_value_get_string (value));
+			return;
+	}
 
-	camel_mime_part_class->construct_from_parser = construct_from_parser;
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
 
-	/* virtual method overload */
-	camel_medium_class->add_header                = add_header;
-	camel_medium_class->set_header                = set_header;
-	camel_medium_class->get_header                = get_header;
-	camel_medium_class->remove_header             = remove_header;
-	camel_medium_class->get_headers               = get_headers;
-	camel_medium_class->free_headers              = free_headers;
-	camel_medium_class->set_content_object        = set_content_object;
+static void
+mime_part_get_property (GObject *object,
+                        guint property_id,
+                        GValue *value,
+                        GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_CONTENT_ID:
+			g_value_set_string (
+				value, camel_mime_part_get_content_id (
+				CAMEL_MIME_PART (object)));
+			return;
+
+		case PROP_CONTENT_MD5:
+			g_value_set_string (
+				value, camel_mime_part_get_content_md5 (
+				CAMEL_MIME_PART (object)));
+			return;
+
+		case PROP_CONTENT_LOCATION:
+			g_value_set_string (
+				value, camel_mime_part_get_content_location (
+				CAMEL_MIME_PART (object)));
+			return;
+
+		case PROP_DESCRIPTION:
+			g_value_set_string (
+				value, camel_mime_part_get_description (
+				CAMEL_MIME_PART (object)));
+			return;
+
+		case PROP_DISPOSITION:
+			g_value_set_string (
+				value, camel_mime_part_get_disposition (
+				CAMEL_MIME_PART (object)));
+			return;
+	}
 
-	camel_data_wrapper_class->write_to_stream     = write_to_stream;
-	camel_data_wrapper_class->construct_from_stream= construct_from_stream;
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
 static void
-camel_mime_part_init (gpointer object, gpointer klass)
+mime_part_finalize (GObject *object)
 {
 	CamelMimePart *mime_part = CAMEL_MIME_PART (object);
 
-	if (((CamelDataWrapper *) mime_part)->mime_type)
-		camel_content_type_unref (((CamelDataWrapper *) mime_part)->mime_type);
-	((CamelDataWrapper *) mime_part)->mime_type = camel_content_type_new ("text", "plain");
-
-	mime_part->description          = NULL;
-	mime_part->disposition          = NULL;
-	mime_part->content_id           = NULL;
-	mime_part->content_MD5          = NULL;
-	mime_part->content_location     = NULL;
-	mime_part->content_languages    = NULL;
-	mime_part->encoding = CAMEL_TRANSFER_ENCODING_DEFAULT;
+	g_free (mime_part->priv->description);
+	g_free (mime_part->priv->content_id);
+	g_free (mime_part->priv->content_md5);
+	g_free (mime_part->priv->content_location);
+	camel_string_list_free (mime_part->priv->content_languages);
+	camel_content_disposition_unref (mime_part->priv->disposition);
+
+	camel_header_raw_clear (&mime_part->priv->headers);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_mime_part_finalize (CamelObject *object)
+mime_part_class_init (CamelMimePartClass *class)
 {
-	CamelMimePart *mime_part = CAMEL_MIME_PART (object);
+	GObjectClass *object_class;
+	CamelMediumClass *medium_class;
+	CamelDataWrapperClass *data_wrapper_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMimePartPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = mime_part_set_property;
+	object_class->get_property = mime_part_get_property;
+	object_class->finalize = mime_part_finalize;
+
+	medium_class = CAMEL_MEDIUM_CLASS (class);
+	medium_class->add_header = add_header;
+	medium_class->set_header = set_header;
+	medium_class->get_header = get_header;
+	medium_class->remove_header = remove_header;
+	medium_class->get_headers = get_headers;
+	medium_class->free_headers = free_headers;
+	medium_class->set_content = set_content;
+
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->write_to_stream = write_to_stream;
+	data_wrapper_class->construct_from_stream = construct_from_stream;
+
+	class->construct_from_parser = construct_from_parser;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_CONTENT_ID,
+		g_param_spec_string (
+			"content-id",
+			"Content ID",
+			NULL,
+			NULL,
+			G_PARAM_READWRITE));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_CONTENT_MD5,
+		g_param_spec_string (
+			"content-md5",
+			"Content MD5",
+			NULL,
+			NULL,
+			G_PARAM_READWRITE));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_DESCRIPTION,
+		g_param_spec_string (
+			"description",
+			"Description",
+			NULL,
+			NULL,
+			G_PARAM_READWRITE));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_DISPOSITION,
+		g_param_spec_string (
+			"disposition",
+			"Disposition",
+			NULL,
+			NULL,
+			G_PARAM_READWRITE));
+
+	init_header_name_table ();
+}
+
+static void
+mime_part_init (CamelMimePart *mime_part)
+{
+	CamelDataWrapper *data_wrapper;
+
+	mime_part->priv = CAMEL_MIME_PART_GET_PRIVATE (mime_part);
+	mime_part->priv->encoding = CAMEL_TRANSFER_ENCODING_DEFAULT;
+
+	data_wrapper = CAMEL_DATA_WRAPPER (mime_part);
 
-	g_free (mime_part->description);
-	g_free (mime_part->content_id);
-	g_free (mime_part->content_MD5);
-	g_free (mime_part->content_location);
-	camel_string_list_free (mime_part->content_languages);
-	camel_content_disposition_unref(mime_part->disposition);
+	if (data_wrapper->mime_type != NULL)
+		camel_content_type_unref (data_wrapper->mime_type);
 
-	camel_header_raw_clear(&mime_part->headers);
+	data_wrapper->mime_type = camel_content_type_new ("text", "plain");
 }
 
-CamelType
+GType
 camel_mime_part_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE)	{
-		type = camel_type_register (CAMEL_MEDIUM_TYPE,
-					    "CamelMimePart",
-					    sizeof (CamelMimePart),
-					    sizeof (CamelMimePartClass),
-					    (CamelObjectClassInitFunc) camel_mime_part_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_part_init,
-					    (CamelObjectFinalizeFunc) camel_mime_part_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MEDIUM,
+			"CamelMimePart",
+			sizeof (CamelMimePartClass),
+			(GClassInitFunc) mime_part_class_init,
+			sizeof (CamelMimePart),
+			(GInstanceInitFunc) mime_part_init,
+			0);
 
 	return type;
 }
@@ -251,33 +405,33 @@ process_header(CamelMedium *medium, const gchar *name, const gchar *value)
 	header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, name);
 	switch (header_type) {
 	case HEADER_DESCRIPTION: /* raw header->utf8 conversion */
-		g_free (mime_part->description);
+		g_free (mime_part->priv->description);
 		if (((CamelDataWrapper *) mime_part)->mime_type) {
 			charset = camel_content_type_param (((CamelDataWrapper *) mime_part)->mime_type, "charset");
 			charset = camel_iconv_charset_name (charset);
 		} else
 			charset = NULL;
-		mime_part->description = g_strstrip (camel_header_decode_string (value, charset));
+		mime_part->priv->description = g_strstrip (camel_header_decode_string (value, charset));
 		break;
 	case HEADER_DISPOSITION:
 		set_disposition (mime_part, value);
 		break;
 	case HEADER_CONTENT_ID:
-		g_free (mime_part->content_id);
-		mime_part->content_id = camel_header_contentid_decode (value);
+		g_free (mime_part->priv->content_id);
+		mime_part->priv->content_id = camel_header_contentid_decode (value);
 		break;
 	case HEADER_ENCODING:
 		text = camel_header_token_decode (value);
-		mime_part->encoding = camel_transfer_encoding_from_string (text);
+		mime_part->priv->encoding = camel_transfer_encoding_from_string (text);
 		g_free (text);
 		break;
 	case HEADER_CONTENT_MD5:
-		g_free (mime_part->content_MD5);
-		mime_part->content_MD5 = g_strdup (value);
+		g_free (mime_part->priv->content_md5);
+		mime_part->priv->content_md5 = g_strdup (value);
 		break;
 	case HEADER_CONTENT_LOCATION:
-		g_free (mime_part->content_location);
-		mime_part->content_location = camel_header_location_decode (value);
+		g_free (mime_part->priv->content_location);
+		mime_part->priv->content_location = camel_header_location_decode (value);
 		break;
 	case HEADER_CONTENT_TYPE:
 		if (((CamelDataWrapper *) mime_part)->mime_type)
@@ -296,7 +450,7 @@ set_header (CamelMedium *medium, const gchar *name, gconstpointer value)
 	CamelMimePart *part = CAMEL_MIME_PART (medium);
 
 	process_header(medium, name, value);
-	camel_header_raw_replace(&part->headers, name, value, -1);
+	camel_header_raw_replace(&part->priv->headers, name, value, -1);
 }
 
 static void
@@ -310,9 +464,9 @@ add_header (CamelMedium *medium, const gchar *name, gconstpointer value)
 
 	/* If it was one of the headers we handled, it must be unique, set it instead of add */
 	if (process_header(medium, name, value))
-		camel_header_raw_replace(&part->headers, name, value, -1);
+		camel_header_raw_replace(&part->priv->headers, name, value, -1);
 	else
-		camel_header_raw_append(&part->headers, name, value, -1);
+		camel_header_raw_append(&part->priv->headers, name, value, -1);
 }
 
 static void
@@ -321,7 +475,7 @@ remove_header (CamelMedium *medium, const gchar *name)
 	CamelMimePart *part = (CamelMimePart *)medium;
 
 	process_header(medium, name, NULL);
-	camel_header_raw_remove(&part->headers, name);
+	camel_header_raw_remove(&part->priv->headers, name);
 }
 
 static gconstpointer
@@ -329,7 +483,7 @@ get_header (CamelMedium *medium, const gchar *name)
 {
 	CamelMimePart *part = (CamelMimePart *)medium;
 
-	return camel_header_raw_find(&part->headers, name, NULL);
+	return camel_header_raw_find(&part->priv->headers, name, NULL);
 }
 
 static GArray *
@@ -341,7 +495,7 @@ get_headers (CamelMedium *medium)
 	struct _camel_header_raw *h;
 
 	headers = g_array_new (FALSE, FALSE, sizeof (CamelMediumHeader));
-	for (h = part->headers; h; h = h->next) {
+	for (h = part->priv->headers; h; h = h->next) {
 		header.name = h->name;
 		header.value = h->value;
 		g_array_append_val (headers, header);
@@ -366,13 +520,22 @@ free_headers (CamelMedium *medium, GArray *gheaders)
  * Set a description on the MIME part.
  **/
 void
-camel_mime_part_set_description (CamelMimePart *mime_part, const gchar *description)
+camel_mime_part_set_description (CamelMimePart *mime_part,
+                                 const gchar *description)
 {
-	gchar *text = camel_header_encode_string ((const guchar *) description);
+	CamelMedium *medium;
+	gchar *text;
+
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+	g_return_if_fail (description != NULL);
+
+	medium = CAMEL_MEDIUM (mime_part);
 
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part),
-				 "Content-Description", text);
+	text = camel_header_encode_string ((guchar *) description);
+	camel_medium_set_header (medium, "Content-Description", text);
 	g_free (text);
+
+	g_object_notify (G_OBJECT (mime_part), "description");
 }
 
 /**
@@ -386,7 +549,9 @@ camel_mime_part_set_description (CamelMimePart *mime_part, const gchar *descript
 const gchar *
 camel_mime_part_get_description (CamelMimePart *mime_part)
 {
-	return mime_part->description;
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
+	return mime_part->priv->description;
 }
 
 /* **** Content-Disposition */
@@ -394,11 +559,12 @@ camel_mime_part_get_description (CamelMimePart *mime_part)
 static void
 set_disposition (CamelMimePart *mime_part, const gchar *disposition)
 {
-	camel_content_disposition_unref(mime_part->disposition);
+	camel_content_disposition_unref(mime_part->priv->disposition);
 	if (disposition)
-		mime_part->disposition = camel_content_disposition_decode(disposition);
+		mime_part->priv->disposition =
+			camel_content_disposition_decode (disposition);
 	else
-		mime_part->disposition = NULL;
+		mime_part->priv->disposition = NULL;
 }
 
 /**
@@ -409,24 +575,30 @@ set_disposition (CamelMimePart *mime_part, const gchar *disposition)
  * Set a disposition on the MIME part.
  **/
 void
-camel_mime_part_set_disposition (CamelMimePart *mime_part, const gchar *disposition)
+camel_mime_part_set_disposition (CamelMimePart *mime_part,
+                                 const gchar *disposition)
 {
+	CamelMedium *medium;
 	gchar *text;
 
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+	medium = CAMEL_MEDIUM (mime_part);
+
 	/* we poke in a new disposition (so we dont lose 'filename', etc) */
-	if (mime_part->disposition == NULL) {
+	if (mime_part->priv->disposition == NULL)
 		set_disposition(mime_part, disposition);
+
+	if (mime_part->priv->disposition != NULL) {
+		g_free (mime_part->priv->disposition->disposition);
+		mime_part->priv->disposition->disposition = g_strdup (disposition);
 	}
-	if (mime_part->disposition != NULL) {
-		g_free(mime_part->disposition->disposition);
-		mime_part->disposition->disposition = g_strdup(disposition);
-	}
-	text = camel_content_disposition_format(mime_part->disposition);
 
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part),
-				 "Content-Disposition", text);
+	text = camel_content_disposition_format (mime_part->priv->disposition);
+	camel_medium_set_header (medium, "Content-Disposition", text);
+	g_free (text);
 
-	g_free(text);
+	g_object_notify (G_OBJECT (mime_part), "disposition");
 }
 
 /**
@@ -440,8 +612,10 @@ camel_mime_part_set_disposition (CamelMimePart *mime_part, const gchar *disposit
 const gchar *
 camel_mime_part_get_disposition (CamelMimePart *mime_part)
 {
-	if (mime_part->disposition)
-		return mime_part->disposition->disposition;
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
+	if (mime_part->priv->disposition)
+		return mime_part->priv->disposition->disposition;
 	else
 		return NULL;
 }
@@ -458,17 +632,21 @@ camel_mime_part_get_disposition (CamelMimePart *mime_part)
 void
 camel_mime_part_set_filename (CamelMimePart *mime_part, const gchar *filename)
 {
-	gchar *str;
 	CamelDataWrapper *dw;
+	CamelMedium *medium;
+	gchar *str;
 
-	if (mime_part->disposition == NULL)
-		mime_part->disposition = camel_content_disposition_decode("attachment");
+	medium = CAMEL_MEDIUM (mime_part);
 
-	camel_header_set_param(&mime_part->disposition->params, "filename", filename);
-	str = camel_content_disposition_format(mime_part->disposition);
+	if (mime_part->priv->disposition == NULL)
+		mime_part->priv->disposition =
+			camel_content_disposition_decode("attachment");
 
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part),
-				 "Content-Disposition", str);
+	camel_header_set_param (
+		&mime_part->priv->disposition->params, "filename", filename);
+	str = camel_content_disposition_format(mime_part->priv->disposition);
+
+	camel_medium_set_header (medium, "Content-Disposition", str);
 	g_free(str);
 
 	dw = (CamelDataWrapper *) mime_part;
@@ -476,7 +654,7 @@ camel_mime_part_set_filename (CamelMimePart *mime_part, const gchar *filename)
 		dw->mime_type = camel_content_type_new ("application", "octet-stream");
 	camel_content_type_set_param (dw->mime_type, "name", filename);
 	str = camel_content_type_format (dw->mime_type);
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part), "Content-Type", str);
+	camel_medium_set_header (medium, "Content-Type", str);
 	g_free (str);
 }
 
@@ -491,8 +669,9 @@ camel_mime_part_set_filename (CamelMimePart *mime_part, const gchar *filename)
 const gchar *
 camel_mime_part_get_filename (CamelMimePart *mime_part)
 {
-	if (mime_part->disposition) {
-		const gchar *name = camel_header_param (mime_part->disposition->params, "filename");
+	if (mime_part->priv->disposition) {
+		const gchar *name = camel_header_param (
+			mime_part->priv->disposition->params, "filename");
 		if (name)
 			return name;
 	}
@@ -510,19 +689,28 @@ camel_mime_part_get_filename (CamelMimePart *mime_part)
  * Set the content-id field on a MIME part.
  **/
 void
-camel_mime_part_set_content_id (CamelMimePart *mime_part, const gchar *contentid)
+camel_mime_part_set_content_id (CamelMimePart *mime_part,
+                                const gchar *contentid)
 {
+	CamelMedium *medium;
 	gchar *cid, *id;
 
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+	medium = CAMEL_MEDIUM (mime_part);
+
 	if (contentid)
 		id = g_strstrip (g_strdup (contentid));
 	else
 		id = camel_header_msgid_generate ();
 
 	cid = g_strdup_printf ("<%s>", id);
-	g_free (id);
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part), "Content-ID", cid);
+	camel_medium_set_header (medium, "Content-ID", cid);
 	g_free (cid);
+
+	g_free (id);
+
+	g_object_notify (G_OBJECT (mime_part), "content-id");
 }
 
 /**
@@ -536,26 +724,35 @@ camel_mime_part_set_content_id (CamelMimePart *mime_part, const gchar *contentid
 const gchar *
 camel_mime_part_get_content_id (CamelMimePart *mime_part)
 {
-	return mime_part->content_id;
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
+	return mime_part->priv->content_id;
 }
 
 /* **** Content-MD5: */
 
 /**
- * camel_mime_part_set_content_MD5:
+ * camel_mime_part_set_content_md5:
  * @mime_part: a #CamelMimePart object
  * @md5sum: the md5sum of the MIME part
  *
  * Set the content-md5 field of the MIME part.
  **/
 void
-camel_mime_part_set_content_MD5 (CamelMimePart *mime_part, const gchar *md5)
+camel_mime_part_set_content_md5 (CamelMimePart *mime_part,
+                                 const gchar *content_md5)
 {
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part), "Content-MD5", md5);
+	CamelMedium *medium;
+
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+	medium = CAMEL_MEDIUM (mime_part);
+
+	camel_medium_set_header (medium, "Content-MD5", content_md5);
 }
 
 /**
- * camel_mime_part_get_content_MD5:
+ * camel_mime_part_get_content_md5:
  * @mime_part: a #CamelMimePart object
  *
  * Get the content-md5 field of the MIME part.
@@ -563,9 +760,11 @@ camel_mime_part_set_content_MD5 (CamelMimePart *mime_part, const gchar *md5)
  * Returns: the content-md5 field of the MIME part
  **/
 const gchar *
-camel_mime_part_get_content_MD5 (CamelMimePart *mime_part)
+camel_mime_part_get_content_md5 (CamelMimePart *mime_part)
 {
-	return mime_part->content_MD5;
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
+	return mime_part->priv->content_md5;
 }
 
 /* **** Content-Location: */
@@ -578,10 +777,19 @@ camel_mime_part_get_content_MD5 (CamelMimePart *mime_part)
  * Set the content-location field of the MIME part.
  **/
 void
-camel_mime_part_set_content_location (CamelMimePart *mime_part, const gchar *location)
+camel_mime_part_set_content_location (CamelMimePart *mime_part,
+                                      const gchar *location)
 {
+	CamelMedium *medium;
+
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+	medium = CAMEL_MEDIUM (mime_part);
+
 	/* FIXME: this should perform content-location folding */
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part), "Content-Location", location);
+	camel_medium_set_header (medium, "Content-Location", location);
+
+	g_object_notify (G_OBJECT (mime_part), "content-location");
 }
 
 /**
@@ -595,7 +803,9 @@ camel_mime_part_set_content_location (CamelMimePart *mime_part, const gchar *loc
 const gchar *
 camel_mime_part_get_content_location (CamelMimePart *mime_part)
 {
-	return mime_part->content_location;
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
+	return mime_part->priv->content_location;
 }
 
 /* **** Content-Transfer-Encoding: */
@@ -609,13 +819,17 @@ camel_mime_part_get_content_location (CamelMimePart *mime_part)
  **/
 void
 camel_mime_part_set_encoding (CamelMimePart *mime_part,
-			      CamelTransferEncoding encoding)
+                              CamelTransferEncoding encoding)
 {
+	CamelMedium *medium;
 	const gchar *text;
 
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+	medium = CAMEL_MEDIUM (mime_part);
+
 	text = camel_transfer_encoding_to_string (encoding);
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part),
-				 "Content-Transfer-Encoding", text);
+	camel_medium_set_header (medium, "Content-Transfer-Encoding", text);
 }
 
 /**
@@ -629,7 +843,11 @@ camel_mime_part_set_encoding (CamelMimePart *mime_part,
 CamelTransferEncoding
 camel_mime_part_get_encoding (CamelMimePart *mime_part)
 {
-	return mime_part->encoding;
+	g_return_val_if_fail (
+		CAMEL_IS_MIME_PART (mime_part),
+		CAMEL_TRANSFER_ENCODING_DEFAULT);
+
+	return mime_part->priv->encoding;
 }
 
 /* FIXME: do something with this stuff ... */
@@ -642,12 +860,15 @@ camel_mime_part_get_encoding (CamelMimePart *mime_part)
  * Set the Content-Languages field of a MIME part.
  **/
 void
-camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *content_languages)
+camel_mime_part_set_content_languages (CamelMimePart *mime_part,
+                                       GList *content_languages)
 {
-	if (mime_part->content_languages)
-		camel_string_list_free (mime_part->content_languages);
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+	if (mime_part->priv->content_languages)
+		camel_string_list_free (mime_part->priv->content_languages);
 
-	mime_part->content_languages = content_languages;
+	mime_part->priv->content_languages = content_languages;
 
 	/* FIXME: translate to a header and set it */
 }
@@ -663,7 +884,9 @@ camel_mime_part_set_content_languages (CamelMimePart *mime_part, GList *content_
 const GList *
 camel_mime_part_get_content_languages (CamelMimePart *mime_part)
 {
-	return mime_part->content_languages;
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
+	return mime_part->priv->content_languages;
 }
 
 /* **** */
@@ -678,10 +901,16 @@ camel_mime_part_get_content_languages (CamelMimePart *mime_part)
  * Set the content-type on a MIME part.
  **/
 void
-camel_mime_part_set_content_type (CamelMimePart *mime_part, const gchar *content_type)
+camel_mime_part_set_content_type (CamelMimePart *mime_part,
+                                  const gchar *content_type)
 {
-	camel_medium_set_header (CAMEL_MEDIUM (mime_part),
-				 "Content-Type", content_type);
+	CamelMedium *medium;
+
+	g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+	medium = CAMEL_MEDIUM (mime_part);
+
+	camel_medium_set_header (medium, "Content-Type", content_type);
 }
 
 /**
@@ -695,23 +924,37 @@ camel_mime_part_set_content_type (CamelMimePart *mime_part, const gchar *content
 CamelContentType *
 camel_mime_part_get_content_type (CamelMimePart *mime_part)
 {
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
 	return ((CamelDataWrapper *) mime_part)->mime_type;
 }
 
+struct _camel_header_raw *
+camel_mime_part_get_raw_headers (CamelMimePart *mime_part)
+{
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+
+	return mime_part->priv->headers;
+}
+
 static void
-set_content_object (CamelMedium *medium, CamelDataWrapper *content)
+set_content (CamelMedium *medium,
+             CamelDataWrapper *content)
 {
 	CamelDataWrapper *mime_part = CAMEL_DATA_WRAPPER (medium);
+	CamelMediumClass *medium_class;
 	CamelContentType *content_type;
 
-	parent_class->set_content_object (medium, content);
+	/* Chain up to parent's set_content() method. */
+	medium_class = CAMEL_MEDIUM_CLASS (parent_class);
+	medium_class->set_content (medium, content);
 
 	content_type = camel_data_wrapper_get_mime_type_field (content);
 	if (mime_part->mime_type != content_type) {
 		gchar *txt;
 
 		txt = camel_content_type_format (content_type);
-		camel_medium_set_header (CAMEL_MEDIUM (mime_part), "Content-Type", txt);
+		camel_medium_set_header (medium, "Content-Type", txt);
 		g_free (txt);
 	}
 }
@@ -800,8 +1043,8 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 	/* FIXME: something needs to be done about this ... */
 	/* TODO: content-languages header? */
 
-	if (mp->headers) {
-		struct _camel_header_raw *h = mp->headers;
+	if (mp->priv->headers) {
+		struct _camel_header_raw *h = mp->priv->headers;
 		gchar *val;
 		gssize (*writefn)(CamelStream *stream, struct _camel_header_raw *);
 
@@ -831,10 +1074,10 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 		return -1;
 	total += count;
 
-	content = camel_medium_get_content_object(medium);
+	content = camel_medium_get_content (medium);
 	if (content) {
 		CamelMimeFilter *filter = NULL;
-		CamelStreamFilter *filter_stream = NULL;
+		CamelStream *filter_stream = NULL;
 		CamelMimeFilter *charenc = NULL;
 		const gchar *content_charset = NULL;
 		const gchar *part_charset = NULL;
@@ -851,13 +1094,13 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 			}
 		}
 
-		if (mp->encoding != content->encoding) {
-			switch (mp->encoding) {
+		if (mp->priv->encoding != content->encoding) {
+			switch (mp->priv->encoding) {
 			case CAMEL_TRANSFER_ENCODING_BASE64:
-				filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (CAMEL_MIME_FILTER_BASIC_BASE64_ENC);
+				filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_BASE64_ENC);
 				break;
 			case CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE:
-				filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (CAMEL_MIME_FILTER_BASIC_QP_ENC);
+				filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_QP_ENC);
 				break;
 			case CAMEL_TRANSFER_ENCODING_UUENCODE:
 				filename = camel_mime_part_get_filename (mp);
@@ -865,7 +1108,7 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 				if (count == -1)
 					return -1;
 				total += count;
-				filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (CAMEL_MIME_FILTER_BASIC_UU_ENC);
+				filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_UU_ENC);
 				break;
 			default:
 				/* content is encoded but the part doesn't want to be... */
@@ -875,15 +1118,17 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 		}
 
 		if (content_charset && part_charset && part_charset != content_charset)
-			charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (content_charset, part_charset);
+			charenc = camel_mime_filter_charset_new (content_charset, part_charset);
 
 		if (filter || charenc) {
-			filter_stream = camel_stream_filter_new_with_stream(stream);
+			filter_stream = camel_stream_filter_new (stream);
 
 			/* if we have a character encoder, add that always */
 			if (charenc) {
-				camel_stream_filter_add(filter_stream, charenc);
-				camel_object_unref (charenc);
+				camel_stream_filter_add (
+					CAMEL_STREAM_FILTER (filter_stream),
+					charenc);
+				g_object_unref (charenc);
 			}
 
 			/* we only re-do crlf on encoded blocks */
@@ -891,16 +1136,20 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 				CamelMimeFilter *crlf = camel_mime_filter_crlf_new(CAMEL_MIME_FILTER_CRLF_ENCODE,
 										   CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
 
-				camel_stream_filter_add(filter_stream, crlf);
-				camel_object_unref (crlf);
+				camel_stream_filter_add (
+					CAMEL_STREAM_FILTER (filter_stream),
+					crlf);
+				g_object_unref (crlf);
 			}
 
 			if (filter) {
-				camel_stream_filter_add(filter_stream, filter);
-				camel_object_unref (filter);
+				camel_stream_filter_add (
+					CAMEL_STREAM_FILTER (filter_stream),
+					filter);
+				g_object_unref (filter);
 			}
 
-			stream = (CamelStream *)filter_stream;
+			stream = filter_stream;
 
 			reencode = TRUE;
 		}
@@ -913,7 +1162,7 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 		if (filter_stream) {
 			errnosav = errno;
 			camel_stream_flush (stream);
-			camel_object_unref (filter_stream);
+			g_object_unref (filter_stream);
 			errno = errnosav;
 		}
 
@@ -922,7 +1171,7 @@ write_to_stream (CamelDataWrapper *dw, CamelStream *stream)
 
 		total += count;
 
-		if (reencode && mp->encoding == CAMEL_TRANSFER_ENCODING_UUENCODE) {
+		if (reencode && mp->priv->encoding == CAMEL_TRANSFER_ENCODING_UUENCODE) {
 			count = camel_stream_write (ostream, "end\n", 4);
 			if (count == -1)
 				return -1;
@@ -999,9 +1248,18 @@ construct_from_parser (CamelMimePart *mime_part, CamelMimeParser *mp)
  * Returns: %0 on success or %-1 on fail
  **/
 gint
-camel_mime_part_construct_from_parser(CamelMimePart *mime_part, CamelMimeParser *mp)
+camel_mime_part_construct_from_parser (CamelMimePart *mime_part,
+                                       CamelMimeParser *mp)
 {
-	return CMP_CLASS (mime_part)->construct_from_parser (mime_part, mp);
+	CamelMimePartClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), -1);
+	g_return_val_if_fail (CAMEL_IS_MIME_PARSER (mp), -1);
+
+	class = CAMEL_MIME_PART_GET_CLASS (mime_part);
+	g_return_val_if_fail (class->construct_from_parser != NULL, -1);
+
+	return class->construct_from_parser (mime_part, mp);
 }
 
 static gint
@@ -1019,7 +1277,7 @@ construct_from_stream(CamelDataWrapper *dw, CamelStream *s)
 	} else {
 		ret = camel_mime_part_construct_from_parser((CamelMimePart *)dw, mp);
 	}
-	camel_object_unref((CamelObject *)mp);
+	g_object_unref (mp);
 	return ret;
 }
 
@@ -1036,7 +1294,7 @@ construct_from_stream(CamelDataWrapper *dw, CamelStream *s)
 CamelMimePart *
 camel_mime_part_new (void)
 {
-	return (CamelMimePart *)camel_object_new (CAMEL_MIME_PART_TYPE);
+	return g_object_new (CAMEL_TYPE_MIME_PART, NULL);
 }
 
 /**
@@ -1066,14 +1324,11 @@ camel_mime_part_set_content (CamelMimePart *mime_part,
 		camel_data_wrapper_set_mime_type (dw, type);
 		stream = camel_stream_mem_new_with_buffer (data, length);
 		camel_data_wrapper_construct_from_stream (dw, stream);
-		camel_object_unref (stream);
-		camel_medium_set_content_object (medium, dw);
-		camel_object_unref (dw);
-	} else {
-		if (medium->content)
-			camel_object_unref (medium->content);
-		medium->content = NULL;
-	}
+		g_object_unref (stream);
+		camel_medium_set_content (medium, dw);
+		g_object_unref (dw);
+	} else
+		camel_medium_set_content (medium, NULL);
 }
 
 /**
@@ -1093,13 +1348,13 @@ camel_mime_part_get_content_size (CamelMimePart *mime_part)
 
 	g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), 0);
 
-	dw = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
+	dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
 
 	null = (CamelStreamNull *) camel_stream_null_new ();
 	camel_data_wrapper_decode_to_stream (dw, (CamelStream *) null);
 	size = null->written;
 
-	camel_object_unref (null);
+	g_object_unref (null);
 
 	return size;
 }
diff --git a/camel/camel-mime-part.h b/camel/camel-mime-part.h
index 0b92db9..0329183 100644
--- a/camel/camel-mime-part.h
+++ b/camel/camel-mime-part.h
@@ -23,46 +23,55 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MIME_PART_H
-#define CAMEL_MIME_PART_H 1
+#define CAMEL_MIME_PART_H
 
 #include <camel/camel-medium.h>
 #include <camel/camel-mime-utils.h>
 #include <camel/camel-mime-parser.h>
 
-#define CAMEL_MIME_PART_TYPE     (camel_mime_part_get_type ())
-#define CAMEL_MIME_PART(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MIME_PART_TYPE, CamelMimePart))
-#define CAMEL_MIME_PART_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MIME_PART_TYPE, CamelMimePartClass))
-#define CAMEL_IS_MIME_PART(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MIME_PART_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MIME_PART \
+	(camel_mime_part_get_type ())
+#define CAMEL_MIME_PART(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MIME_PART, CamelMimePart))
+#define CAMEL_MIME_PART_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MIME_PART, CamelMimePartClass))
+#define CAMEL_IS_MIME_PART(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MIME_PART))
+#define CAMEL_IS_MIME_PART_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MIME_PART))
+#define CAMEL_MIME_PART_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MIME_PART, CamelMimePartClass))
 
 G_BEGIN_DECLS
 
-/* Do not change these values directly, you would regret it one day */
+typedef struct _CamelMimePart CamelMimePart;
+typedef struct _CamelMimePartClass CamelMimePartClass;
+typedef struct _CamelMimePartPrivate CamelMimePartPrivate;
+
 struct _CamelMimePart {
-	CamelMedium parent_object;
-
-	struct _camel_header_raw *headers; /* mime headers */
-
-	/* All fields here are -** PRIVATE **- */
-	/* TODO: these should be in a camelcontentinfo */
-	gchar *description;
-	CamelContentDisposition *disposition;
-	gchar *content_id;
-	gchar *content_MD5;
-	gchar *content_location;
-	GList *content_languages;
-	CamelTransferEncoding encoding;
+	CamelMedium parent;
+	CamelMimePartPrivate *priv;
 };
 
-typedef struct _CamelMimePartClass {
+struct _CamelMimePartClass {
 	CamelMediumClass parent_class;
 
 	/* Virtual methods */
 	gint (*construct_from_parser) (CamelMimePart *, CamelMimeParser *);
-} CamelMimePartClass;
+};
 
-/* Standard Camel function */
-CamelType camel_mime_part_get_type (void);
+GType camel_mime_part_get_type (void);
 
 /* public methods */
 CamelMimePart *  camel_mime_part_new                    (void);
@@ -79,8 +88,8 @@ const	  gchar  *camel_mime_part_get_filename		(CamelMimePart *mime_part);
 void             camel_mime_part_set_content_id		(CamelMimePart *mime_part, const gchar *contentid);
 const	  gchar  *camel_mime_part_get_content_id		(CamelMimePart *mime_part);
 
-void		 camel_mime_part_set_content_MD5	(CamelMimePart *mime_part, const gchar *md5sum);
-const	  gchar  *camel_mime_part_get_content_MD5	(CamelMimePart *mime_part);
+void		 camel_mime_part_set_content_md5	(CamelMimePart *mime_part, const gchar *md5sum);
+const	  gchar  *camel_mime_part_get_content_md5	(CamelMimePart *mime_part);
 
 void		 camel_mime_part_set_content_location	(CamelMimePart *mime_part, const gchar *location);
 const	  gchar  *camel_mime_part_get_content_location	(CamelMimePart *mime_part);
@@ -95,6 +104,9 @@ const	  GList *camel_mime_part_get_content_languages	(CamelMimePart *mime_part);
 void               camel_mime_part_set_content_type	(CamelMimePart *mime_part, const gchar *content_type);
 CamelContentType  *camel_mime_part_get_content_type	(CamelMimePart *mime_part);
 
+struct _camel_header_raw *
+		camel_mime_part_get_raw_headers	(CamelMimePart *mime_part);
+
 /* construction */
 gint		camel_mime_part_construct_from_parser  (CamelMimePart *mime_part, CamelMimeParser *parser);
 
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index d3abbd2..2800815 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -42,8 +42,6 @@
 #define MAXHOSTNAMELEN 1024
 #endif
 
-#include <glib.h>
-
 #include <libedataserver/e-time-utils.h>
 
 #include "camel-charset-map.h"
diff --git a/camel/camel-mime-utils.h b/camel/camel-mime-utils.h
index 722576e..348b09f 100644
--- a/camel/camel-mime-utils.h
+++ b/camel/camel-mime-utils.h
@@ -20,8 +20,12 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MIME_UTILS_H
-#define _CAMEL_MIME_UTILS_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MIME_UTILS_H
+#define CAMEL_MIME_UTILS_H
 
 #include <time.h>
 #include <glib.h>
@@ -283,4 +287,4 @@ extern unsigned short camel_mime_special_table[256];
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MIME_UTILS_H */
+#endif /* CAMEL_MIME_UTILS_H */
diff --git a/camel/camel-movemail.c b/camel/camel-movemail.c
index 86f19c3..e048e05 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"
@@ -453,7 +452,7 @@ camel_movemail_solaris (gint oldsfd, gint dfd, CamelException *ex)
 	gchar *buffer;
 	gint len;
 	gint sfd;
-	CamelMimeFilterFrom *ffrom;
+	CamelMimeFilter *ffrom;
 	gint ret = 1;
 	gchar *from = NULL;
 
@@ -509,7 +508,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,8 +518,8 @@ camel_movemail_solaris (gint oldsfd, gint dfd, CamelException *ex)
 		g_free(from);
 	}
 
-	camel_object_unref((CamelObject *)mp);
-	camel_object_unref((CamelObject *)ffrom);
+	g_object_unref (mp);
+	g_object_unref (ffrom);
 
 	return ret;
 
@@ -531,8 +530,8 @@ fail:
 			      _("Error copying mail temp file: %s"),
 			      g_strerror (errno));
 
-	camel_object_unref((CamelObject *)mp);
-	camel_object_unref((CamelObject *)ffrom);
+	g_object_unref (mp);
+	g_object_unref (ffrom);
 
 	return -1;
 }
diff --git a/camel/camel-movemail.h b/camel/camel-movemail.h
index a0cbb47..2923274 100644
--- a/camel/camel-movemail.h
+++ b/camel/camel-movemail.h
@@ -22,8 +22,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MOVEMAIL_H
-#define CAMEL_MOVEMAIL_H 1
+#define CAMEL_MOVEMAIL_H
 
 #include <camel/camel-exception.h>
 
diff --git a/camel/camel-msgport.h b/camel/camel-msgport.h
index da89c73..563d13c 100644
--- a/camel/camel-msgport.h
+++ b/camel/camel-msgport.h
@@ -18,6 +18,10 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MSGPORT_H
 #define CAMEL_MSGPORT_H
 
diff --git a/camel/camel-multipart-encrypted.c b/camel/camel-multipart-encrypted.c
index 7988bfd..600b672 100644
--- a/camel/camel-multipart-encrypted.c
+++ b/camel/camel-multipart-encrypted.c
@@ -27,7 +27,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-mime-filter-crlf.h"
@@ -38,80 +37,102 @@
 #include "camel-stream-fs.h"
 #include "camel-stream-mem.h"
 
-static void camel_multipart_encrypted_class_init (CamelMultipartEncryptedClass *klass);
-static void camel_multipart_encrypted_init (gpointer object, gpointer klass);
-static void camel_multipart_encrypted_finalize (CamelObject *object);
+static gpointer parent_class;
 
-static void set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type);
+static void
+multipart_encrypted_dispose (GObject *object)
+{
+	CamelMultipartEncrypted *multipart;
 
-static CamelMultipartClass *parent_class = NULL;
+	multipart = CAMEL_MULTIPART_ENCRYPTED (object);
 
-CamelType
-camel_multipart_encrypted_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_multipart_get_type (),
-					    "CamelMultipartEncrypted",
-					    sizeof (CamelMultipartEncrypted),
-					    sizeof (CamelMultipartEncryptedClass),
-					    (CamelObjectClassInitFunc) camel_multipart_encrypted_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_multipart_encrypted_init,
-					    (CamelObjectFinalizeFunc) camel_multipart_encrypted_finalize);
+	if (multipart->decrypted) {
+		g_object_unref (multipart->decrypted);
+		multipart->decrypted = NULL;
 	}
 
-	return type;
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_multipart_encrypted_class_init (CamelMultipartEncryptedClass *klass)
+multipart_encrypted_finalize (GObject *object)
 {
-	CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (klass);
+	CamelMultipartEncrypted *multipart;
+
+	multipart = CAMEL_MULTIPART_ENCRYPTED (object);
 
-	parent_class = (CamelMultipartClass *) camel_multipart_get_type ();
+	g_free (multipart->protocol);
 
-	/* virtual method overload */
-	camel_data_wrapper_class->set_mime_type_field = set_mime_type_field;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+/* we snoop the mime type to get the protocol */
 static void
-camel_multipart_encrypted_init (gpointer object, gpointer klass)
+multipart_encrypted_set_mime_type_field (CamelDataWrapper *data_wrapper,
+                                         CamelContentType *mime_type)
 {
-	CamelMultipartEncrypted *multipart = (CamelMultipartEncrypted *) object;
+	CamelMultipartEncrypted *multipart;
+	CamelDataWrapperClass *data_wrapper_class;
 
-	camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (multipart), "multipart/encrypted");
+	multipart = CAMEL_MULTIPART_ENCRYPTED (data_wrapper);
 
-	multipart->decrypted = NULL;
+	if (mime_type != NULL) {
+		const gchar *protocol;
+
+		protocol = camel_content_type_param (mime_type, "protocol");
+		g_free (multipart->protocol);
+		multipart->protocol = g_strdup (protocol);
+	}
+
+	/* Chain up to parent's set_mime_type_field() method. */
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (parent_class);
+	data_wrapper_class->set_mime_type_field (data_wrapper, mime_type);
 }
 
 static void
-camel_multipart_encrypted_finalize (CamelObject *object)
+multipart_encrypted_class_init (CamelMultipartEncryptedClass *class)
 {
-	CamelMultipartEncrypted *mpe = (CamelMultipartEncrypted *) object;
+	GObjectClass *object_class;
+	CamelDataWrapperClass *data_wrapper_class;
+
+	parent_class = g_type_class_peek_parent (class);
 
-	g_free (mpe->protocol);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = multipart_encrypted_dispose;
+	object_class->finalize = multipart_encrypted_finalize;
 
-	if (mpe->decrypted)
-		camel_object_unref (mpe->decrypted);
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->set_mime_type_field =
+		multipart_encrypted_set_mime_type_field;
 }
 
-/* we snoop the mime type to get the protocol */
 static void
-set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type)
+multipart_encrypted_init (CamelMultipartEncrypted *multipart)
 {
-	CamelMultipartEncrypted *mpe = (CamelMultipartEncrypted *) data_wrapper;
+	camel_data_wrapper_set_mime_type (
+		CAMEL_DATA_WRAPPER (multipart), "multipart/encrypted");
 
-	if (mime_type) {
-		const gchar *protocol;
+	multipart->decrypted = NULL;
+}
 
-		protocol = camel_content_type_param (mime_type, "protocol");
-		g_free (mpe->protocol);
-		mpe->protocol = g_strdup (protocol);
-	}
+GType
+camel_multipart_encrypted_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MULTIPART,
+			"CamelMultipartEncrypted",
+			sizeof (CamelMultipartEncryptedClass),
+			(GClassInitFunc) multipart_encrypted_class_init,
+			sizeof (CamelMultipartEncrypted),
+			(GInstanceInitFunc) multipart_encrypted_init,
+			0);
 
-	((CamelDataWrapperClass *) parent_class)->set_mime_type_field (data_wrapper, mime_type);
+	return type;
 }
 
 /**
@@ -127,9 +148,5 @@ set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type
 CamelMultipartEncrypted *
 camel_multipart_encrypted_new (void)
 {
-	CamelMultipartEncrypted *multipart;
-
-	multipart = (CamelMultipartEncrypted *) camel_object_new (CAMEL_MULTIPART_ENCRYPTED_TYPE);
-
-	return multipart;
+	return g_object_new (CAMEL_TYPE_MULTIPART_ENCRYPTED, NULL);
 }
diff --git a/camel/camel-multipart-encrypted.h b/camel/camel-multipart-encrypted.h
index 7068cd5..8c66588 100644
--- a/camel/camel-multipart-encrypted.h
+++ b/camel/camel-multipart-encrypted.h
@@ -20,15 +20,33 @@
  *
  */
 
-#ifndef __CAMEL_MULTIPART_ENCRYPTED_H__
-#define __CAMEL_MULTIPART_ENCRYPTED_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_MULTIPART_ENCRYPTED_H
+#define CAMEL_MULTIPART_ENCRYPTED_H
 
 #include <camel/camel-multipart.h>
 
-#define CAMEL_MULTIPART_ENCRYPTED_TYPE     (camel_multipart_encrypted_get_type ())
-#define CAMEL_MULTIPART_ENCRYPTED(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MULTIPART_ENCRYPTED_TYPE, CamelMultipartEncrypted))
-#define CAMEL_MULTIPART_ENCRYPTED_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MULTIPART_ENCRYPTED_TYPE, CamelMultipartEncryptedClass))
-#define CAMEL_IS_MULTIPART_ENCRYPTED(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MULTIPART_ENCRYPTED_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MULTIPART_ENCRYPTED \
+	(camel_multipart_encrypted_get_type ())
+#define CAMEL_MULTIPART_ENCRYPTED(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MULTIPART_ENCRYPTED, CamelMultipartEncrypted))
+#define CAMEL_MULTIPART_ENCRYPTED_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MULTIPART_ENCRYPTED, CamelMultipartEncryptedClass))
+#define CAMEL_IS_MULTIPART_ENCRYPTED(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MULTIPART_ENCRYPTED))
+#define CAMEL_IS_MULTIPART_ENCRYPTED_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MULTIPART_ENCRYPTED))
+#define CAMEL_MULTIPART_ENCRYPTED_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MULTIPART_ENCRYPTED, CamelMultipartEncryptedClass))
 
 G_BEGIN_DECLS
 
@@ -42,7 +60,7 @@ enum {
 };
 
 struct _CamelMultipartEncrypted {
-	CamelMultipart parent_object;
+	CamelMultipart parent;
 
 	CamelMimePart *version;
 	CamelMimePart *content;
@@ -56,10 +74,10 @@ struct _CamelMultipartEncryptedClass {
 
 };
 
-CamelType camel_multipart_encrypted_get_type (void);
+GType camel_multipart_encrypted_get_type (void);
 
 CamelMultipartEncrypted *camel_multipart_encrypted_new (void);
 
 G_END_DECLS
 
-#endif /* __CAMEL_MULTIPART_ENCRYPTED_H__ */
+#endif /* CAMEL_MULTIPART_ENCRYPTED_H */
diff --git a/camel/camel-multipart-signed.c b/camel/camel-multipart-signed.c
index 4cba88e..77512b6 100644
--- a/camel/camel-multipart-signed.c
+++ b/camel/camel-multipart-signed.c
@@ -34,7 +34,6 @@
 #include <alloca.h>
 #endif
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
@@ -64,82 +63,102 @@ static void set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentTyp
 static gint construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
 static gint signed_construct_from_parser (CamelMultipart *multipart, struct _CamelMimeParser *mp);
 
-static CamelMultipartClass *parent_class = NULL;
+static gpointer parent_class;
 
-/* Returns the class for a CamelMultipartSigned */
-#define CMP_CLASS(so) CAMEL_MULTIPART_SIGNED_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static void
+multipart_signed_dispose (GObject *object)
+{
+	CamelMultipartSigned *multipart;
+
+	multipart = CAMEL_MULTIPART_SIGNED (object);
+
+	if (multipart->signature != NULL) {
+		g_object_unref (multipart->signature);
+		multipart->signature = NULL;
+	}
+
+	if (multipart->content != NULL) {
+		g_object_unref (multipart->content);
+		multipart->content = NULL;
+	}
+
+	if (multipart->contentraw != NULL) {
+		g_object_unref (multipart->contentraw);
+		multipart->contentraw = NULL;
+	}
 
-/* Returns the class for a CamelDataWrapper */
-#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
 
 static void
-camel_multipart_signed_class_init (CamelMultipartSignedClass *camel_multipart_signed_class)
+multipart_signed_finalize (GObject *object)
 {
-	CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS(camel_multipart_signed_class);
-	CamelMultipartClass *mpclass = (CamelMultipartClass *)camel_multipart_signed_class;
-
-	parent_class = (CamelMultipartClass *)camel_multipart_get_type();
-
-	/* virtual method overload */
-	camel_data_wrapper_class->construct_from_stream = construct_from_stream;
-	camel_data_wrapper_class->write_to_stream = write_to_stream;
-	camel_data_wrapper_class->decode_to_stream = write_to_stream;
-	camel_data_wrapper_class->set_mime_type_field = set_mime_type_field;
-
-	mpclass->add_part = signed_add_part;
-	mpclass->add_part_at = signed_add_part_at;
-	mpclass->remove_part = signed_remove_part;
-	mpclass->remove_part_at = signed_remove_part_at;
-	mpclass->get_part = signed_get_part;
-	mpclass->get_number = signed_get_number;
-	mpclass->construct_from_parser = signed_construct_from_parser;
-
-/*
-	mpclass->get_boundary = signed_get_boundary;
-	mpclass->set_boundary = signed_set_boundary;
-*/
+	CamelMultipartSigned *multipart;
+
+	multipart = CAMEL_MULTIPART_SIGNED (object);
+
+	g_free (multipart->protocol);
+	g_free (multipart->micalg);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_multipart_signed_init (gpointer object, gpointer klass)
+multipart_signed_class_init (CamelMultipartSignedClass *class)
 {
-	CamelMultipartSigned *multipart = (CamelMultipartSigned *)object;
-
-	camel_data_wrapper_set_mime_type(CAMEL_DATA_WRAPPER(multipart), "multipart/signed");
-	multipart->start1 = -1;
+	GObjectClass *object_class;
+	CamelDataWrapperClass *data_wrapper_class;
+	CamelMultipartClass *multipart_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = multipart_signed_dispose;
+	object_class->finalize = multipart_signed_finalize;
+
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->construct_from_stream = construct_from_stream;
+	data_wrapper_class->write_to_stream = write_to_stream;
+	data_wrapper_class->decode_to_stream = write_to_stream;
+	data_wrapper_class->set_mime_type_field = set_mime_type_field;
+
+	multipart_class = CAMEL_MULTIPART_CLASS (class);
+	multipart_class->add_part = signed_add_part;
+	multipart_class->add_part_at = signed_add_part_at;
+	multipart_class->remove_part = signed_remove_part;
+	multipart_class->remove_part_at = signed_remove_part_at;
+	multipart_class->get_part = signed_get_part;
+	multipart_class->get_number = signed_get_number;
+	multipart_class->construct_from_parser = signed_construct_from_parser;
 }
 
 static void
-camel_multipart_signed_finalize (CamelObject *object)
+multipart_signed_init (CamelMultipartSigned *multipart)
 {
-	CamelMultipartSigned *mps = (CamelMultipartSigned *)object;
-
-	g_free(mps->protocol);
-	g_free(mps->micalg);
-	if (mps->signature)
-		camel_object_unref((CamelObject *)mps->signature);
-	if (mps->content)
-		camel_object_unref((CamelObject *)mps->content);
-	if (mps->contentraw)
-		camel_object_unref((CamelObject *)mps->contentraw);
+	camel_data_wrapper_set_mime_type (
+		CAMEL_DATA_WRAPPER (multipart), "multipart/signed");
+
+	multipart->start1 = -1;
 }
 
-CamelType
+GType
 camel_multipart_signed_get_type (void)
 {
-	static CamelType camel_multipart_signed_type = CAMEL_INVALID_TYPE;
-
-	if (camel_multipart_signed_type == CAMEL_INVALID_TYPE) {
-		camel_multipart_signed_type = camel_type_register (camel_multipart_get_type (), "CamelMultipartSigned",
-								   sizeof (CamelMultipartSigned),
-								   sizeof (CamelMultipartSignedClass),
-								   (CamelObjectClassInitFunc) camel_multipart_signed_class_init,
-								   NULL,
-								   (CamelObjectInitFunc) camel_multipart_signed_init,
-								   (CamelObjectFinalizeFunc) camel_multipart_signed_finalize);
-	}
-
-	return camel_multipart_signed_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MULTIPART,
+			"CamelMultipartSigned",
+			sizeof (CamelMultipartSignedClass),
+			(GClassInitFunc) multipart_signed_class_init,
+			sizeof (CamelMultipartSigned),
+			(GInstanceInitFunc) multipart_signed_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -173,11 +192,7 @@ camel_multipart_signed_get_type (void)
 CamelMultipartSigned *
 camel_multipart_signed_new (void)
 {
-	CamelMultipartSigned *multipart;
-
-	multipart = (CamelMultipartSigned *)camel_object_new(CAMEL_MULTIPART_SIGNED_TYPE);
-
-	return multipart;
+	return g_object_new (CAMEL_TYPE_MULTIPART_SIGNED, NULL);
 }
 
 static gint
@@ -229,7 +244,7 @@ parse_content(CamelMultipartSigned *mps)
 {
 	CamelMimeParser *cmp;
 	CamelMultipart *mp = (CamelMultipart *)mps;
-	CamelStreamMem *mem;
+	CamelStream *stream;
 	const gchar *boundary;
 	gchar *buf;
 	gsize len;
@@ -241,8 +256,8 @@ parse_content(CamelMultipartSigned *mps)
 		return -1;
 	}
 
-	mem = (CamelStreamMem *)((CamelDataWrapper *)mps)->stream;
-	if (mem == NULL) {
+	stream = ((CamelDataWrapper *)mps)->stream;
+	if (stream == NULL) {
 		g_warning("Trying to parse multipart/signed without constructing first");
 		return -1;
 	}
@@ -251,9 +266,9 @@ parse_content(CamelMultipartSigned *mps)
 	   This is so we can parse all cases properly, without altering the content.
 	   All we are doing is finding part offsets. */
 
-	camel_stream_reset((CamelStream *)mem);
+	camel_stream_reset(stream);
 	cmp = camel_mime_parser_new();
-	camel_mime_parser_init_with_stream(cmp, (CamelStream *)mem);
+	camel_mime_parser_init_with_stream(cmp, stream);
 	camel_mime_parser_push_state(cmp, CAMEL_MIME_PARSER_STATE_MULTIPART, boundary);
 
 	mps->start1 = -1;
@@ -265,11 +280,15 @@ parse_content(CamelMultipartSigned *mps)
 		if (mps->start1 == -1) {
 			mps->start1 = camel_mime_parser_tell_start_headers(cmp);
 		} else if (mps->start2 == -1) {
+			GByteArray *buffer;
+
+			buffer = camel_stream_mem_get_byte_array (
+				CAMEL_STREAM_MEM (stream));
 			mps->start2 = camel_mime_parser_tell_start_headers(cmp);
 			mps->end1 = camel_mime_parser_tell_start_boundary(cmp);
-			if (mps->end1 > mps->start1 && mem->buffer->data[mps->end1-1] == '\n')
+			if (mps->end1 > mps->start1 && buffer->data[mps->end1-1] == '\n')
 				mps->end1--;
-			if (mps->end1 > mps->start1 && mem->buffer->data[mps->end1-1] == '\r')
+			if (mps->end1 > mps->start1 && buffer->data[mps->end1-1] == '\r')
 				mps->end1--;
 		} else {
 			g_warning("multipart/signed has more than 2 parts, remaining parts ignored");
@@ -287,7 +306,7 @@ parse_content(CamelMultipartSigned *mps)
 		camel_multipart_set_postface(mp, camel_mime_parser_postface(cmp));
 	}
 
-	camel_object_unref(cmp);
+	g_object_unref (cmp);
 
 	if (mps->end2 == -1 || mps->start2 == -1) {
 		return -1;
@@ -354,7 +373,7 @@ signed_get_part(CamelMultipart *multipart, guint index)
 			return mps->content;
 		if (mps->contentraw) {
 			stream = mps->contentraw;
-			camel_object_ref((CamelObject *)stream);
+			g_object_ref (stream);
 		} else if (mps->start1 == -1
 			   && parse_content(mps) == -1
 			   && (stream = ((CamelDataWrapper *)mps)->stream) == NULL) {
@@ -364,14 +383,14 @@ signed_get_part(CamelMultipart *multipart, guint index)
 			return NULL;
 		} else if (mps->start1 == -1) {
 			stream = dw->stream;
-			camel_object_ref(stream);
+			g_object_ref (stream);
 		} else {
 			stream = camel_seekable_substream_new((CamelSeekableStream *)dw->stream, mps->start1, mps->end1);
 		}
 		camel_stream_reset(stream);
 		mps->content = camel_mime_part_new();
 		camel_data_wrapper_construct_from_stream((CamelDataWrapper *)mps->content, stream);
-		camel_object_unref(stream);
+		g_object_unref (stream);
 		return mps->content;
 	case CAMEL_MULTIPART_SIGNED_SIGNATURE:
 		if (mps->signature)
@@ -387,7 +406,7 @@ signed_get_part(CamelMultipart *multipart, guint index)
 		camel_stream_reset(stream);
 		mps->signature = camel_mime_part_new();
 		camel_data_wrapper_construct_from_stream((CamelDataWrapper *)mps->signature, stream);
-		camel_object_unref((CamelObject *)stream);
+		g_object_unref (stream);
 		return mps->signature;
 	default:
 		g_warning("trying to get object out of bounds for multipart");
@@ -418,25 +437,25 @@ signed_get_number(CamelMultipart *multipart)
 }
 
 static void
-set_stream(CamelMultipartSigned *mps, CamelStream *mem)
+set_stream(CamelMultipartSigned *mps, CamelStream *stream)
 {
 	CamelDataWrapper *dw = (CamelDataWrapper *)mps;
 
 	if (dw->stream)
-		camel_object_unref((CamelObject *)dw->stream);
-	dw->stream = (CamelStream *)mem;
+		g_object_unref (dw->stream);
+	dw->stream = stream;
 
 	mps->start1 = -1;
 	if (mps->content) {
-		camel_object_unref((CamelObject *)mps->content);
+		g_object_unref (mps->content);
 		mps->content = NULL;
 	}
 	if (mps->contentraw) {
-		camel_object_unref((CamelObject *)mps->contentraw);
+		g_object_unref (mps->contentraw);
 		mps->contentraw = NULL;
 	}
 	if (mps->signature) {
-		camel_object_unref((CamelObject *)mps->signature);
+		g_object_unref (mps->signature);
 		mps->signature = NULL;
 	}
 }
@@ -463,7 +482,7 @@ signed_construct_from_parser(CamelMultipart *multipart, struct _CamelMimeParser
 	CamelMultipartSigned *mps = (CamelMultipartSigned *)multipart;
 	gchar *buf;
 	gsize len;
-	CamelStream *mem;
+	CamelStream *stream;
 
 	/* we *must not* be in multipart state, otherwise the mime parser will
 	   parse the headers which is a no no @#$ # stupid multipart/signed spec */
@@ -473,11 +492,11 @@ signed_construct_from_parser(CamelMultipart *multipart, struct _CamelMimeParser
 	content_type = camel_mime_parser_content_type(mp);
 	camel_multipart_set_boundary(multipart, camel_content_type_param(content_type, "boundary"));
 
-	mem = camel_stream_mem_new();
+	stream = camel_stream_mem_new();
 	while (camel_mime_parser_step(mp, &buf, &len) != CAMEL_MIME_PARSER_STATE_BODY_END)
-		camel_stream_write(mem, buf, len);
+		camel_stream_write(stream, buf, len);
 
-	set_stream(mps, mem);
+	set_stream(mps, stream);
 
 	err = camel_mime_parser_errno(mp);
 	if (err != 0) {
@@ -583,7 +602,7 @@ camel_multipart_signed_get_content_stream(CamelMultipartSigned *mps, CamelExcept
 
 	if (mps->contentraw) {
 		constream = mps->contentraw;
-		camel_object_ref((CamelObject *)constream);
+		g_object_ref (constream);
 	} else {
 		CamelStream *sub;
 		CamelMimeFilter *canon_filter;
@@ -595,13 +614,13 @@ camel_multipart_signed_get_content_stream(CamelMultipartSigned *mps, CamelExcept
 
 		/* first, prepare our parts */
 		sub = camel_seekable_substream_new((CamelSeekableStream *)((CamelDataWrapper *)mps)->stream, mps->start1, mps->end1);
-		constream = (CamelStream *)camel_stream_filter_new_with_stream(sub);
-		camel_object_unref((CamelObject *)sub);
+		constream = camel_stream_filter_new (sub);
+		g_object_unref (sub);
 
 		/* Note: see rfc2015 or rfc3156, section 5 */
 		canon_filter = camel_mime_filter_canon_new (CAMEL_MIME_FILTER_CANON_CRLF);
 		camel_stream_filter_add((CamelStreamFilter *)constream, (CamelMimeFilter *)canon_filter);
-		camel_object_unref((CamelObject *)canon_filter);
+		g_object_unref (canon_filter);
 	}
 
 	return constream;
diff --git a/camel/camel-multipart-signed.h b/camel/camel-multipart-signed.h
index 8e673dc..20b1054 100644
--- a/camel/camel-multipart-signed.h
+++ b/camel/camel-multipart-signed.h
@@ -24,15 +24,33 @@
    No, because we dont have different parts?
    I'm not really sure yet ... ? */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MULTIPART_SIGNED_H
-#define CAMEL_MULTIPART_SIGNED_H 1
+#define CAMEL_MULTIPART_SIGNED_H
 
 #include <camel/camel-multipart.h>
 
-#define CAMEL_MULTIPART_SIGNED_TYPE     (camel_multipart_signed_get_type ())
-#define CAMEL_MULTIPART_SIGNED(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MULTIPART_SIGNED_TYPE, CamelMultipartSigned))
-#define CAMEL_MULTIPART_SIGNED_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MULTIPART_SIGNED_TYPE, CamelMultipartSignedClass))
-#define CAMEL_IS_MULTIPART_SIGNED(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MULTIPART_SIGNED_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MULTIPART_SIGNED \
+	(camel_multipart_signed_get_type ())
+#define CAMEL_MULTIPART_SIGNED(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MULTIPART_SIGNED, CamelMultipartSigned))
+#define CAMEL_MULTIPART_SIGNED_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MULTIPART_SIGNED, CamelMultipartSignedClass))
+#define CAMEL_IS_MULTIPART_SIGNED(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MULTIPART_SIGNED))
+#define CAMEL_IS_MULTIPART_SIGNED_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MULTIPART_SIGNED))
+#define CAMEL_MULTIPART_SIGNED_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MULTIPART_SIGNED, CamelMultipartSignedClass))
 
 G_BEGIN_DECLS
 
@@ -55,7 +73,7 @@ typedef struct _CamelMultipartSigned CamelMultipartSigned;
 
 struct _CamelMultipartSigned
 {
-	CamelMultipart parent_object;
+	CamelMultipart parent;
 
 	/* these are the client visible parts, decoded forms of our data wrapper content */
 	CamelMimePart *content;
@@ -81,8 +99,7 @@ typedef struct {
 	CamelMultipartClass parent_class;
 } CamelMultipartSignedClass;
 
-/* Standard Camel function */
-CamelType camel_multipart_signed_get_type (void);
+GType camel_multipart_signed_get_type (void);
 
 /* public methods */
 CamelMultipartSigned *camel_multipart_signed_new           (void);
diff --git a/camel/camel-multipart.c b/camel/camel-multipart.c
index eb2da00..f90fc32 100644
--- a/camel/camel-multipart.c
+++ b/camel/camel-multipart.c
@@ -59,86 +59,88 @@ static gssize               write_to_stream   (CamelDataWrapper *data_wrapper,
 
 static gint construct_from_parser(CamelMultipart *multipart, struct _CamelMimeParser *mp);
 
-static CamelDataWrapperClass *parent_class = NULL;
-
-/* Returns the class for a CamelMultipart */
-#define CMP_CLASS(so) CAMEL_MULTIPART_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-/* Returns the class for a CamelDataWrapper */
-#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-static void
-camel_multipart_class_init (CamelMultipartClass *camel_multipart_class)
-{
-	CamelDataWrapperClass *camel_data_wrapper_class =
-		CAMEL_DATA_WRAPPER_CLASS (camel_multipart_class);
-
-	parent_class = (CamelDataWrapperClass *) camel_data_wrapper_get_type ();
-
-	/* virtual method definition */
-	camel_multipart_class->add_part = add_part;
-	camel_multipart_class->add_part_at = add_part_at;
-	camel_multipart_class->remove_part = remove_part;
-	camel_multipart_class->remove_part_at = remove_part_at;
-	camel_multipart_class->get_part = get_part;
-	camel_multipart_class->get_number = get_number;
-	camel_multipart_class->set_boundary = set_boundary;
-	camel_multipart_class->get_boundary = get_boundary;
-	camel_multipart_class->construct_from_parser = construct_from_parser;
-
-	/* virtual method overload */
-	camel_data_wrapper_class->write_to_stream = write_to_stream;
-	camel_data_wrapper_class->decode_to_stream = write_to_stream;
-	camel_data_wrapper_class->is_offline = is_offline;
-}
+static gpointer parent_class;
 
 static void
-camel_multipart_init (gpointer object, gpointer klass)
+multipart_dispose (GObject *object)
 {
 	CamelMultipart *multipart = CAMEL_MULTIPART (object);
 
-	camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (multipart),
-					  "multipart/mixed");
+	g_list_foreach (multipart->parts, (GFunc) g_object_unref, NULL);
+	g_list_free (multipart->parts);
 	multipart->parts = NULL;
-	multipart->preface = NULL;
-	multipart->postface = NULL;
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_multipart_finalize (CamelObject *object)
+multipart_finalize (GObject *object)
 {
 	CamelMultipart *multipart = CAMEL_MULTIPART (object);
 
-	g_list_foreach (multipart->parts, (GFunc) camel_object_unref, NULL);
+	g_free (multipart->preface);
+	g_free (multipart->postface);
 
-	if (multipart->parts)
-		g_list_free (multipart->parts);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
 
-	/*if (multipart->boundary)
-	  g_free (multipart->boundary);*/
+static void
+multipart_class_init (CamelMultipartClass *class)
+{
+	GObjectClass *object_class;
+	CamelDataWrapperClass *data_wrapper_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = multipart_dispose;
+	object_class->finalize = multipart_finalize;
+
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->write_to_stream = write_to_stream;
+	data_wrapper_class->decode_to_stream = write_to_stream;
+	data_wrapper_class->is_offline = is_offline;
+
+	class->add_part = add_part;
+	class->add_part_at = add_part_at;
+	class->remove_part = remove_part;
+	class->remove_part_at = remove_part_at;
+	class->get_part = get_part;
+	class->get_number = get_number;
+	class->set_boundary = set_boundary;
+	class->get_boundary = get_boundary;
+	class->construct_from_parser = construct_from_parser;
+}
 
-	if (multipart->preface)
-		g_free (multipart->preface);
-	if (multipart->postface)
-		g_free (multipart->postface);
+static void
+multipart_init (CamelMultipart *multipart)
+{
+	camel_data_wrapper_set_mime_type (
+		CAMEL_DATA_WRAPPER (multipart), "multipart/mixed");
+	multipart->parts = NULL;
+	multipart->preface = NULL;
+	multipart->postface = NULL;
 }
 
-CamelType
+GType
 camel_multipart_get_type (void)
 {
-	static CamelType camel_multipart_type = CAMEL_INVALID_TYPE;
-
-	if (camel_multipart_type == CAMEL_INVALID_TYPE) {
-		camel_multipart_type = camel_type_register (camel_data_wrapper_get_type (), "CamelMultipart",
-							    sizeof (CamelMultipart),
-							    sizeof (CamelMultipartClass),
-							    (CamelObjectClassInitFunc) camel_multipart_class_init,
-							    NULL,
-							    (CamelObjectInitFunc) camel_multipart_init,
-							    (CamelObjectFinalizeFunc) camel_multipart_finalize);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID)) {
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_DATA_WRAPPER,
+			"CamelMultipart",
+			sizeof (CamelMultipartClass),
+			(GClassInitFunc) multipart_class_init,
+			sizeof (CamelMultipart),
+			(GInstanceInitFunc) multipart_init,
+			0);
 	}
 
-	return camel_multipart_type;
+	return type;
 }
 
 /**
@@ -153,7 +155,7 @@ camel_multipart_new (void)
 {
 	CamelMultipart *multipart;
 
-	multipart = (CamelMultipart *)camel_object_new (CAMEL_MULTIPART_TYPE);
+	multipart = g_object_new (CAMEL_TYPE_MULTIPART, NULL);
 	multipart->preface = NULL;
 	multipart->postface = NULL;
 
@@ -164,7 +166,7 @@ static void
 add_part (CamelMultipart *multipart, CamelMimePart *part)
 {
 	multipart->parts = g_list_append (multipart->parts, part);
-	camel_object_ref (part);
+	g_object_ref (part);
 }
 
 /**
@@ -175,19 +177,25 @@ add_part (CamelMultipart *multipart, CamelMimePart *part)
  * Appends the part to the multipart object.
  **/
 void
-camel_multipart_add_part (CamelMultipart *multipart, CamelMimePart *part)
+camel_multipart_add_part (CamelMultipart *multipart,
+                          CamelMimePart *part)
 {
+	CamelMultipartClass *class;
+
 	g_return_if_fail (CAMEL_IS_MULTIPART (multipart));
 	g_return_if_fail (CAMEL_IS_MIME_PART (part));
 
-	CMP_CLASS (multipart)->add_part (multipart, part);
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_if_fail (class->add_part != NULL);
+
+	class->add_part (multipart, part);
 }
 
 static void
 add_part_at (CamelMultipart *multipart, CamelMimePart *part, guint index)
 {
 	multipart->parts = g_list_insert (multipart->parts, part, index);
-	camel_object_ref (part);
+	g_object_ref (part);
 }
 
 /**
@@ -202,12 +210,17 @@ add_part_at (CamelMultipart *multipart, CamelMimePart *part, guint index)
  **/
 void
 camel_multipart_add_part_at (CamelMultipart *multipart,
-			     CamelMimePart *part, guint index)
+                             CamelMimePart *part, guint index)
 {
+	CamelMultipartClass *class;
+
 	g_return_if_fail (CAMEL_IS_MULTIPART (multipart));
 	g_return_if_fail (CAMEL_IS_MIME_PART (part));
 
-	CMP_CLASS (multipart)->add_part_at (multipart, part, index);
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_if_fail (class->add_part_at != NULL);
+
+	class->add_part_at (multipart, part, index);
 }
 
 static void
@@ -216,7 +229,7 @@ remove_part (CamelMultipart *multipart, CamelMimePart *part)
 	if (!multipart->parts)
 		return;
 	multipart->parts = g_list_remove (multipart->parts, part);
-	camel_object_unref (part);
+	g_object_unref (part);
 }
 
 /**
@@ -228,12 +241,17 @@ remove_part (CamelMultipart *multipart, CamelMimePart *part)
  **/
 void
 camel_multipart_remove_part (CamelMultipart *multipart,
-			     CamelMimePart *part)
+                             CamelMimePart *part)
 {
+	CamelMultipartClass *class;
+
 	g_return_if_fail (CAMEL_IS_MULTIPART (multipart));
 	g_return_if_fail (CAMEL_IS_MIME_PART (part));
 
-	CMP_CLASS (multipart)->remove_part (multipart, part);
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_if_fail (class->remove_part != NULL);
+
+	class->remove_part (multipart, part);
 }
 
 static CamelMimePart *
@@ -257,7 +275,7 @@ remove_part_at (CamelMultipart *multipart, guint index)
 
 	multipart->parts = g_list_remove_link (parts_list, part_to_remove);
 	if (part_to_remove->data)
-		camel_object_unref (part_to_remove->data);
+		g_object_unref (part_to_remove->data);
 	g_list_free_1 (part_to_remove);
 
 	return removed_part;
@@ -270,15 +288,21 @@ remove_part_at (CamelMultipart *multipart, guint index)
  *
  * Remove the indicated part from the multipart object.
  *
- * Returns: the removed part. Note that it is #camel_object_unref'ed
+ * Returns: the removed part. Note that it is #g_object_unref'ed
  * before being returned, which may cause it to be destroyed.
  **/
 CamelMimePart *
-camel_multipart_remove_part_at (CamelMultipart *multipart, guint index)
+camel_multipart_remove_part_at (CamelMultipart *multipart,
+                                guint index)
 {
+	CamelMultipartClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), NULL);
 
-	return CMP_CLASS (multipart)->remove_part_at (multipart, index);
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_val_if_fail (class->remove_part_at != NULL, NULL);
+
+	return class->remove_part_at (multipart, index);
 }
 
 static CamelMimePart *
@@ -304,11 +328,17 @@ get_part (CamelMultipart *multipart, guint index)
  * Returns: the indicated subpart, or %NULL
  **/
 CamelMimePart *
-camel_multipart_get_part (CamelMultipart *multipart, guint index)
+camel_multipart_get_part (CamelMultipart *multipart,
+                          guint index)
 {
+	CamelMultipartClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), NULL);
 
-	return CMP_CLASS (multipart)->get_part (multipart, index);
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_val_if_fail (class->get_part != NULL, NULL);
+
+	return class->get_part (multipart, index);
 }
 
 static guint
@@ -326,9 +356,14 @@ get_number (CamelMultipart *multipart)
 guint
 camel_multipart_get_number (CamelMultipart *multipart)
 {
+	CamelMultipartClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), 0);
 
-	return CMP_CLASS (multipart)->get_number (multipart);
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_val_if_fail (class->get_number != NULL, 0);
+
+	return class->get_number (multipart);
 }
 
 static void
@@ -383,11 +418,17 @@ set_boundary (CamelMultipart *multipart, const gchar *boundary)
  * be used.
  **/
 void
-camel_multipart_set_boundary (CamelMultipart *multipart, const gchar *boundary)
+camel_multipart_set_boundary (CamelMultipart *multipart,
+                              const gchar *boundary)
 {
+	CamelMultipartClass *class;
+
 	g_return_if_fail (CAMEL_IS_MULTIPART (multipart));
 
-	CMP_CLASS (multipart)->set_boundary (multipart, boundary);
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_if_fail (class->set_boundary != NULL);
+
+	class->set_boundary (multipart, boundary);
 }
 
 static const gchar *
@@ -408,7 +449,14 @@ get_boundary (CamelMultipart *multipart)
 const gchar *
 camel_multipart_get_boundary (CamelMultipart *multipart)
 {
-	return CMP_CLASS (multipart)->get_boundary (multipart);
+	CamelMultipartClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_MULTIPART (multipart), NULL);
+
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_val_if_fail (class->get_boundary != NULL, NULL);
+
+	return class->get_boundary (multipart);
 }
 
 static gboolean
@@ -418,7 +466,7 @@ is_offline (CamelDataWrapper *data_wrapper)
 	GList *node;
 	CamelDataWrapper *part;
 
-	if (parent_class->is_offline (data_wrapper))
+	if (CAMEL_DATA_WRAPPER_CLASS (parent_class)->is_offline (data_wrapper))
 		return TRUE;
 	for (node = multipart->parts; node; node = node->next) {
 		part = node->data;
@@ -559,7 +607,7 @@ construct_from_parser(CamelMultipart *multipart, struct _CamelMimeParser *mp)
 		bodypart = camel_mime_part_new();
 		camel_mime_part_construct_from_parser(bodypart, mp);
 		camel_multipart_add_part(multipart, bodypart);
-		camel_object_unref((CamelObject *)bodypart);
+		g_object_unref (bodypart);
 	}
 
 	/* these are only return valid data in the MULTIPART_END state */
@@ -584,9 +632,16 @@ construct_from_parser(CamelMultipart *multipart, struct _CamelMimeParser *mp)
  * Returns: %0 on success or %-1 on fail
  **/
 gint
-camel_multipart_construct_from_parser(CamelMultipart *multipart, struct _CamelMimeParser *mp)
+camel_multipart_construct_from_parser (CamelMultipart *multipart,
+                                       CamelMimeParser *mp)
 {
-	g_return_val_if_fail(CAMEL_IS_MULTIPART(multipart), -1);
+	CamelMultipartClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_MULTIPART(multipart), -1);
+	g_return_val_if_fail (CAMEL_IS_MIME_PARSER (mp), -1);
+
+	class = CAMEL_MULTIPART_GET_CLASS (multipart);
+	g_return_val_if_fail (class->construct_from_parser != NULL, -1);
 
-	return CMP_CLASS(multipart)->construct_from_parser(multipart, mp);
+	return class->construct_from_parser(multipart, mp);
 }
diff --git a/camel/camel-multipart.h b/camel/camel-multipart.h
index a711453..8e9d6cc 100644
--- a/camel/camel-multipart.h
+++ b/camel/camel-multipart.h
@@ -23,30 +23,50 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_MULTIPART_H
-#define CAMEL_MULTIPART_H 1
+#define CAMEL_MULTIPART_H
 
 #include <camel/camel-data-wrapper.h>
 
-#define CAMEL_MULTIPART_TYPE     (camel_multipart_get_type ())
-#define CAMEL_MULTIPART(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MULTIPART_TYPE, CamelMultipart))
-#define CAMEL_MULTIPART_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MULTIPART_TYPE, CamelMultipartClass))
-#define CAMEL_IS_MULTIPART(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MULTIPART_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MULTIPART \
+	(camel_multipart_get_type ())
+#define CAMEL_MULTIPART(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MULTIPART, CamelMultipart))
+#define CAMEL_MULTIPART_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MULTIPART, CamelMultipartClass))
+#define CAMEL_IS_MULTIPART(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MULTIPART))
+#define CAMEL_IS_MULTIPART_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MULTIPART))
+#define CAMEL_MULTIPART_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MULTIPART, CamelMultipartClass))
 
 G_BEGIN_DECLS
 
 struct _CamelMimeParser;
 
-struct _CamelMultipart
-{
-	CamelDataWrapper parent_object;
+typedef struct _CamelMultipart CamelMultipart;
+typedef struct _CamelMultipartClass CamelMultipartClass;
+
+struct _CamelMultipart {
+	CamelDataWrapper parent;
 
 	GList *parts;
 	gchar *preface;
 	gchar *postface;
 };
 
-typedef struct {
+struct _CamelMultipartClass {
 	CamelDataWrapperClass parent_class;
 
 	/* Virtual methods */
@@ -61,11 +81,9 @@ typedef struct {
 
 	gint (*construct_from_parser)(CamelMultipart *, struct _CamelMimeParser *);
 	/*int (*construct_from_stream)(CamelMultipart *, CamelStream *);*/
+};
 
-} CamelMultipartClass;
-
-/* Standard Camel function */
-CamelType camel_multipart_get_type (void);
+GType camel_multipart_get_type (void);
 
 /* public methods */
 CamelMultipart *    camel_multipart_new            (void);
diff --git a/camel/camel-net-utils-win32.h b/camel/camel-net-utils-win32.h
index a4f21f5..b177de5 100644
--- a/camel/camel-net-utils-win32.h
+++ b/camel/camel-net-utils-win32.h
@@ -3,6 +3,11 @@
  * This file is part of the w64 mingw-runtime package.
  * No warranty is given; refer to the file DISCLAIMER within this package.
  */
+
+#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_
 
diff --git a/camel/camel-net-utils.c b/camel/camel-net-utils.c
index e7ba45e..dc64948 100644
--- a/camel/camel-net-utils.c
+++ b/camel/camel-net-utils.c
@@ -29,7 +29,6 @@
 #include <pthread.h>
 #include <stdio.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
diff --git a/camel/camel-net-utils.h b/camel/camel-net-utils.h
index 10e8719..85e2469 100644
--- a/camel/camel-net-utils.h
+++ b/camel/camel-net-utils.h
@@ -20,8 +20,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_NET_UTILS_H
-#define CAMEL_NET_UTILS_H 1
+#define CAMEL_NET_UTILS_H
 
 #include <sys/types.h>
 
diff --git a/camel/camel-news-address.c b/camel/camel-news-address.c
index 3680f8e..530a732 100644
--- a/camel/camel-news-address.c
+++ b/camel/camel-news-address.c
@@ -20,30 +20,20 @@
 
 #include "camel-news-address.h"
 
-static void camel_news_address_class_init (CamelNewsAddressClass *klass);
-
-static CamelAddressClass *camel_news_address_parent;
-
-static void
-camel_news_address_class_init (CamelNewsAddressClass *klass)
-{
-	camel_news_address_parent = CAMEL_ADDRESS_CLASS (camel_type_get_global_classfuncs (camel_address_get_type ()));
-}
-
-CamelType
+GType
 camel_news_address_get_type (void)
 {
-	static guint type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_address_get_type (), "CamelNewsAddress",
-					    sizeof (CamelNewsAddress),
-					    sizeof (CamelNewsAddressClass),
-					    (CamelObjectClassInitFunc) camel_news_address_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
+	static guint type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_ADDRESS,
+			"CamelNewsAddress",
+			sizeof (CamelNewsAddressClass),
+			(GClassInitFunc) NULL,
+			sizeof (CamelNewsAddress),
+			(GInstanceInitFunc) NULL,
+			0);
 
 	return type;
 }
@@ -58,6 +48,5 @@ camel_news_address_get_type (void)
 CamelNewsAddress *
 camel_news_address_new (void)
 {
-	CamelNewsAddress *new = CAMEL_NEWS_ADDRESS ( camel_object_new (camel_news_address_get_type ()));
-	return new;
+	return g_object_new (CAMEL_TYPE_NEWS_ADDRESS, NULL);
 }
diff --git a/camel/camel-news-address.h b/camel/camel-news-address.h
index 5f6b90c..7b756eb 100644
--- a/camel/camel-news-address.h
+++ b/camel/camel-news-address.h
@@ -19,36 +19,56 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
-#ifndef _CAMEL_NEWS_ADDRESS_H
-#define _CAMEL_NEWS_ADDRESS_H
+#ifndef CAMEL_NEWS_ADDRESS_H
+#define CAMEL_NEWS_ADDRESS_H
 
 #include <camel/camel-address.h>
 
-#define CAMEL_NEWS_ADDRESS(obj)         CAMEL_CHECK_CAST (obj, camel_news_address_get_type (), CamelNewsAddress)
-#define CAMEL_NEWS_ADDRESS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_news_address_get_type (), CamelNewsAddressClass)
-#define CAMEL_IS_NEWS_ADDRESS(obj)      CAMEL_CHECK_TYPE (obj, camel_news_address_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_NEWS_ADDRESS \
+	(camel_news_address_get_type ())
+#define CAMEL_NEWS_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_NEWS_ADDRESS, CamelNewsAddress))
+#define CAMEL_NEWS_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_NEWS_ADDRESS, CamelNewsAddressClass))
+#define CAMEL_IS_NEWS_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_NEWS_ADDRESS))
+#define CAMEL_IS_NEWS_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_NEWS_ADDRESS))
+#define CAMEL_NEWS_ADDRESS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_NEWS_ADDRESS, CamelNewsAddressClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelNewsAddress CamelNewsAddress;
 typedef struct _CamelNewsAddressClass CamelNewsAddressClass;
+typedef struct _CamelNewsAddressPrivate CamelNewsAddressPrivate;
 
 struct _CamelNewsAddress {
 	CamelAddress parent;
-
-	struct _CamelNewsAddressPrivate *priv;
+	CamelNewsAddressPrivate *priv;
 };
 
 struct _CamelNewsAddressClass {
 	CamelAddressClass parent_class;
 };
 
-CamelType		camel_news_address_get_type	(void);
+GType		camel_news_address_get_type	(void);
 CamelNewsAddress      *camel_news_address_new	(void);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_NEWS_ADDRESS_H */
+#endif /* CAMEL_NEWS_ADDRESS_H */
 
 #endif /* CAMEL_DISABLE_DEPRECATED */
diff --git a/camel/camel-nntp-address.c b/camel/camel-nntp-address.c
index 7f489d6..46e30c3 100644
--- a/camel/camel-nntp-address.c
+++ b/camel/camel-nntp-address.c
@@ -26,94 +26,55 @@
 
 #define d(x)
 
-static gint    nntp_decode		(CamelAddress *, const gchar *raw);
-static gchar * nntp_encode		(CamelAddress *);
-static gint    nntp_cat		(CamelAddress *dest, const CamelAddress *source);
-static void   nntp_remove		(CamelAddress *, gint index);
+static gint    nntp_address_decode		(CamelAddress *, const gchar *raw);
+static gchar * nntp_address_encode		(CamelAddress *);
+static gint    nntp_address_cat		(CamelAddress *dest, CamelAddress *source);
+static void   nntp_address_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;
+static gpointer parent_class;
 
 struct _address {
 	gchar *name;
 	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 +84,64 @@ nntp_encode(CamelAddress *a)
 }
 
 static gint
-nntp_cat (CamelAddress *dest, const 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
+nntp_address_class_init(CamelNNTPAddressClass *class)
+{
+	CamelAddressClass *address_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	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;
+}
+
+GType
+camel_nntp_address_get_type(void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_ADDRESS,
+			"CamelNNTPAddress",
+			sizeof (CamelNNTPAddressClass),
+			(GClassInitFunc) nntp_address_class_init,
+			sizeof (CamelNNTPAddress),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	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 g_object_new (CAMEL_TYPE_NNTP_ADDRESS, NULL);
 }
 
 /**
diff --git a/camel/camel-nntp-address.h b/camel/camel-nntp-address.h
index 2dde5d8..569e82b 100644
--- a/camel/camel-nntp-address.h
+++ b/camel/camel-nntp-address.h
@@ -19,31 +19,50 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_NNTP_ADDRESS_H
-#define _CAMEL_NNTP_ADDRESS_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_NNTP_ADDRESS_H
+#define CAMEL_NNTP_ADDRESS_H
 
 #include <camel/camel-address.h>
 
-#define CAMEL_NNTP_ADDRESS(obj)         CAMEL_CHECK_CAST (obj, camel_nntp_address_get_type (), CamelNNTPAddress)
-#define CAMEL_NNTP_ADDRESS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_nntp_address_get_type (), CamelNNTPAddressClass)
-#define CAMEL_IS_NNTP_ADDRESS(obj)      CAMEL_CHECK_TYPE (obj, camel_nntp_address_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_NNTP_ADDRESS \
+	(camel_nntp_address_get_type ())
+#define CAMEL_NNTP_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_NNTP_ADDRESS, CamelNNTPAddress))
+#define CAMEL_NNTP_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_NNTP_ADDRESS, CamelNNTPAddressClass))
+#define CAMEL_IS_NNTP_ADDRESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_NNTP_ADDRESS))
+#define CAMEL_IS_NNTP_ADDRESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_NNTP_ADDRESS))
+#define CAMEL_NNTP_ADDRESS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_NTTP_ADDRESS, CamelNNTPAddressClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelNNTPAddress CamelNNTPAddress;
 typedef struct _CamelNNTPAddressClass CamelNNTPAddressClass;
+typedef struct _CamelNNTPAddressPrivate CamelNNTPAddressPrivate;
 
 struct _CamelNNTPAddress {
 	CamelAddress parent;
-
-	struct _CamelNNTPAddressPrivate *priv;
+	CamelNNTPAddressPrivate *priv;
 };
 
 struct _CamelNNTPAddressClass {
 	CamelAddressClass parent_class;
 };
 
-CamelType		camel_nntp_address_get_type	(void);
+GType		camel_nntp_address_get_type	(void);
 CamelNNTPAddress   *camel_nntp_address_new	(void);
 
 gint			camel_nntp_address_add	(CamelNNTPAddress *a, const gchar *name);
@@ -51,4 +70,4 @@ gboolean		camel_nntp_address_get	(const CamelNNTPAddress *a, gint index, const g
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_NNTP_ADDRESS_H */
+#endif /* CAMEL_NNTP_ADDRESS_H */
diff --git a/camel/camel-object-bag.c b/camel/camel-object-bag.c
new file mode 100644
index 0000000..79ca4a2
--- /dev/null
+++ b/camel/camel-object-bag.c
@@ -0,0 +1,525 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "camel-object-bag.h"
+
+#include <glib-object.h>
+
+typedef struct _KeyReservation KeyReservation;
+
+struct _KeyReservation {
+	gpointer key;
+	gint waiters;
+	GThread *owner;
+	GCond *cond;
+};
+
+struct _CamelObjectBag {
+	GHashTable *key_table;
+	GHashTable *object_table;
+	GEqualFunc key_equal_func;
+	CamelCopyFunc key_copy_func;
+	GFreeFunc key_free_func;
+	GSList *reserved;  /* list of KeyReservations */
+	GMutex *mutex;
+};
+
+static KeyReservation *
+key_reservation_new (CamelObjectBag *bag,
+                     gconstpointer key)
+{
+	KeyReservation *reservation;
+
+	reservation = g_slice_new0 (KeyReservation);
+	reservation->key = bag->key_copy_func (key);
+	reservation->owner = g_thread_self ();
+	reservation->cond = g_cond_new ();
+
+	bag->reserved = g_slist_prepend (bag->reserved, reservation);
+
+	return reservation;
+}
+
+static KeyReservation *
+key_reservation_lookup (CamelObjectBag *bag,
+                        gconstpointer key)
+{
+	GSList *iter;
+
+	/* XXX Might be easier to use a GHashTable for reservations. */
+	for (iter = bag->reserved; iter != NULL; iter = iter->next) {
+		KeyReservation *reservation = iter->data;
+		if (bag->key_equal_func (reservation->key, key))
+			return reservation;
+	}
+
+	return NULL;
+}
+
+static void
+key_reservation_free (CamelObjectBag *bag,
+                      KeyReservation *reservation)
+{
+	/* Make sure the reservation is actually in the object bag. */
+	g_return_if_fail (key_reservation_lookup (bag, reservation->key) != NULL);
+
+	bag->reserved = g_slist_remove (bag->reserved, reservation);
+
+	bag->key_free_func (reservation->key);
+	g_cond_free (reservation->cond);
+	g_slice_free (KeyReservation, reservation);
+}
+
+static void
+object_bag_notify (CamelObjectBag *bag,
+                   GObject *where_the_object_was)
+{
+	gpointer key;
+
+	g_mutex_lock (bag->mutex);
+
+	key = g_hash_table_lookup (bag->key_table, where_the_object_was);
+	if (key != NULL) {
+		g_hash_table_remove (bag->key_table, where_the_object_was);
+		g_hash_table_remove (bag->object_table, key);
+	}
+
+	g_mutex_unlock (bag->mutex);
+}
+
+static void
+object_bag_weak_unref (gpointer key,
+                       GObject *object,
+                       CamelObjectBag *bag)
+{
+	g_object_weak_unref (object, (GWeakNotify) object_bag_notify, bag);
+}
+
+static void
+object_bag_unreserve (CamelObjectBag *bag,
+                      gconstpointer key)
+{
+	KeyReservation *reservation;
+
+	reservation = key_reservation_lookup (bag, key);
+	g_return_if_fail (reservation != NULL);
+	g_return_if_fail (reservation->owner == g_thread_self ());
+
+	if (reservation->waiters > 0) {
+		reservation->owner = NULL;
+		g_cond_signal (reservation->cond);
+	} else
+		key_reservation_free (bag, reservation);
+}
+
+/**
+ * camel_object_bag_new:
+ * @key_hash_func: a hashing function for keys
+ * @key_equal_func: a comparison function for keys
+ * @key_copy_func: a function to copy keys
+ * @key_free_func: a function to free keys
+ *
+ * Returns a new object bag.  Object bags are keyed hash tables of objects
+ * that can be updated atomically using transaction semantics.  Use
+ * camel_object_bag_destroy() to free the object bag.
+ *
+ * Returns: a newly-allocated #CamelObjectBag
+ **/
+CamelObjectBag *
+camel_object_bag_new (GHashFunc key_hash_func,
+                      GEqualFunc key_equal_func,
+                      CamelCopyFunc key_copy_func,
+                      GFreeFunc key_free_func)
+{
+	CamelObjectBag *bag;
+	GHashTable *key_table;
+	GHashTable *object_table;
+
+	g_return_val_if_fail (key_hash_func != NULL, NULL);
+	g_return_val_if_fail (key_equal_func != NULL, NULL);
+	g_return_val_if_fail (key_copy_func != NULL, NULL);
+	g_return_val_if_fail (key_free_func != NULL, NULL);
+
+	/* Each key is shared between both hash tables, so only one
+	 * table needs to be responsible for destroying keys. */
+
+	key_table = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+	object_table = g_hash_table_new_full (
+		key_hash_func, key_equal_func,
+		(GDestroyNotify) key_free_func,
+		(GDestroyNotify) NULL);
+
+	bag = g_slice_new0 (CamelObjectBag);
+	bag->key_table = key_table;
+	bag->object_table = object_table;
+	bag->key_equal_func = key_equal_func;
+	bag->key_copy_func = key_copy_func;
+	bag->key_free_func = key_free_func;
+	bag->mutex = g_mutex_new ();
+
+	return bag;
+}
+
+/**
+ * camel_object_bag_get:
+ * @bag: a #CamelObjectBag
+ * @key: a key
+ *
+ * Lookup an object by @key.  If the key is currently reserved, the function
+ * will block until another thread commits or aborts the reservation.  The
+ * caller owns the reference to the returned object.  Use g_object_unref ()
+ * to unreference it.
+ *
+ * Returns: the object corresponding to @key, or %NULL if not found
+ **/
+gpointer
+camel_object_bag_get (CamelObjectBag *bag,
+                      gconstpointer key)
+{
+	KeyReservation *reservation;
+	gpointer object;
+
+	g_return_val_if_fail (bag != NULL, NULL);
+	g_return_val_if_fail (key != NULL, NULL);
+
+	g_mutex_lock (bag->mutex);
+
+	/* Look for the key in the bag. */
+	object = g_hash_table_lookup (bag->object_table, key);
+	if (object != NULL) {
+		g_object_ref (object);
+		g_mutex_unlock (bag->mutex);
+		return object;
+	}
+
+	/* Check if the key has been reserved. */
+	reservation = key_reservation_lookup (bag, key);
+	if (reservation == NULL) {
+		/* No such key, so return NULL. */
+		g_mutex_unlock (bag->mutex);
+		return NULL;
+	}
+
+	/* Wait for the key to be unreserved. */
+	reservation->waiters++;
+	while (reservation->owner != NULL)
+		g_cond_wait (reservation->cond, bag->mutex);
+	reservation->waiters--;
+
+	/* Check if an object was added by another thread. */
+	object = g_hash_table_lookup (bag->object_table, key);
+	if (object != NULL)
+		g_object_ref (object);
+
+	/* We're not reserving it. */
+	reservation->owner = g_thread_self ();
+	object_bag_unreserve (bag, key);
+
+	g_mutex_unlock (bag->mutex);
+
+	return object;
+}
+
+/**
+ * camel_object_bag_peek:
+ * @bag: a #CamelObjectBag
+ * @key: an unreserved key
+ *
+ * Returns the object for @key in @bag, ignoring any reservations.  If it
+ * isn't committed, then it isn't considered.  This should only be used
+ * where reliable transactional-based state is not required.
+ *
+ * Unlink other "peek" operations, the caller owns the returned object
+ * reference.  Use g_object_unref () to unreference it.
+ *
+ * Returns: the object for @key, or %NULL if @key is reserved or not found
+ **/
+gpointer
+camel_object_bag_peek (CamelObjectBag *bag,
+                       gconstpointer key)
+{
+	gpointer object;
+
+	g_return_val_if_fail (bag != NULL, NULL);
+	g_return_val_if_fail (key != NULL, NULL);
+
+	g_mutex_lock (bag->mutex);
+
+	object = g_hash_table_lookup (bag->object_table, key);
+	if (object != NULL)
+		g_object_ref (object);
+
+	g_mutex_unlock (bag->mutex);
+
+	return object;
+}
+
+/**
+ * camel_object_bag_reserve:
+ * @bag: a #CamelObjectBag
+ * @key: the key to reserve
+ *
+ * Reserves @key in @bag.  If @key is already reserved in another thread,
+ * then wait until the reservation has been committed.
+ *
+ * After reserving @key, you either get a reference to the object
+ * corresponding to @key (similar to camel_object_bag_get()) or you get
+ * %NULL, signifying that you MUST call either camel_object_bag_add() or
+ * camel_object_bag_abort().
+ *
+ * Returns: the object for @key, or %NULL if @key is not found
+ **/
+gpointer
+camel_object_bag_reserve (CamelObjectBag *bag,
+                          gconstpointer key)
+{
+	KeyReservation *reservation;
+	gpointer object;
+
+	g_return_val_if_fail (bag != NULL, NULL);
+	g_return_val_if_fail (key != NULL, NULL);
+
+	g_mutex_lock (bag->mutex);
+
+	/* If object for key already exists, return it immediately. */
+	object = g_hash_table_lookup (bag->object_table, key);
+	if (object != NULL) {
+		g_object_ref (object);
+		g_mutex_unlock (bag->mutex);
+		return object;
+	}
+
+	/* If no such key exists in the bag, create a reservation. */
+	reservation = key_reservation_lookup (bag, key);
+	if (reservation == NULL) {
+		reservation = key_reservation_new (bag, key);
+		g_mutex_unlock (bag->mutex);
+		return NULL;
+	}
+
+	/* Wait for the reservation to be committed or aborted. */
+	reservation->waiters++;
+	while (reservation->owner != NULL)
+		g_cond_wait (reservation->cond, bag->mutex);
+	reservation->owner = g_thread_self ();
+	reservation->waiters--;
+
+	/* Check if the object was added by another thread. */
+	object = g_hash_table_lookup (bag->object_table, key);
+	if (object != NULL) {
+		/* We have an object; no need to reserve the key. */
+		object_bag_unreserve (bag, key);
+		g_object_ref (object);
+	}
+
+	g_mutex_unlock (bag->mutex);
+
+	return object;
+}
+
+/**
+ * camel_object_bag_add:
+ * @bag: a #CamelObjectBag
+ * @key: a reserved key
+ * @object: a #GObject
+ *
+ * Adds @object to @bag.  The @key MUST have been previously reserved using
+ * camel_object_bag_reserve().
+ **/
+void
+camel_object_bag_add (CamelObjectBag *bag,
+                      gconstpointer key,
+                      gpointer object)
+{
+	g_return_if_fail (bag != NULL);
+	g_return_if_fail (key != NULL);
+	g_return_if_fail (G_IS_OBJECT (object));
+
+	g_mutex_lock (bag->mutex);
+
+	if (g_hash_table_lookup (bag->key_table, object) == NULL) {
+		gpointer copied_key;
+
+		copied_key = bag->key_copy_func (key);
+		g_hash_table_insert (bag->key_table, object, copied_key);
+		g_hash_table_insert (bag->object_table, copied_key, object);
+		object_bag_unreserve (bag, key);
+
+		g_object_weak_ref (
+			G_OBJECT (object), (GWeakNotify)
+			object_bag_notify, bag);
+	}
+
+	g_mutex_unlock (bag->mutex);
+}
+
+/**
+ * camel_object_bag_abort:
+ * @bag: a #CamelObjectBag
+ * @key: a reserved key
+ *
+ * Aborts a key reservation.
+ **/
+void
+camel_object_bag_abort (CamelObjectBag *bag,
+                        gconstpointer key)
+{
+	g_return_if_fail (bag != NULL);
+	g_return_if_fail (key != NULL);
+
+	g_mutex_lock (bag->mutex);
+
+	object_bag_unreserve (bag, key);
+
+	g_mutex_unlock (bag->mutex);
+}
+
+/**
+ * camel_object_bag_rekey:
+ * @bag: a #CamelObjectBag
+ * @object: a #GObject
+ * @new_key: a new key for @object
+ *
+ * Changes the key for @object to @new_key, atomically.
+ *
+ * It is considered a programming error if @object is not found in @bag.
+ * In such case the function will emit a terminal warning and return.
+ **/
+void
+camel_object_bag_rekey (CamelObjectBag *bag,
+                        gpointer object,
+                        gconstpointer new_key)
+{
+	gpointer key;
+
+	g_return_if_fail (bag != NULL);
+	g_return_if_fail (G_IS_OBJECT (object));
+	g_return_if_fail (new_key != NULL);
+
+	g_mutex_lock (bag->mutex);
+
+	key = g_hash_table_lookup (bag->key_table, object);
+	if (key != NULL) {
+		/* Remove the old key. */
+		g_hash_table_remove (bag->object_table, key);
+		g_hash_table_remove (bag->key_table, object);
+
+		/* Insert the new key. */
+		key = bag->key_copy_func (new_key);
+		g_hash_table_insert (bag->object_table, key, object);
+		g_hash_table_insert (bag->key_table, object, key);
+	} else
+		g_warn_if_reached ();
+
+	g_mutex_unlock (bag->mutex);
+}
+
+/**
+ * camel_object_bag_list:
+ * @bag: a #CamelObjectBag
+ *
+ * Returns a #GPtrArray of all the objects in the bag.  The caller owns
+ * both the array and the object references, so to free the array use:
+ *
+ * <informalexample>
+ *   <programlisting>
+ *     g_ptr_array_foreach (array, g_object_unref, NULL);
+ *     g_ptr_array_free (array, TRUE);
+ *   </programlisting>
+ * </informalexample>
+ *
+ * Returns: an array of objects in @bag
+ **/
+GPtrArray *
+camel_object_bag_list (CamelObjectBag *bag)
+{
+	GPtrArray *array;
+	GList *values;
+
+	g_return_val_if_fail (bag != NULL, NULL);
+
+	/* XXX Too bad we're not returning a GList; this would be trivial. */
+
+	array = g_ptr_array_new ();
+
+	g_mutex_lock (bag->mutex);
+
+	values = g_hash_table_get_values (bag->object_table);
+	while (values != NULL) {
+		g_ptr_array_add (array, g_object_ref (values->data));
+		values = g_list_delete_link (values, values);
+	}
+
+	g_mutex_unlock (bag->mutex);
+
+	return array;
+}
+
+/**
+ * camel_object_bag_remove:
+ * @bag: a #CamelObjectBag
+ * @object: a #GObject
+ *
+ * Removes @object from @bag.
+ **/
+void
+camel_object_bag_remove (CamelObjectBag *bag,
+                         gpointer object)
+{
+	gpointer key;
+
+	g_return_if_fail (bag != NULL);
+	g_return_if_fail (G_IS_OBJECT (object));
+
+	g_mutex_lock (bag->mutex);
+
+	key = g_hash_table_lookup (bag->key_table, object);
+	if (key != NULL) {
+		object_bag_weak_unref (key, object, bag);
+		g_hash_table_remove (bag->key_table, object);
+		g_hash_table_remove (bag->object_table, key);
+	}
+
+	g_mutex_unlock (bag->mutex);
+}
+
+/**
+ * camel_object_bag_destroy:
+ * @bag: a #CamelObjectBag
+ *
+ * Frees @bag.  As a precaution, the function will emit a warning to standard
+ * error and return without freeing @bag if @bag still has reserved keys.
+ **/
+void
+camel_object_bag_destroy (CamelObjectBag *bag)
+{
+	g_return_if_fail (bag != NULL);
+	g_return_if_fail (bag->reserved == NULL);
+
+	/* Drop remaining weak references. */
+	g_hash_table_foreach (
+		bag->object_table, (GHFunc)
+		object_bag_weak_unref, bag);
+
+	g_hash_table_destroy (bag->key_table);
+	g_hash_table_destroy (bag->object_table);
+	g_mutex_free (bag->mutex);
+	g_slice_free (CamelObjectBag, bag);
+}
diff --git a/camel/camel-object-bag.h b/camel/camel-object-bag.h
new file mode 100644
index 0000000..97dd4fb
--- /dev/null
+++ b/camel/camel-object-bag.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+/* Manages bags of weakly-referenced GObjects. */
+
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_OBJECT_BAG_H
+#define CAMEL_OBJECT_BAG_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _CamelObjectBag CamelObjectBag;
+typedef gpointer (*CamelCopyFunc) (gconstpointer object);
+
+CamelObjectBag *camel_object_bag_new		(GHashFunc key_hash_func,
+						 GEqualFunc key_equal_func,
+						 CamelCopyFunc key_copy_func,
+						 GFreeFunc key_free_func);
+gpointer	camel_object_bag_get		(CamelObjectBag *bag,
+						 gconstpointer key);
+gpointer	camel_object_bag_peek		(CamelObjectBag *bag,
+						 gconstpointer key);
+gpointer	camel_object_bag_reserve	(CamelObjectBag *bag,
+						 gconstpointer key);
+void		camel_object_bag_add		(CamelObjectBag *bag,
+						 gconstpointer key,
+						 gpointer object);
+void		camel_object_bag_abort		(CamelObjectBag *bag,
+						 gconstpointer key);
+void		camel_object_bag_rekey		(CamelObjectBag *bag,
+						 gpointer object,
+						 gconstpointer new_key);
+GPtrArray *	camel_object_bag_list		(CamelObjectBag *bag);
+void		camel_object_bag_remove		(CamelObjectBag *bag,
+						 gpointer object);
+void		camel_object_bag_destroy	(CamelObjectBag *bag);
+
+G_END_DECLS
+
+#endif /* CAMEL_OBJECT_BAG_H */
diff --git a/camel/camel-object.c b/camel/camel-object.c
index 548c63e..61d6675 100644
--- a/camel/camel-object.c
+++ b/camel/camel-object.c
@@ -29,26 +29,18 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
 #include <libedataserver/e-data-server-util.h>
 
 #include "camel-file-utils.h"
-#include "camel-list-utils.h"
 #include "camel-object.h"
 
 #define d(x)
 #define b(x)			/* object bag */
 #define h(x)			/* hooks */
 
-/* I just mashed the keyboard for these... */
-#define CAMEL_OBJECT_MAGIC		 0x77A344ED
-#define CAMEL_OBJECT_CLASS_MAGIC	 0xEE26A997
-#define CAMEL_INTERFACE_MAGIC	 0xBCE137A7
-#define CAMEL_OBJECT_FINALISED_MAGIC       0x84AC365F
-#define CAMEL_OBJECT_CLASS_FINALISED_MAGIC 0x7621ABCD
-#define CAMEL_INTERFACE_FINALISED_MAGIC    0x7CB2FE71
+static gpointer parent_class;
 
 /* ** Quickie type system ************************************************* */
 
@@ -87,29 +79,6 @@ typedef struct _CamelHookPair
 	gpointer data;
 } CamelHookPair;
 
-struct _CamelObjectBagKey {
-	struct _CamelObjectBagKey *next;
-
-	gpointer key;		/* the key reserved */
-	gint waiters;		/* count of threads waiting for key */
-	pthread_t owner;	/* the thread that has reserved the bag for a new entry */
-	gint have_owner;
-	GCond *cond;
-};
-
-struct _CamelObjectBag {
-	GHashTable *object_table; /* object by key */
-	GHashTable *key_table;	/* key by object */
-	GEqualFunc equal_key;
-	CamelCopyFunc copy_key;
-	GFreeFunc free_key;
-
-	struct _CamelObjectBagKey *reserved;
-};
-
-/* used to tag a bag hookpair */
-static const gchar bag_name[] = "object:bag";
-
 /* meta-data stuff */
 static void co_metadata_free(CamelObject *obj, CamelObjectMeta *meta);
 static CamelObjectMeta *co_metadata_get(CamelObject *obj);
@@ -118,39 +87,20 @@ static CamelHookPair *co_metadata_pair(CamelObject *obj, gint create);
 static const gchar meta_name[] = "object:meta";
 #define CAMEL_OBJECT_STATE_FILE_MAGIC "CLMD"
 
-/* interface stuff */
-static const gchar interface_name[] = "object:interface";
-
 /* ********************************************************************** */
 
 static CamelHookList *camel_object_get_hooks(CamelObject *o);
 static void camel_object_free_hooks(CamelObject *o);
-static void camel_object_bag_remove_unlocked(CamelObjectBag *inbag, CamelObject *o, CamelHookList *hooks);
 
 #define camel_object_unget_hooks(o) \
 	(g_static_rec_mutex_unlock(&CAMEL_OBJECT(o)->hooks->lock))
 
 /* ********************************************************************** */
 
-/* type-lock must be recursive, for atomically creating classes */
-static GStaticRecMutex type_lock = G_STATIC_REC_MUTEX_INIT;
-/* ref-lock must be global :-(  for object bags to work */
-static GMutex *ref_lock;
-
-static GHashTable *type_table;
-
-/* fundamental types are accessed via global */
-CamelType camel_object_type = CAMEL_INVALID_TYPE;
-CamelType camel_interface_type = CAMEL_INVALID_TYPE;
-
 #define P_LOCK(l) (pthread_mutex_lock(&l))
 #define P_UNLOCK(l) (pthread_mutex_unlock(&l))
 #define CLASS_LOCK(k) (g_mutex_lock((((CamelObjectClass *)k)->lock)))
 #define CLASS_UNLOCK(k) (g_mutex_unlock((((CamelObjectClass *)k)->lock)))
-#define REF_LOCK() (g_mutex_lock(ref_lock))
-#define REF_UNLOCK() (g_mutex_unlock(ref_lock))
-#define TYPE_LOCK() (g_static_rec_mutex_lock(&type_lock))
-#define TYPE_UNLOCK() (g_static_rec_mutex_unlock(&type_lock))
 
 static struct _CamelHookPair *
 pair_alloc(void)
@@ -188,54 +138,19 @@ hooks_free(CamelHookList *hooks)
 	g_slice_free (CamelHookList, hooks);
 }
 
-/* not checked locked, who cares, only required for people that want to redefine root objects */
-void
-camel_type_init(void)
-{
-	static gint init = FALSE;
-
-	if (init)
-		return;
-
-	init = TRUE;
-	type_table = g_hash_table_new(NULL, NULL);
-	ref_lock = g_mutex_new();
-}
-
 /* ************************************************************************ */
 
 /* CamelObject base methods */
 
-/* Should this return the object to the caller? */
-static void
-cobject_init(CamelObject *o, CamelObjectClass *klass)
-{
-	o->klass = klass;
-	o->magic = CAMEL_OBJECT_MAGIC;
-	o->ref_count = 1;
-	o->flags = 0;
-}
-
-static void
-cobject_finalise(CamelObject *o)
-{
-	/*printf("%p: finalise %s\n", o, o->klass->name);*/
-
-	if (o->ref_count == 0)
-		return;
-
-	camel_object_free_hooks(o);
-
-	o->magic = CAMEL_OBJECT_FINALISED_MAGIC;
-	o->klass = NULL;
-}
-
 static gint
 cobject_getv(CamelObject *o, CamelException *ex, CamelArgGetV *args)
 {
+	CamelObjectClass *class;
 	gint i;
 	guint32 tag;
 
+	class = CAMEL_OBJECT_GET_CLASS (o);
+
 	for (i=0;i<args->argc;i++) {
 		CamelArgGet *arg = &args->argv[i];
 
@@ -243,7 +158,7 @@ cobject_getv(CamelObject *o, CamelException *ex, CamelArgGetV *args)
 
 		switch (tag & CAMEL_ARG_TAG) {
 		case CAMEL_OBJECT_ARG_DESCRIPTION:
-			*arg->ca_str = (gchar *)o->klass->name;
+			*arg->ca_str = (gchar *) G_OBJECT_CLASS_NAME (class);
 			break;
 		case CAMEL_OBJECT_ARG_METADATA:
 			*arg->ca_ptr = co_metadata_get(o);
@@ -587,557 +502,70 @@ abort:
 }
 
 static void
-cobject_class_init(CamelObjectClass *klass)
-{
-	klass->magic = CAMEL_OBJECT_CLASS_MAGIC;
-
-	klass->getv = cobject_getv;
-	klass->setv = cobject_setv;
-	klass->free = cobject_free;
-
-	klass->meta_get = cobject_meta_get;
-	klass->meta_set = cobject_meta_set;
-	klass->state_read = cobject_state_read;
-	klass->state_write = cobject_state_write;
-
-	camel_object_class_add_event(klass, "finalize", NULL);
-	camel_object_class_add_event(klass, "meta_changed", NULL);
-}
-
-static void
-cobject_class_finalise(CamelObjectClass * klass)
-{
-	klass->magic = CAMEL_OBJECT_CLASS_FINALISED_MAGIC;
-
-	g_free(klass);
-}
-
-/* CamelInterface base methods */
-
-G_GNUC_NORETURN static void
-cinterface_init(CamelObject *o, CamelObjectClass *klass)
-{
-	g_error("Cannot instantiate interfaces, trying to instantiate '%s'", klass->name);
-}
-
-static gint
-cinterface_getv(CamelObject *o, CamelException *ex, CamelArgGetV *args)
-{
-	return 0;
-}
-
-static gint
-cinterface_setv(CamelObject *o, CamelException *ex, CamelArgV *args)
-{
-	return 0;
-}
-
-static void
-cinterface_free(CamelObject *o, guint32 tag, gpointer value)
-{
-	/* NOOP */
-}
-
-static void
-cinterface_class_init(CamelObjectClass *klass)
-{
-	klass->magic = CAMEL_INTERFACE_MAGIC;
-
-	/* just setup dummy callbacks, properties could be part of the interface but we support none */
-	klass->getv = cinterface_getv;
-	klass->setv = cinterface_setv;
-	klass->free = cinterface_free;
-
-	/* TODO: ok, these are cruft hanging around an interface, but it saves having to define two different class bases */
-	klass->meta_get = NULL;
-	klass->meta_set = NULL;
-	klass->state_read = NULL;
-	klass->state_write = NULL;
-}
-
-static void
-cinterface_class_finalise(CamelObjectClass * klass)
-{
-	klass->magic = CAMEL_INTERFACE_FINALISED_MAGIC;
-	g_free(klass);
-}
-
-/* this function must be called for any other in the object system */
-CamelType
-camel_object_get_type(void)
-{
-	if (camel_object_type == CAMEL_INVALID_TYPE) {
-		camel_type_init();
-
-		camel_object_type = camel_type_register(NULL, "CamelObject", /*, 0, 0*/
-							sizeof(CamelObject), sizeof(CamelObjectClass),
-							cobject_class_init, cobject_class_finalise,
-							cobject_init, cobject_finalise);
-
-		camel_interface_type = camel_type_register(NULL, "CamelInterface",
-							   0, sizeof(CamelInterface),
-							   cinterface_class_init, cinterface_class_finalise,
-							   cinterface_init, NULL);
-
-	}
-
-	return camel_object_type;
-}
-
-static void
-camel_type_class_init(CamelObjectClass *klass, CamelObjectClass *type)
+object_dispose (GObject *object)
 {
-	if (type->parent)
-		camel_type_class_init(klass, type->parent);
-
-	if (type->klass_init)
-		type->klass_init(klass);
-}
-
-static CamelType
-co_type_register(CamelType parent, const gchar * name,
-		 /*guint ver, guint rev,*/
-		 gsize object_size, gsize klass_size,
-		 CamelObjectClassInitFunc class_init,
-		 CamelObjectClassFinalizeFunc class_finalise,
-		 CamelObjectInitFunc object_init,
-		 CamelObjectFinalizeFunc object_finalise)
-{
-	CamelObjectClass *klass;
-	/*int offset;
-	  gsize size;*/
-
-	TYPE_LOCK();
-
-	camel_type_init(); /* has a static boolean itself */
-
-	/* Have to check creation, it might've happened in another thread before we got here */
-	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) {
-			g_warning("camel_type_register: Trying to re-register class '%s'", name);
-			klass = NULL;
-		}
-		TYPE_UNLOCK();
-		return klass;
-	}
-
-	/* this is for objects with no parent as part of their struct ('interfaces'?) */
-	/*offset = parent?parent->klass_size:0;
-	offset = (offset + 3) & (~3);
-
-	size = offset + klass_size;
+	CamelObject *camel_object = CAMEL_OBJECT (object);
 
-	klass = g_slice_alloc0(size);
-
-	klass->klass_size = size;
-	klass->klass_data = offset;
-
-	offset = parent?parent->object_size:0;
-	offset = (offset + 3) & (~3);
-
-	klass->object_size = offset + object_size;
-	klass->object_data = offset;*/
-
-	if (parent
-	    && klass_size < parent->klass_size) {
-		g_warning("camel_type_register: '%s' has smaller class size than parent '%s'", name, parent->name);
-		TYPE_UNLOCK();
-		return NULL;
+	if (camel_object->hooks != NULL) {
+		camel_object_trigger_event (object, "finalize", NULL);
+		camel_object_free_hooks (camel_object);
 	}
 
-	klass = g_slice_alloc0 (klass_size);
-	klass->klass_size = klass_size;
-	klass->object_size = object_size;
-	klass->lock = g_mutex_new();
-	klass->hooks = NULL;
-
-	klass->parent = parent;
-	if (parent) {
-		klass->next = parent->child;
-		parent->child = klass;
-	}
-	klass->name = name;
-
-	/*klass->version = ver;
-	  klass->revision = rev;*/
-
-	klass->klass_init = class_init;
-	klass->klass_finalise = class_finalise;
-
-	klass->init = object_init;
-	klass->finalise = object_finalise;
-
-	/* setup before class init, incase class init func uses the type or looks it up ? */
-	g_hash_table_insert(type_table, (gpointer)name, klass);
-
-	camel_type_class_init(klass, klass);
-
-	TYPE_UNLOCK();
-
-	return klass;
-}
-
-CamelType
-camel_type_register(CamelType parent, const gchar * name,
-		    /*guint ver, guint rev,*/
-		    gsize object_size, gsize klass_size,
-		    CamelObjectClassInitFunc class_init,
-		    CamelObjectClassFinalizeFunc class_finalise,
-		    CamelObjectInitFunc object_init,
-		    CamelObjectFinalizeFunc object_finalise)
-{
-	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);
-}
-
-CamelType
-camel_interface_register(CamelType parent, const gchar *name,
-			 gsize class_size,
-			 CamelObjectClassInitFunc class_init,
-			 CamelObjectClassFinalizeFunc class_finalise)
-{
-	if (parent != NULL && parent->magic != CAMEL_INTERFACE_MAGIC) {
-		g_warning("camel_interface_register: invalid junk parent class for '%s'", name);
-		return NULL;
-	}
-
-	return camel_type_register(parent, name, 0, class_size, class_init, class_finalise, NULL, NULL);
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_object_init(CamelObject *o, CamelObjectClass *klass, CamelType type)
+object_class_init (CamelObjectClass *class)
 {
-	if (type->parent)
-		camel_object_init(o, klass, type->parent);
+	GObjectClass *object_class;
 
-	if (type->init)
-		type->init(o, klass);
-}
-
-CamelObject *
-camel_object_new(CamelType type)
-{
-	CamelObject *o;
-
-	if (type == NULL)
-		return NULL;
-
-	if (type->magic != CAMEL_OBJECT_CLASS_MAGIC)
-		return NULL;
+	parent_class = g_type_class_peek_parent (class);
 
-	CLASS_LOCK(type);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = object_dispose;
 
-	o = g_slice_alloc0 (type->object_size);
+	class->hooks = NULL;
 
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	if (type->instances)
-		type->instances->prev = o;
-	o->next = type->instances;
-	o->prev = NULL;
-	type->instances = o;
-#endif
+	class->getv = cobject_getv;
+	class->setv = cobject_setv;
+	class->free = cobject_free;
 
-	CLASS_UNLOCK(type);
+	class->meta_get = cobject_meta_get;
+	class->meta_set = cobject_meta_set;
+	class->state_read = cobject_state_read;
+	class->state_write = cobject_state_write;
 
-	camel_object_init(o, type, type);
-
-	d(printf("%p: new %s()\n", o, o->klass->name));
-
-	return o;
-}
-
-void
-camel_object_ref(gpointer vo)
-{
-	register CamelObject *o = vo;
-
-	g_return_if_fail(CAMEL_IS_OBJECT(o));
-
-	REF_LOCK();
-
-	o->ref_count++;
-	d(printf("%p: ref %s(%d)\n", o, o->klass->name, o->ref_count));
-
-	REF_UNLOCK();
+	camel_object_class_add_event (class, "finalize", NULL);
 }
 
-void
-camel_object_unref(gpointer vo)
-{
-	register CamelObject *o = vo;
-	register CamelObjectClass *klass, *k;
-	CamelHookList *hooks = NULL;
-
-	g_return_if_fail(CAMEL_IS_OBJECT(o));
-
-	klass = o->klass;
-
-	if (o->hooks)
-		hooks = camel_object_get_hooks(o);
-
-	REF_LOCK();
-
-	o->ref_count--;
-
-	d(printf("%p: unref %s(%d)\n", o, o->klass->name, o->ref_count));
-
-	if (o->ref_count > 0
-	    || (o->flags & CAMEL_OBJECT_DESTROY)) {
-		REF_UNLOCK();
-		if (hooks)
-			camel_object_unget_hooks(o);
-		return;
-	}
-
-	o->flags |= CAMEL_OBJECT_DESTROY;
-
-	if (hooks)
-		camel_object_bag_remove_unlocked(NULL, o, hooks);
-
-	REF_UNLOCK();
-
-	if (hooks)
-		camel_object_unget_hooks(o);
-
-	camel_object_trigger_event(o, "finalize", NULL);
-
-	k = klass;
-	while (k) {
-		if (k->finalise)
-			k->finalise(o);
-		k = k->parent;
-	}
-
-	o->magic = CAMEL_OBJECT_FINALISED_MAGIC;
-
-	CLASS_LOCK(klass);
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	if (o->prev)
-		o->prev->next = o->next;
-	else
-		klass->instances = o->next;
-	if (o->next)
-		o->next->prev = o->prev;
-#endif
-	g_slice_free1 (klass->object_size, o);
-	CLASS_UNLOCK(klass);
-}
-
-const gchar *
-camel_type_to_name(CamelType type)
-{
-	if (type == NULL)
-		return "(NULL class)";
-
-	if (type->magic == CAMEL_OBJECT_CLASS_MAGIC)
-		return type->name;
-
-	if (type->magic == CAMEL_INTERFACE_MAGIC)
-		return type->name;
-
-	return "(Junk class)";
-}
-
-CamelType camel_name_to_type(const gchar *name)
-{
-	/* TODO: Load a class off disk (!) */
-
-	return g_hash_table_lookup(type_table, name);
-}
-
-static gchar *
-desc_data(CamelObject *o, guint32 ok)
-{
-	gchar *what;
-
-	if (o == NULL)
-		what = g_strdup("NULL OBJECT");
-	else if (o->magic == ok)
-		what = NULL;
-	else if (o->magic == CAMEL_OBJECT_MAGIC)
-		what = g_strdup_printf("CLASS '%s'", ((CamelObjectClass *)o)->name);
-	else if (o->magic == CAMEL_OBJECT_CLASS_MAGIC)
-		what = g_strdup_printf("CLASS '%s'", ((CamelObjectClass *)o)->name);
-	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");
-	else if (o->magic == CAMEL_OBJECT_CLASS_FINALISED_MAGIC)
-		what = g_strdup_printf("finalised CLASS");
-	else if (o->magic == CAMEL_INTERFACE_FINALISED_MAGIC)
-		what = g_strdup_printf("finalised INTERFACE");
-	else
-		what = g_strdup_printf("junk data");
-
-	return what;
-}
-
-#define check_magic(o, ctype, omagic) \
-	( ((CamelObject *)(o))->magic == (omagic) \
-	&& (ctype)->magic == CAMEL_OBJECT_CLASS_MAGIC) \
-	? 1 : check_magic_fail(o, ctype, omagic)
-
-static gboolean
-check_magic_fail(gpointer o, CamelType ctype, guint32 omagic)
-{
-	gchar *what, *to;
-
-	what = desc_data(o, omagic);
-	to = desc_data((CamelObject *)ctype, CAMEL_OBJECT_CLASS_MAGIC);
-
-	if (what || to) {
-		if (what == NULL) {
-			if (omagic == CAMEL_OBJECT_MAGIC)
-				what = g_strdup_printf("OBJECT '%s'", ((CamelObject *)o)->klass->name);
-			else
-				what = g_strdup_printf("OBJECT '%s'", ((CamelObjectClass *)o)->name);
-		}
-		if (to == NULL)
-			to = g_strdup_printf("OBJECT '%s'", ctype->name);
-		g_warning("Trying to check %s is %s", what, to);
-		g_free(what);
-		g_free(to);
-
-		return FALSE;
-	}
-
-	return TRUE;
-}
-
-gboolean
-camel_object_is(CamelObject *o, CamelType ctype)
-{
-	CamelObjectClass *k;
-
-	g_return_val_if_fail(o != NULL, FALSE);
-	g_return_val_if_fail(check_magic(o, ctype, CAMEL_OBJECT_MAGIC), FALSE);
-
-	k = o->klass;
-	while (k) {
-		if (k == ctype)
-			return TRUE;
-		k = k->parent;
-	}
-
-	return FALSE;
-}
-
-gboolean
-camel_object_class_is(CamelObjectClass *k, CamelType ctype)
-{
-	g_return_val_if_fail(k != NULL, FALSE);
-	g_return_val_if_fail(check_magic(k, ctype, CAMEL_OBJECT_CLASS_MAGIC), FALSE);
-
-	while (k) {
-		if (k == ctype)
-			return TRUE;
-		k = k->parent;
-	}
-
-	return FALSE;
-}
-
-gboolean
-camel_interface_is(CamelObjectClass *k, CamelType ctype)
-{
-	g_return_val_if_fail(k != NULL, FALSE);
-	g_return_val_if_fail(check_magic(k, ctype, CAMEL_INTERFACE_MAGIC), FALSE);
-
-	while (k) {
-		if (k == ctype)
-			return TRUE;
-		k = k->parent;
-	}
-
-	return FALSE;
-}
-
-CamelObject *
-camel_object_cast(CamelObject *o, CamelType ctype)
-{
-	CamelObjectClass *k;
-
-        g_return_val_if_fail(o != NULL, NULL);
-	g_return_val_if_fail(check_magic(o, ctype, CAMEL_OBJECT_MAGIC), NULL);
-
-	k = o->klass;
-	while (k) {
-		if (k == ctype)
-			return o;
-		k = k->parent;
-	}
-
-	g_warning("Object %p (class '%s') doesn't have '%s' in its hierarchy", (gpointer) o, o->klass->name, ctype->name);
-
-	return NULL;
-}
-
-CamelObjectClass *
-camel_object_class_cast(CamelObjectClass *k, CamelType ctype)
-{
-	CamelObjectClass *r = k;
-
-	g_return_val_if_fail(check_magic(k, ctype, CAMEL_OBJECT_CLASS_MAGIC), NULL);
-
-	while (k) {
-		if (k == ctype)
-			return r;
-		k = k->parent;
-	}
-
-	g_warning("Class '%s' doesn't have '%s' in its hierarchy", r->name, ctype->name);
-
-	return NULL;
-}
-
-CamelObjectClass *
-camel_interface_cast(CamelObjectClass *k, CamelType ctype)
-{
-	CamelObjectClass *r = k;
-
-	g_return_val_if_fail(check_magic(k, ctype, CAMEL_INTERFACE_MAGIC), NULL);
-
-	while (k) {
-		if (k == ctype)
-			return r;
-		k = k->parent;
-	}
-
-	g_warning("Interface '%s' doesn't have '%s' in its hierarchy", r->name, ctype->name);
-
-	return NULL;
-}
-
-static CamelHookPair *
-co_find_pair(CamelObjectClass *klass, const gchar *name)
+GType
+camel_object_get_type(void)
 {
-	CamelHookPair *hook;
+	static GType type = G_TYPE_INVALID;
 
-	hook = klass->hooks;
-	while (hook) {
-		if (strcmp(hook->name, name) == 0)
-			return hook;
-		hook = hook->next;
-	}
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			G_TYPE_OBJECT,
+			"CamelObject",
+			sizeof (CamelObjectClass),
+			(GClassInitFunc) object_class_init,
+			sizeof (CamelObject),
+			(GInstanceInitFunc) NULL,
+			0);
 
-	return NULL;
+	return type;
 }
 
 static CamelHookPair *
-co_find_pair_ptr(CamelObjectClass *klass, const gchar *name)
+co_find_pair (CamelObjectClass *class,
+              const gchar *name)
 {
 	CamelHookPair *hook;
 
-	hook = klass->hooks;
+	hook = class->hooks;
 	while (hook) {
-		if (hook->name == name)
+		if (strcmp (hook->name, name) == 0)
 			return hook;
 		hook = hook->next;
 	}
@@ -1147,104 +575,56 @@ co_find_pair_ptr(CamelObjectClass *klass, const gchar *name)
 
 /* class functions */
 void
-camel_object_class_add_event(CamelObjectClass *klass, const gchar *name, CamelObjectEventPrepFunc prep)
+camel_object_class_add_event (CamelObjectClass *class,
+                              const gchar *name,
+                              CamelObjectEventPrepFunc prep)
 {
 	CamelHookPair *pair;
 
 	g_return_if_fail (name);
 
-	pair = co_find_pair(klass, name);
+	pair = co_find_pair (class, name);
 	if (pair) {
-		g_warning("camel_object_class_add_event: '%s' is already declared for '%s'",
-			  name, klass->name);
+		g_warning ("%s: '%s' is already declared for '%s'",
+			G_STRFUNC, name, G_OBJECT_CLASS_NAME (class));
 		return;
 	}
 
-	if (klass->magic == CAMEL_INTERFACE_MAGIC && prep != NULL) {
-		g_warning("camel_object_class_add_event: '%s', CamelInterface '%s' may not have an event prep function - ignored",
-			  name, klass->name);
-		prep = NULL;
-	}
-
-	pair = pair_alloc();
+	pair = pair_alloc ();
 	pair->name = name;
 	pair->func.prep = prep;
 	pair->flags = 0;
 
-	pair->next = klass->hooks;
-	klass->hooks = pair;
-}
-
-void
-camel_object_class_add_interface(CamelObjectClass *klass, CamelType itype)
-{
-	CamelHookPair *pair;
-	CamelType iscan;
-	GPtrArray *interfaces;
-	gint i;
-
-	if (!camel_interface_is(itype, camel_interface_type)) {
-		g_warning("Cannot add an interface not derived from CamelInterface on class '%s'", klass->name);
-		return;
-	}
-
-	if (camel_object_class_is(klass, camel_interface_type)) {
-		g_warning("Cannot add an interface onto a class derived from CamelInterface");
-		return;
-	}
-
-	/* we store it on the class hooks so we don't have to add any extra space to the class */
-	pair = co_find_pair_ptr(klass, interface_name);
-	if (pair == NULL) {
-		pair = pair_alloc();
-		pair->data = g_ptr_array_new();
-		pair->next = klass->hooks;
-		klass->hooks = pair;
-	}
-
-	/* We just check that this type isn't added/derived anywhere else */
-	interfaces = pair->data;
-	iscan = itype;
-	while (iscan && iscan != camel_interface_type) {
-		for (i=0;i<interfaces->len;i++) {
-			if (camel_interface_is((CamelType)interfaces->pdata[i], iscan)) {
-				g_warning("Cannot add an interface twice '%s' on class '%s'\n", itype->name, klass->name);
-				return;
-			}
-		}
-		iscan = iscan->parent;
-	}
-
-	if (iscan == camel_interface_type)
-		g_ptr_array_add(interfaces, itype);
+	pair->next = class->hooks;
+	class->hooks = pair;
 }
 
 /* free hook data */
 static void
 camel_object_free_hooks(CamelObject *o)
 {
-	CamelHookPair *pair, *next;
+        CamelHookPair *pair, *next;
 
-	if (o->hooks) {
-		g_assert(o->hooks->depth == 0);
-		g_assert((o->hooks->flags & CAMEL_HOOK_PAIR_REMOVED) == 0);
+        if (o->hooks) {
+                g_assert(o->hooks->depth == 0);
+                g_assert((o->hooks->flags & CAMEL_HOOK_PAIR_REMOVED) == 0);
 
-		pair = o->hooks->list;
-		while (pair) {
-			next = pair->next;
+                pair = o->hooks->list;
+                while (pair) {
+                        next = pair->next;
 
-			if (pair->name == meta_name) {
-				co_metadata_free(o, pair->data);
-				g_free(pair->func.filename);
-			}
+                        if (pair->name == meta_name) {
+                                co_metadata_free(o, pair->data);
+                                g_free(pair->func.filename);
+                        }
 
-			pair_free(pair);
-			pair = next;
-		}
-		g_static_rec_mutex_free(&o->hooks->lock);
-		hooks_free(o->hooks);
-		o->hooks = NULL;
-	}
+                        pair_free(pair);
+                        pair = next;
+                }
+                g_static_rec_mutex_free(&o->hooks->lock);
+                hooks_free(o->hooks);
+                o->hooks = NULL;
+        }
 }
 
 /* return (allocate if required) the object's hook list, locking at the same time */
@@ -1276,9 +656,13 @@ camel_object_get_hooks(CamelObject *o)
 }
 
 guint
-camel_object_hook_event(gpointer vo, const gchar * name, CamelObjectEventHookFunc func, gpointer data)
+camel_object_hook_event (gpointer vo,
+                         const gchar *name,
+                         CamelObjectEventHookFunc func,
+                         gpointer data)
 {
 	CamelObject *obj = vo;
+	CamelObjectClass *class;
 	CamelHookPair *pair, *hook;
 	CamelHookList *hooks;
 	gint id;
@@ -1287,28 +671,18 @@ camel_object_hook_event(gpointer vo, const gchar * name, CamelObjectEventHookFun
 	g_return_val_if_fail(name != NULL, 0);
 	g_return_val_if_fail(func != NULL, 0);
 
-	hook = co_find_pair(obj->klass, name);
+	class = CAMEL_OBJECT_GET_CLASS (obj);
+
+	hook = co_find_pair(class, name);
 
 	/* Check all interfaces on this object for events defined on them */
 	if (hook == NULL) {
-		pair = co_find_pair_ptr(obj->klass, interface_name);
-		if (pair) {
-			GPtrArray *interfaces = pair->data;
-			gint i;
-
-			for (i=0;i<interfaces->len;i++) {
-				hook = co_find_pair(interfaces->pdata[i], name);
-				if (hook)
-					goto setup;
-			}
-		}
-
 		g_warning("camel_object_hook_event: trying to hook event '%s' in class '%s' with no defined events.",
-			  name, obj->klass->name);
+			  name, G_OBJECT_CLASS_NAME (class));
 
 		return 0;
 	}
-setup:
+
 	/* setup hook pair */
 	pair = pair_alloc();
 	pair->name = hook->name;	/* effectively static! */
@@ -1330,7 +704,8 @@ setup:
 }
 
 void
-camel_object_remove_event(gpointer vo, guint id)
+camel_object_remove_event (gpointer vo,
+                           guint id)
 {
 	CamelObject *obj = vo;
 	CamelHookList *hooks;
@@ -1341,7 +716,7 @@ camel_object_remove_event(gpointer vo, guint id)
 
 	if (obj->hooks == NULL) {
 		g_warning("camel_object_unhook_event: trying to unhook '%u' from an instance of '%s' with no hooks",
-			  id, obj->klass->name);
+			  id, G_OBJECT_TYPE_NAME (obj));
 		return;
 	}
 
@@ -1371,11 +746,14 @@ camel_object_remove_event(gpointer vo, guint id)
 	camel_object_unget_hooks(obj);
 
 	g_warning("camel_object_unhook_event: cannot find hook id %u in instance of '%s'",
-		  id, obj->klass->name);
+		  id, G_OBJECT_TYPE_NAME (obj));
 }
 
 void
-camel_object_unhook_event(gpointer vo, const gchar * name, CamelObjectEventHookFunc func, gpointer data)
+camel_object_unhook_event (gpointer vo,
+                           const gchar *name,
+                           CamelObjectEventHookFunc func,
+                           gpointer data)
 {
 	CamelObject *obj = vo;
 	CamelHookList *hooks;
@@ -1387,7 +765,7 @@ camel_object_unhook_event(gpointer vo, const gchar * name, CamelObjectEventHookF
 
 	if (obj->hooks == NULL) {
 		g_warning("camel_object_unhook_event: trying to unhook '%s' from an instance of '%s' with no hooks",
-			  name, obj->klass->name);
+			  name, G_OBJECT_TYPE_NAME (obj));
 		return;
 	}
 
@@ -1419,13 +797,16 @@ camel_object_unhook_event(gpointer vo, const gchar * name, CamelObjectEventHookF
 	camel_object_unget_hooks(obj);
 
 	g_warning("camel_object_unhook_event: cannot find hook/data pair %p/%p in an instance of '%s' attached to '%s'",
-		  (gpointer) func, data, obj->klass->name, name);
+		  (gpointer) func, data, G_OBJECT_TYPE_NAME (obj), name);
 }
 
 void
-camel_object_trigger_event(gpointer vo, const gchar * name, gpointer event_data)
+camel_object_trigger_event (gpointer vo,
+                            const gchar *name,
+                            gpointer event_data)
 {
 	CamelObject *obj = vo;
+	CamelObjectClass *class;
 	CamelHookList *hooks;
 	CamelHookPair *pair, **pairs, *parent, *hook;
 	gint i, size;
@@ -1434,27 +815,17 @@ camel_object_trigger_event(gpointer vo, const gchar * name, gpointer event_data)
 	g_return_if_fail (CAMEL_IS_OBJECT (obj));
 	g_return_if_fail (name);
 
-	hook = co_find_pair(obj->klass, name);
+	class = CAMEL_OBJECT_GET_CLASS (obj);
+
+	hook = co_find_pair(class, name);
 	if (hook)
 		goto trigger;
 
 	if (obj->hooks == NULL)
 		return;
 
-	/* interface events can't have prep functions */
-	pair = co_find_pair_ptr(obj->klass, interface_name);
-	if (pair) {
-		GPtrArray *interfaces = pair->data;
-
-		for (i=0;i<interfaces->len;i++) {
-			hook = co_find_pair(interfaces->pdata[i], name);
-			if (hook)
-				goto trigger_interface;
-		}
-	}
-
 	g_warning("camel_object_trigger_event: trying to trigger unknown event '%s' in class '%s'",
-		  name, obj->klass->name);
+		  name, G_OBJECT_TYPE_NAME (obj));
 
 	return;
 
@@ -1467,9 +838,8 @@ trigger:
 	if (obj->hooks == NULL)
 		return;
 
-trigger_interface:
 	/* lock the object for hook emission */
-	camel_object_ref(obj);
+	g_object_ref(obj);
 	hooks = camel_object_get_hooks(obj);
 
 	if (hooks->list) {
@@ -1512,89 +882,86 @@ trigger_interface:
 	}
 
 	camel_object_unget_hooks(obj);
-	camel_object_unref(obj);
-}
-
-gpointer
-camel_object_get_interface(gpointer vo, CamelType itype)
-{
-	CamelObject *obj = vo;
-	CamelHookPair *pair;
-
-	g_return_val_if_fail(CAMEL_IS_OBJECT (obj), NULL);
-	g_return_val_if_fail(camel_interface_is(itype, camel_interface_type), NULL);
-
-	pair = co_find_pair_ptr(obj->klass, interface_name);
-	if (pair) {
-		GPtrArray *interfaces = pair->data;
-		gint i;
-
-		for (i=0;i<interfaces->len;i++) {
-			if (camel_interface_is((CamelType)interfaces->pdata[i], itype))
-				return (CamelType)interfaces->pdata[i];
-		}
-	}
-
-	g_warning("Object %p class %s doesn't contain interface %s\n", vo, obj->klass->name, itype->name);
-
-	return NULL;
+	g_object_unref(obj);
 }
 
 /* get/set arg methods */
-gint camel_object_set(gpointer vo, CamelException *ex, ...)
+gint
+camel_object_set (gpointer vo,
+                  CamelException *ex, ...)
 {
+	CamelObjectClass *class;
 	CamelArgV args;
 	CamelObject *o = vo;
-	CamelObjectClass *klass = o->klass;
 	gint ret = 0;
 
 	g_return_val_if_fail(CAMEL_IS_OBJECT(o), -1);
 
 	camel_argv_start(&args, ex);
 
+	class = CAMEL_OBJECT_GET_CLASS (o);
+	g_return_val_if_fail (class->setv != NULL, -1);
+
 	while (camel_argv_build(&args) && ret == 0)
-		ret = klass->setv(o, ex, &args);
+		ret = class->setv(o, ex, &args);
 	if (ret == 0)
-		ret = klass->setv(o, ex, &args);
+		ret = class->setv(o, ex, &args);
 
 	camel_argv_end(&args);
 
 	return ret;
 }
 
-gint camel_object_setv(gpointer vo, CamelException *ex, CamelArgV *args)
+gint
+camel_object_setv (gpointer vo,
+                   CamelException *ex,
+                   CamelArgV *args)
 {
+	CamelObjectClass *class;
+
 	g_return_val_if_fail(CAMEL_IS_OBJECT(vo), -1);
 
-	return ((CamelObject *)vo)->klass->setv(vo, ex, args);
+	class = CAMEL_OBJECT_GET_CLASS (vo);
+	g_return_val_if_fail (class->setv != NULL, -1);
+
+	return class->setv (vo, ex, args);
 }
 
-gint camel_object_get(gpointer vo, CamelException *ex, ...)
+gint
+camel_object_get (gpointer vo,
+                  CamelException *ex,
+                  ...)
 {
+	CamelObjectClass *class;
 	CamelObject *o = vo;
 	CamelArgGetV args;
-	CamelObjectClass *klass = o->klass;
 	gint ret = 0;
 
 	g_return_val_if_fail(CAMEL_IS_OBJECT(o), -1);
 
 	camel_argv_start(&args, ex);
 
+	class = CAMEL_OBJECT_GET_CLASS (o);
+	g_return_val_if_fail (class->getv != NULL, -1);
+
 	while (camel_arggetv_build(&args) && ret == 0)
-		ret = klass->getv(o, ex, &args);
+		ret = class->getv(o, ex, &args);
 	if (ret == 0)
-		ret = klass->getv(o, ex, &args);
+		ret = class->getv(o, ex, &args);
 
 	camel_argv_end(&args);
 
 	return ret;
 }
 
-gpointer camel_object_get_ptr(gpointer vo, CamelException *ex, gint tag)
+gpointer
+camel_object_get_ptr (gpointer vo,
+                      CamelException *ex,
+                      gint tag)
 {
+	CamelObjectClass *class;
 	CamelObject *o = vo;
 	CamelArgGetV args;
-	CamelObjectClass *klass = o->klass;
 	gint ret = 0;
 	gpointer val = NULL;
 
@@ -1608,18 +975,23 @@ gpointer camel_object_get_ptr(gpointer vo, CamelException *ex, gint tag)
 	args.argv[0].tag = tag;
 	args.argv[0].ca_ptr = &val;
 
-	ret = klass->getv(o, ex, &args);
+	class = CAMEL_OBJECT_GET_CLASS (o);
+	g_return_val_if_fail (class->getv != NULL, NULL);
+
+	ret = class->getv(o, ex, &args);
 	if (ret != 0)
 		return NULL;
 	else
 		return val;
 }
 
-gint camel_object_get_int(gpointer vo, CamelException *ex, gint tag)
+gint
+camel_object_get_int (gpointer vo,
+                      CamelException *ex, gint tag)
 {
+	CamelObjectClass *class;
 	CamelObject *o = vo;
 	CamelArgGetV args;
-	CamelObjectClass *klass = o->klass;
 	gint ret = 0;
 	gint val = 0;
 
@@ -1632,18 +1004,29 @@ gint camel_object_get_int(gpointer vo, CamelException *ex, gint tag)
 	args.argv[0].tag = tag;
 	args.argv[0].ca_int = &val;
 
-	ret = klass->getv(o, ex, &args);
+	class = CAMEL_OBJECT_GET_CLASS (o);
+	g_return_val_if_fail (class->getv != NULL, 0);
+
+	ret = class->getv(o, ex, &args);
 	if (ret != 0)
 		return 0;
 	else
 		return val;
 }
 
-gint camel_object_getv(gpointer vo, CamelException *ex, CamelArgGetV *args)
+gint
+camel_object_getv (gpointer vo,
+                   CamelException *ex,
+                   CamelArgGetV *args)
 {
+	CamelObjectClass *class;
+
 	g_return_val_if_fail(CAMEL_IS_OBJECT(vo), -1);
 
-	return ((CamelObject *)vo)->klass->getv(vo, ex, args);
+	class = CAMEL_OBJECT_GET_CLASS (vo);
+	g_return_val_if_fail (class->getv != NULL, -1);
+
+	return class->getv (vo, ex, args);
 }
 
 /* NB: If this doesn't return NULL, then you must unget_hooks when done */
@@ -1735,14 +1118,19 @@ co_metadata_free(CamelObject *obj, CamelObjectMeta *meta)
  * Return value: NULL if the meta-data is not set.
  **/
 gchar *
-camel_object_meta_get(gpointer vo, const gchar * name)
+camel_object_meta_get (gpointer vo,
+                       const gchar * name)
 {
 	CamelObject *obj = vo;
+	CamelObjectClass *class;
 
-	g_return_val_if_fail(CAMEL_IS_OBJECT (obj), NULL);
-	g_return_val_if_fail(name != NULL, NULL);
+	g_return_val_if_fail (CAMEL_IS_OBJECT (obj), NULL);
+	g_return_val_if_fail (name != NULL, NULL);
+
+	class = CAMEL_OBJECT_GET_CLASS (obj);
+	g_return_val_if_fail (class->meta_get != NULL, NULL);
 
-	return obj->klass->meta_get(obj, name);
+	return class->meta_get (obj, name);
 }
 
 /**
@@ -1754,10 +1142,6 @@ camel_object_meta_get(gpointer vo, const gchar * name)
  * Set a meta-data item on an object.  If the object supports persistent
  * data, then the meta-data will be persistent across sessions.
  *
- * If the meta-data changes, is added, or removed, then a
- * "meta_changed" event will be triggered with the name of the changed
- * data.
- *
  * Return Value: TRUE if the setting caused a change to the object's
  * metadata.
  **/
@@ -1765,16 +1149,15 @@ gboolean
 camel_object_meta_set(gpointer vo, const gchar * name, const gchar *value)
 {
 	CamelObject *obj = vo;
+	CamelObjectClass *class;
 
-	g_return_val_if_fail(CAMEL_IS_OBJECT (obj), FALSE);
-	g_return_val_if_fail(name != NULL, FALSE);
+	g_return_val_if_fail (CAMEL_IS_OBJECT (obj), FALSE);
+	g_return_val_if_fail (name != NULL, FALSE);
 
-	if (obj->klass->meta_set(obj, name, value)) {
-		camel_object_trigger_event(obj, "meta_changed", (gpointer)name);
-		return TRUE;
-	}
+	class = CAMEL_OBJECT_GET_CLASS (obj);
+	g_return_val_if_fail (class->meta_set != NULL, FALSE);
 
-	return FALSE;
+	return class->meta_set (obj, name, value);
 }
 
 /**
@@ -1801,7 +1184,7 @@ gint camel_object_state_read(gpointer vo)
 	if (fp != NULL) {
 		if (fread(magic, 4, 1, fp) == 1
 		    && memcmp(magic, CAMEL_OBJECT_STATE_FILE_MAGIC, 4) == 0)
-			res = obj->klass->state_read(obj, fp);
+			res = CAMEL_OBJECT_GET_CLASS (obj)->state_read(obj, fp);
 		else
 			res = -1;
 		fclose(fp);
@@ -1838,7 +1221,7 @@ gint camel_object_state_write(gpointer vo)
 	fp = g_fopen(savename, "wb");
 	if (fp != NULL) {
 		if (fwrite(CAMEL_OBJECT_STATE_FILE_MAGIC, 4, 1, fp) == 1
-		    && obj->klass->state_write(obj, fp) == 0) {
+		    && CAMEL_OBJECT_GET_CLASS (obj)->state_write(obj, fp) == 0) {
 			if (fclose(fp) == 0) {
 				res = 0;
 				g_rename(savename, file);
@@ -1877,530 +1260,5 @@ void camel_object_free(gpointer vo, guint32 tag, gpointer value)
 	   This would also let us copy and do other things with args
 	   we can't do, but i can't see a use for that yet ...  */
 
-	((CamelObject *)vo)->klass->free(vo, tag, value);
-}
-
-static void
-object_class_dump_tree_rec(CamelType root, gint depth)
-{
-	gchar *p;
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	struct _CamelObject *o;
-#endif
-
-	p = alloca(depth*2+1);
-	memset(p, ' ', depth*2);
-	p[depth*2] = 0;
-
-	while (root) {
-		CLASS_LOCK(root);
-		printf("%sClass: %s\n", p, root->name);
-		/*printf("%sVersion: %u.%u\n", p, root->version, root->revision);*/
-		if (root->hooks) {
-			CamelHookPair *pair = root->hooks;
-
-			while (pair) {
-				printf("%s  event '%s' prep %p\n", p, pair->name, (gpointer) pair->func.prep);
-				pair = pair->next;
-			}
-		}
-
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-		o = root->instances;
-		while (o) {
-			printf("%s instance %p [%d]\n", p, (gpointer) o, o->ref_count);
-			/* todo: should lock hooks while it scans them */
-			if (o->hooks) {
-				CamelHookPair *pair = o->hooks->list;
-
-				while (pair) {
-					printf("%s  hook '%s' func %p data %p\n", p, pair->name, (gpointer) pair->func.event, (gpointer) pair->data);
-					pair = pair->next;
-				}
-			}
-			o = o->next;
-		}
-#endif
-		CLASS_UNLOCK(root);
-
-		if (root->child)
-			object_class_dump_tree_rec(root->child, depth+1);
-
-		root = root->next;
-	}
-}
-
-void
-camel_object_class_dump_tree(CamelType root)
-{
-	object_class_dump_tree_rec(root, 0);
-}
-
-/**
- * camel_object_bag_new:
- * @hash:
- * @equal:
- * @keycopy:
- * @keyfree:
- *
- * Allocate a new object bag.  Object bag's are key'd hash tables of
- * camel-objects which can be updated atomically using transaction
- * semantics.
- *
- * Return value:
- **/
-CamelObjectBag *
-camel_object_bag_new(GHashFunc hash, GEqualFunc equal, CamelCopyFunc keycopy, GFreeFunc keyfree)
-{
-	CamelObjectBag *bag;
-
-	bag = g_malloc(sizeof(*bag));
-	bag->object_table = g_hash_table_new(hash, equal);
-	bag->equal_key = equal;
-	bag->copy_key = keycopy;
-	bag->free_key = keyfree;
-	bag->key_table = g_hash_table_new(NULL, NULL);
-	bag->reserved = NULL;
-
-	return bag;
-}
-
-static void
-save_object(gpointer key, CamelObject *o, GPtrArray *objects)
-{
-	g_ptr_array_add(objects, o);
-}
-
-void
-camel_object_bag_destroy(CamelObjectBag *bag)
-{
-	GPtrArray *objects = g_ptr_array_new();
-	gint i;
-
-	g_assert(bag->reserved == NULL);
-
-	g_hash_table_foreach(bag->object_table, (GHFunc)save_object, objects);
-	for (i=0;i<objects->len;i++)
-		camel_object_bag_remove(bag, objects->pdata[i]);
-
-	g_ptr_array_free(objects, TRUE);
-	g_hash_table_destroy(bag->object_table);
-	g_hash_table_destroy(bag->key_table);
-	g_free(bag);
-}
-
-/* must be called with ref_lock held */
-static void
-co_bag_unreserve(CamelObjectBag *bag, gconstpointer key)
-{
-	struct _CamelObjectBagKey *res, *resp;
-
-	resp = (struct _CamelObjectBagKey *)&bag->reserved;
-	res = resp->next;
-	while (res) {
-		if (bag->equal_key(res->key, key))
-			break;
-		resp = res;
-		res = res->next;
-	}
-
-	g_assert(res != NULL);
-	g_assert(res->have_owner && pthread_equal(res->owner, pthread_self()));
-
-	if (res->waiters > 0) {
-		b(printf("unreserve bag '%s', waking waiters\n", (gchar *)key));
-		res->have_owner = FALSE;
-		g_cond_signal(res->cond);
-	} else {
-		b(printf("unreserve bag '%s', no waiters, freeing reservation\n", (gchar *)key));
-		resp->next = res->next;
-		bag->free_key(res->key);
-		g_cond_free(res->cond);
-		g_free(res);
-	}
-}
-
-/**
- * camel_object_bag_add:
- * @bag:
- * @key:
- * @vo:
- *
- * Add an object @vo to the object bag @bag.  The @key MUST have
- * previously been reserved using camel_object_bag_reserve().
- **/
-void
-camel_object_bag_add(CamelObjectBag *bag, gconstpointer key, gpointer vo)
-{
-	CamelObject *o = vo;
-	CamelHookList *hooks;
-	CamelHookPair *pair;
-	gpointer k;
-
-	hooks = camel_object_get_hooks(o);
-	REF_LOCK();
-
-	pair = hooks->list;
-	while (pair) {
-		if (pair->name == bag_name && pair->data == bag) {
-			REF_UNLOCK();
-			camel_object_unget_hooks(o);
-			return;
-		}
-		pair = pair->next;
-	}
-
-	pair = pair_alloc();
-	pair->name = bag_name;
-	pair->data = bag;
-	pair->flags = 0;
-	pair->func.event = NULL;
-
-	pair->next = hooks->list;
-	hooks->list = pair;
-	hooks->list_length++;
-
-	k = bag->copy_key(key);
-	g_hash_table_insert(bag->object_table, k, vo);
-	g_hash_table_insert(bag->key_table, vo, k);
-
-	co_bag_unreserve(bag, key);
-
-	REF_UNLOCK();
-	camel_object_unget_hooks(o);
-}
-
-/**
- * camel_object_bag_get:
- * @bag:
- * @key:
- *
- * Lookup an object by @key.  If the key is currently reserved, then
- * wait until the key has been committed before continuing.
- *
- * Return value: NULL if the object corresponding to @key is not
- * in the bag.  Otherwise a ref'd object pointer which the caller owns
- * the ref to.
- **/
-gpointer
-camel_object_bag_get(CamelObjectBag *bag, gconstpointer key)
-{
-	CamelObject *o;
-
-	REF_LOCK();
-
-	o = g_hash_table_lookup(bag->object_table, key);
-	if (o) {
-		b(printf("object bag get '%s' = %p\n", (gchar *)key, o));
-
-		/* we use the same lock as the refcount */
-		o->ref_count++;
-	} else {
-		struct _CamelObjectBagKey *res = bag->reserved;
-
-		/* check if this name is reserved currently, if so wait till its finished */
-		while (res) {
-			if (bag->equal_key(res->key, key))
-				break;
-			res = res->next;
-		}
-
-		if (res) {
-			b(printf("object bag get '%s', reserved, waiting\n", (gchar *)key));
-
-			res->waiters++;
-			g_assert(!res->have_owner || !pthread_equal(res->owner, pthread_self()));
-			g_cond_wait(res->cond, ref_lock);
-			res->waiters--;
-
-			/* re-check if it slipped in */
-			o = g_hash_table_lookup(bag->object_table, key);
-			if (o)
-				o->ref_count++;
-
-			b(printf("object bag get '%s', finished waiting, got %p\n", (gchar *)key, o));
-
-			/* we don't actually reserve it */
-			res->owner = pthread_self();
-			res->have_owner = TRUE;
-			co_bag_unreserve(bag, key);
-		}
-	}
-
-	REF_UNLOCK();
-
-	return o;
-}
-
-/**
- * camel_object_bag_peek:
- * @bag:
- * @key:
- *
- * Lookup the object @key in @bag, ignoring any reservations.  If it
- * isn't committed, then it isn't considered.  This should only be
- * used where reliable transactional-based state is not required.
- *
- * Unlike other 'peek' operations, the object is still reffed if
- * found.
- *
- * Return value: A referenced object, or NULL if @key is not
- * present in the bag.
- **/
-gpointer
-camel_object_bag_peek(CamelObjectBag *bag, gconstpointer key)
-{
-	CamelObject *o;
-
-	REF_LOCK();
-
-	o = g_hash_table_lookup(bag->object_table, key);
-	if (o) {
-		/* we use the same lock as the refcount */
-		o->ref_count++;
-	}
-
-	REF_UNLOCK();
-
-	return o;
-}
-
-/**
- * camel_object_bag_reserve:
- * @bag:
- * @key:
- *
- * Reserve a key in the object bag.  If the key is already reserved in
- * another thread, then wait until the reservation has been committed.
- *
- * After reserving a key, you either get a reffed pointer to the
- * object corresponding to the key, similar to object_bag_get, or you
- * get NULL, signifying that you then MIST call either object_bag_add
- * or object_bag_abort.
- *
- * You may reserve multiple keys from the same thread, but they should
- * always be reserved in the same order, to avoid deadlocks.
- *
- * Return value:
- **/
-gpointer
-camel_object_bag_reserve(CamelObjectBag *bag, gconstpointer key)
-{
-	CamelObject *o;
-
-	REF_LOCK();
-
-	o = g_hash_table_lookup(bag->object_table, key);
-	if (o) {
-		o->ref_count++;
-	} else {
-		struct _CamelObjectBagKey *res = bag->reserved;
-
-		while (res) {
-			if (bag->equal_key(res->key, key))
-				break;
-			res = res->next;
-		}
-
-		if (res) {
-			b(printf("bag reserve %s, already reserved, waiting\n", (gchar *)key));
-			g_assert(!res->have_owner || !pthread_equal(res->owner, pthread_self()));
-			res->waiters++;
-			g_cond_wait(res->cond, ref_lock);
-			res->waiters--;
-			/* incase its slipped in while we were waiting */
-			o = g_hash_table_lookup(bag->object_table, key);
-			if (o) {
-				b(printf("finished wait, someone else created '%s' = %p\n", (gchar *)key, o));
-				o->ref_count++;
-				/* in which case we dont need to reserve the bag either */
-				res->owner = pthread_self();
-				res->have_owner = TRUE;
-				co_bag_unreserve(bag, key);
-			} else {
-				b(printf("finished wait, now owner of '%s'\n", (gchar *)key));
-				res->owner = pthread_self();
-				res->have_owner = TRUE;
-			}
-		} else {
-			b(printf("bag reserve %s, no key, reserving\n", (gchar *)key));
-			res = g_malloc(sizeof(*res));
-			res->waiters = 0;
-			res->key = bag->copy_key(key);
-			res->cond = g_cond_new();
-			res->owner = pthread_self();
-			res->have_owner = TRUE;
-			res->next = bag->reserved;
-			bag->reserved = res;
-		}
-	}
-
-	REF_UNLOCK();
-
-	return o;
-}
-
-/**
- * camel_object_bag_abort:
- * @bag:
- * @key:
- *
- * Abort a key reservation.
- **/
-void
-camel_object_bag_abort(CamelObjectBag *bag, gconstpointer key)
-{
-	REF_LOCK();
-
-	co_bag_unreserve(bag, key);
-
-	REF_UNLOCK();
-}
-
-/**
- * camel_object_bag_rekey:
- * @bag:
- * @o:
- * @newkey:
- *
- * Re-key an object, atomically.  The key for object @o is set to
- * @newkey, in an atomic manner.
- *
- * It is an api (fatal) error if @o is not currently in the bag.
- **/
-void
-camel_object_bag_rekey(CamelObjectBag *bag, gpointer o, gconstpointer newkey)
-{
-	gpointer oldkey;
-
-	REF_LOCK();
-
-	if (g_hash_table_lookup_extended(bag->key_table, o, NULL, &oldkey)) {
-		g_hash_table_remove(bag->object_table, oldkey);
-		g_hash_table_remove(bag->key_table, o);
-		bag->free_key(oldkey);
-		oldkey = bag->copy_key(newkey);
-		g_hash_table_insert(bag->object_table, oldkey, o);
-		g_hash_table_insert(bag->key_table, o, oldkey);
-	} else {
-		abort();
-	}
-
-	REF_UNLOCK();
-}
-
-static void
-save_bag(gpointer key, CamelObject *o, GPtrArray *list)
-{
-	/* we have the refcount lock already */
-	o->ref_count++;
-	g_ptr_array_add(list, o);
-}
-
-/* get a list of all objects in the bag, ref'd
-   ignores any reserved keys */
-GPtrArray *
-camel_object_bag_list(CamelObjectBag *bag)
-{
-	GPtrArray *list;
-
-	list = g_ptr_array_new();
-
-	REF_LOCK();
-	g_hash_table_foreach(bag->object_table, (GHFunc)save_bag, list);
-	REF_UNLOCK();
-
-	return list;
-}
-
-/* if bag is NULL, remove all bags from object */
-static void
-camel_object_bag_remove_unlocked(CamelObjectBag *inbag, CamelObject *o, CamelHookList *hooks)
-{
-	CamelHookPair *pair, *parent;
-	gpointer oldkey;
-	CamelObjectBag *bag;
-
-	parent = (CamelHookPair *)&hooks->list;
-	pair = parent->next;
-	while (pair) {
-		if (pair->name == bag_name
-		    && (inbag == NULL || inbag == pair->data)) {
-			bag = pair->data;
-			/* lookup object in table? */
-			oldkey = g_hash_table_lookup(bag->key_table, o);
-			if (oldkey) {
-				g_hash_table_remove(bag->key_table, o);
-				g_hash_table_remove(bag->object_table, oldkey);
-				bag->free_key(oldkey);
-			}
-			parent->next = pair->next;
-			pair_free(pair);
-			hooks->list_length--;
-		} else {
-			parent = pair;
-		}
-		pair = parent->next;
-	}
-}
-
-void
-camel_object_bag_remove(CamelObjectBag *inbag, gpointer vo)
-{
-	CamelObject *o = vo;
-	CamelHookList *hooks;
-
-	if (o->hooks == NULL)
-		return;
-
-	hooks = camel_object_get_hooks(o);
-	REF_LOCK();
-
-	camel_object_bag_remove_unlocked(inbag, o, hooks);
-
-	REF_UNLOCK();
-	camel_object_unget_hooks(o);
-}
-
-/* ********************************************************************** */
-
-gpointer camel_iterator_new(CamelIteratorVTable *klass, gsize size)
-{
-	CamelIterator *it;
-
-	g_assert(size >= sizeof(CamelIterator));
-
-	it = g_malloc0(size);
-	it->klass = klass;
-
-	return it;
-}
-
-gconstpointer camel_iterator_next(gpointer it, CamelException *ex)
-{
-	g_assert(it);
-	return ((CamelIterator *)it)->klass->next(it, ex);
-}
-
-void camel_iterator_reset(gpointer it)
-{
-	g_assert(it);
-	((CamelIterator *)it)->klass->reset(it);
-}
-
-gint camel_iterator_length(gpointer it)
-{
-	g_assert(it);
-	g_return_val_if_fail(((CamelIterator *)it)->klass->length != NULL, 0);
-
-	return ((CamelIterator *)it)->klass->length(it);
-}
-
-void camel_iterator_free(gpointer it)
-{
-	if (it) {
-		if (((CamelIterator *)it)->klass->free)
-			((CamelIterator *)it)->klass->free(it);
-		g_free(it);
-	}
+	CAMEL_OBJECT_GET_CLASS (vo)->free (vo, tag, value);
 }
diff --git a/camel/camel-object.h b/camel/camel-object.h
index 4b2216b..61bc261 100644
--- a/camel/camel-object.h
+++ b/camel/camel-object.h
@@ -22,75 +22,61 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_OBJECT_H
-#define CAMEL_OBJECT_H 1
+#define CAMEL_OBJECT_H
 
 #include <glib.h>
+#include <glib-object.h>
 #include <stdio.h>		/* FILE */
 #include <stdlib.h>		/* gsize */
 #include <stdarg.h>
 #include <pthread.h>
 
 #include <camel/camel-arg.h>
-#include <camel/camel-types.h>	/* this is a @##$ #SF stupid header */
-
-/* turn on so that camel_object_class_dump_tree() dumps object instances as well */
-#define CAMEL_OBJECT_TRACK_INSTANCES
+#include <camel/camel-exception.h>
+
+/* The CamelObjectBag API was originally defined in this header,
+ * so include it here for backward-compatibility. */
+#include <camel/camel-object-bag.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_OBJECT \
+	(camel_object_get_type ())
+#define CAMEL_OBJECT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_OBJECT, CamelObject))
+#define CAMEL_OBJECT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_OBJECT, CamelObjectClass))
+#define CAMEL_IS_OBJECT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_OBJECT))
+#define CAMEL_IS_OBJECT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_OBJECT))
+#define CAMEL_OBJECT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_OBJECT, CamelObjectClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelObjectClass *CamelType;
-
-#ifdef G_DISABLE_CHECKS
-#define CAMEL_CHECK_CAST(obj, ctype, ptype)         ((ptype *) obj)
-#define CAMEL_CHECK_CLASS_CAST(klass, ctype, ptype) ((ptype *) klass)
-#else
-#define CAMEL_CHECK_CAST(obj, ctype, ptype)         ((ptype *) camel_object_cast ((CamelObject *)(obj), (CamelType)(ctype)))
-#define CAMEL_CHECK_CLASS_CAST(klass, ctype, ptype) ((ptype *) camel_object_class_cast ((CamelObjectClass *)(klass), (CamelType)(ctype) ))
-#endif
-#define CAMEL_CHECK_TYPE(obj, ctype)                (camel_object_is ((CamelObject *)(obj), (CamelType)(ctype) ))
-#define CAMEL_CHECK_CLASS_TYPE(klass, ctype)        (camel_object_class_is ((CamelObjectClass *)(klass), (CamelType)(ctype)))
-
-extern CamelType camel_object_type;
-
-#define CAMEL_OBJECT_TYPE        (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))
-#define CAMEL_OBJECT_CLASS(k)    (CAMEL_CHECK_CLASS_CAST ((k), camel_object_type, CamelObjectClass))
-#define CAMEL_IS_OBJECT(o)       (CAMEL_CHECK_TYPE((o), camel_object_type))
-#define CAMEL_IS_OBJECT_CLASS(k) (CAMEL_CHECK_CLASS_TYPE((k), camel_object_type))
-
-#define CAMEL_OBJECT_GET_CLASS(o) ((CamelObjectClass *)(CAMEL_OBJECT(o))->klass)
-#define CAMEL_OBJECT_GET_TYPE(o)  ((CamelType)(CAMEL_OBJECT(o))->klass)
-
 typedef struct _CamelObjectClass CamelObjectClass;
 typedef struct _CamelObject CamelObject;
 typedef guint CamelObjectHookID;
-#ifndef CAMEL_DISABLE_DEPRECATED
 typedef struct _CamelObjectMeta CamelObjectMeta;
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
-#ifndef CAMEL_DISABLE_DEPRECATED
-extern CamelType camel_interface_type;
-#define CAMEL_INTERFACE_TYPE (camel_interface_type)
-typedef struct _CamelInterface CamelInterface;
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
-typedef void (*CamelObjectClassInitFunc) (CamelObjectClass *);
-typedef void (*CamelObjectClassFinalizeFunc) (CamelObjectClass *);
-typedef void (*CamelObjectInitFunc) (CamelObject *, CamelObjectClass *);
-typedef void (*CamelObjectFinalizeFunc) (CamelObject *);
 
 typedef gboolean (*CamelObjectEventPrepFunc) (CamelObject *, gpointer);
 typedef void (*CamelObjectEventHookFunc) (CamelObject *, gpointer, gpointer);
 
-#define CAMEL_INVALID_TYPE (NULL)
-
 /* camel object args. */
 enum {
 	/* Get a description of the object. */
-	CAMEL_OBJECT_ARG_DESCRIPTION = CAMEL_ARG_FIRST,	/* Get a copy of the meta-data list (should be freed) */
+	CAMEL_OBJECT_ARG_DESCRIPTION = CAMEL_ARG_FIRST,
+	/* Get a copy of the meta-data list (should be freed) */
 	CAMEL_OBJECT_ARG_METADATA,
 	CAMEL_OBJECT_ARG_STATE_FILE,
 	CAMEL_OBJECT_ARG_PERSISTENT_PROPERTIES
@@ -106,10 +92,6 @@ enum {
 	CAMEL_OBJECT_PERSISTENT_PROPERTIES = CAMEL_OBJECT_ARG_PERSISTENT_PROPERTIES | CAMEL_ARG_PTR
 };
 
-typedef enum _CamelObjectFlags {
-	CAMEL_OBJECT_DESTROY = (1<<0)
-} CamelObjectFlags;
-
 /* returned by get::CAMEL_OBJECT_METADATA */
 struct _CamelObjectMeta {
 	struct _CamelObjectMeta *next;
@@ -118,58 +100,19 @@ struct _CamelObjectMeta {
 	gchar name[1];		/* allocated as part of structure */
 };
 
-/* TODO: create a simpleobject which has no events on it, or an interface for events */
 struct _CamelObject {
-	struct _CamelObjectClass *klass;
-
-	guint32 magic;		/* only really needed for debugging ... */
+	GObject parent;
 
 	/* current hooks on this object */
 	struct _CamelHookList *hooks;
-
-	guint32 ref_count:24;
-	guint32 flags:8;
-
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	struct _CamelObject *next, *prev;
-#endif
 };
 
-struct _CamelObjectClass
-{
-	struct _CamelObjectClass *parent;
-
-	guint32 magic;		/* in same spot for validation */
-
-	struct _CamelObjectClass *next, *child; /* maintain heirarchy, just for kicks */
-
-	const gchar *name;
-
-	gpointer lock;		/* lock when used in threading, else just pads struct */
-
-	/*unsigned short version, revision;*/
-
-	/* if the object's bigger than 64K, it could use redesigning */
-	unsigned short object_size/*, object_data*/;
-	unsigned short klass_size/*, klass_data*/;
+struct _CamelObjectClass {
+	GObjectClass parent_class;
 
 	/* available hooks for this class */
 	struct _CamelHookPair *hooks;
 
-	/* memchunks for this type */
-	struct _EMemChunk *instance_chunks;
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	struct _CamelObject *instances;
-#endif
-
-	/* init class */
-	void (*klass_init)(struct _CamelObjectClass *);
-	void (*klass_finalise)(struct _CamelObjectClass *);
-
-	/* init/finalise object */
-	void (*init)(struct _CamelObject *, struct _CamelObjectClass *);
-	void (*finalise)(struct _CamelObject *);
-
 	/* root-class fields follow, type system above */
 
 	/* get/set interface */
@@ -187,66 +130,10 @@ struct _CamelObjectClass
 	gint (*state_write)(struct _CamelObject *, FILE *fp);
 };
 
-#ifndef CAMEL_DISABLE_DEPRECATED
-/* an interface is just a class with no instance data */
-struct _CamelInterface {
-	struct _CamelObjectClass type;
-};
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
-/* The type system .... it's pretty simple..... */
-void camel_type_init (void);
-CamelType camel_type_register(CamelType parent, const gchar * name, /*guint ver, guint rev,*/
-			      gsize instance_size,
-			      gsize classfuncs_size,
-			      CamelObjectClassInitFunc class_init,
-			      CamelObjectClassFinalizeFunc  class_finalize,
-			      CamelObjectInitFunc instance_init,
-			      CamelObjectFinalizeFunc instance_finalize);
-
-#ifndef CAMEL_DISABLE_DEPRECATED
-CamelType camel_interface_register(CamelType parent, const gchar *name,
-				   gsize classfuncs_size,
-				   CamelObjectClassInitFunc class_init,
-				   CamelObjectClassFinalizeFunc class_finalize);
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
-/* deprecated interface */
-#define camel_type_get_global_classfuncs(x) ((CamelObjectClass *)(x))
-
 /* object class methods (types == classes now) */
-const gchar *camel_type_to_name (CamelType type);
-CamelType camel_name_to_type (const gchar *name);
 void camel_object_class_add_event (CamelObjectClass *klass, const gchar *name, CamelObjectEventPrepFunc prep);
-#ifndef CAMEL_DISABLE_DEPRECATED
-void camel_object_class_add_interface(CamelObjectClass *klass, CamelType itype);
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
-void camel_object_class_dump_tree (CamelType root);
-
-/* casting */
-CamelObject *camel_object_cast(CamelObject *obj, CamelType ctype);
-gboolean camel_object_is(CamelObject *obj, CamelType ctype);
-
-CamelObjectClass *camel_object_class_cast (CamelObjectClass *klass, CamelType ctype);
-gboolean camel_object_class_is (CamelObjectClass *klass, CamelType ctype);
-
-#ifndef CAMEL_DISABLE_DEPRECATED
-CamelObjectClass *camel_interface_cast(CamelObjectClass *klass, CamelType ctype);
-gboolean camel_interface_is(CamelObjectClass *k, CamelType ctype);
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
-CamelType camel_object_get_type (void);
-
-CamelObject *camel_object_new (CamelType type);
 
-void camel_object_ref(gpointer);
-void camel_object_unref(gpointer);
-
-#ifdef CAMEL_DEBUG
-#define camel_object_ref(o) (printf("%s (%s:%d):ref (%p)\n", __FUNCTION__, __FILE__, __LINE__, o), camel_object_ref(o))
-#define camel_object_unref(o) (printf("%s (%s:%d):unref (%p)\n", __FUNCTION__, __FILE__, __LINE__, o), camel_object_unref (o))
-#endif
+GType camel_object_get_type (void);
 
 /* hooks */
 CamelObjectHookID camel_object_hook_event(gpointer obj, const gchar *name, CamelObjectEventHookFunc hook, gpointer data);
@@ -254,11 +141,6 @@ void camel_object_remove_event(gpointer obj, CamelObjectHookID id);
 void camel_object_unhook_event(gpointer obj, const gchar *name, CamelObjectEventHookFunc hook, gpointer data);
 void camel_object_trigger_event(gpointer obj, const gchar *name, gpointer event_data);
 
-#ifndef CAMEL_DISABLE_DEPRECATED
-/* interfaces */
-gpointer camel_object_get_interface(gpointer vo, CamelType itype);
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
 /* get/set methods */
 gint camel_object_set(gpointer obj, struct _CamelException *ex, ...);
 gint camel_object_setv(gpointer obj, struct _CamelException *ex, CamelArgV *);
@@ -280,72 +162,6 @@ gint camel_object_state_write(gpointer vo);
 /* free a retrieved object.  May be a noop for static data. */
 void camel_object_free(gpointer vo, guint32 tag, gpointer value);
 
-/* for managing bags of weakly-ref'd 'child' objects */
-typedef struct _CamelObjectBag CamelObjectBag;
-typedef gpointer (*CamelCopyFunc)(gconstpointer vo);
-
-CamelObjectBag *camel_object_bag_new(GHashFunc hash, GEqualFunc equal, CamelCopyFunc keycopy, GFreeFunc keyfree);
-gpointer camel_object_bag_get(CamelObjectBag *bag, gconstpointer key);
-gpointer camel_object_bag_peek(CamelObjectBag *bag, gconstpointer key);
-gpointer camel_object_bag_reserve(CamelObjectBag *bag, gconstpointer key);
-void camel_object_bag_add(CamelObjectBag *bag, gconstpointer key, gpointer vo);
-void camel_object_bag_abort(CamelObjectBag *bag, gconstpointer key);
-void camel_object_bag_rekey(CamelObjectBag *bag, gpointer o, gconstpointer newkey);
-GPtrArray *camel_object_bag_list(CamelObjectBag *bag);
-void camel_object_bag_remove(CamelObjectBag *bag, gpointer o);
-void camel_object_bag_destroy(CamelObjectBag *bag);
-
-#define CAMEL_MAKE_CLASS(type, tname, parent, pname)				\
-static CamelType type##_type;							\
-static pname##Class * type##_parent_class;					\
-										\
-CamelType									\
-type##_get_type(void)								\
-{										\
-	if (type##_type == 0) {							\
-		type##_parent_class = (pname##Class *)parent##_get_type();	\
-		type##_type = camel_type_register(				\
-			type##_parent_class, #tname "Class",			\
-			sizeof(tname),						\
-			sizeof(tname ## Class),					\
-			(CamelObjectClassInitFunc) type##_class_init,		\
-			NULL,							\
-			(CamelObjectInitFunc) type##_init,			\
-			(CamelObjectFinalizeFunc) type##_finalise);		\
-	}									\
-										\
-	return type##_type;							\
-}
-
-#ifndef CAMEL_DISABLE_DEPRECATED
-/* Utility functions, not object specific, but too small to separate */
-typedef struct _CamelIteratorVTable CamelIteratorVTable;
-typedef struct _CamelIterator CamelIterator;
-
-struct _CamelIteratorVTable {
-	/* free fields, dont free base object */
-	void (*free)(gpointer it);
-	/* go to the next messageinfo */
-	gconstpointer (*next)(gpointer it, CamelException *ex);
-	/* go back to the start */
-	void (*reset)(gpointer it);
-	/* *ESTIMATE* how many results are in the iterator */
-	gint (*length)(gpointer it);
-};
-
-struct _CamelIterator {
-	CamelIteratorVTable *klass;
-
-	/* subclasses adds new fields afterwards */
-};
-
-gpointer camel_iterator_new(CamelIteratorVTable *klass, gsize size);
-void camel_iterator_free(gpointer it);
-gconstpointer camel_iterator_next(gpointer it, CamelException *ex);
-void camel_iterator_reset(gpointer it);
-gint camel_iterator_length(gpointer it);
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
 G_END_DECLS
 
 #endif /* CAMEL_OBJECT_H */
diff --git a/camel/camel-offline-folder.c b/camel/camel-offline-folder.c
index a8d941e..066d424 100644
--- a/camel/camel-offline-folder.c
+++ b/camel/camel-offline-folder.c
@@ -24,7 +24,6 @@
 #include <config.h>
 #endif
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-offline-folder.h"
@@ -32,18 +31,7 @@
 #include "camel-service.h"
 #include "camel-session.h"
 
-#define CAMEL_OFFLINE_FOLDER_GET_CLASS(f) (CAMEL_OFFLINE_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (f)))
-
-static void camel_offline_folder_class_init (CamelOfflineFolderClass *klass);
-static void camel_offline_folder_init (CamelOfflineFolder *folder, CamelOfflineFolderClass *klass);
-static void camel_offline_folder_finalize (CamelObject *object);
-
-static gint offline_folder_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
-static gint offline_folder_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
-
-static void offline_folder_downsync (CamelOfflineFolder *offline, const gchar *expression, CamelException *ex);
-
-static CamelFolderClass *parent_class = NULL;
+static gpointer parent_class;
 
 static GSList *offline_folder_props = NULL;
 
@@ -51,45 +39,6 @@ static CamelProperty offline_prop_list[] = {
 	{ CAMEL_OFFLINE_FOLDER_SYNC_OFFLINE, "sync_offline", N_("Copy folder content locally for offline operation") },
 };
 
-CamelType
-camel_offline_folder_get_type (void)
-{
-	static CamelType type = NULL;
-
-	if (!type) {
-		type = camel_type_register (CAMEL_FOLDER_TYPE,
-					    "CamelOfflineFolder",
-					    sizeof (CamelOfflineFolder),
-					    sizeof (CamelOfflineFolderClass),
-					    (CamelObjectClassInitFunc) camel_offline_folder_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_offline_folder_init,
-					    (CamelObjectFinalizeFunc) camel_offline_folder_finalize);
-	}
-
-	return type;
-}
-
-static void
-camel_offline_folder_class_init (CamelOfflineFolderClass *klass)
-{
-	gint i;
-
-	parent_class = (CamelFolderClass *) camel_type_get_global_classfuncs (CAMEL_FOLDER_TYPE);
-
-	if (offline_folder_props == NULL) {
-		for (i = 0; i < G_N_ELEMENTS (offline_prop_list); i++) {
-			offline_prop_list[i].description = _(offline_prop_list[i].description);
-			offline_folder_props = g_slist_prepend (offline_folder_props, &offline_prop_list[i]);
-		}
-	}
-
-	((CamelObjectClass *) klass)->getv = offline_folder_getv;
-	((CamelObjectClass *) klass)->setv = offline_folder_setv;
-
-	klass->downsync = offline_folder_downsync;
-}
-
 struct _offline_downsync_msg {
 	CamelSessionThreadMsg msg;
 
@@ -112,7 +61,7 @@ offline_downsync_sync (CamelSession *session, CamelSessionThreadMsg *mm)
 
 			camel_operation_progress (NULL, pc);
 			if ((message = camel_folder_get_message (m->folder, m->changes->uid_added->pdata[i], &mm->ex)))
-				camel_object_unref (message);
+				g_object_unref (message);
 		}
 	} else {
 		camel_offline_folder_downsync ((CamelOfflineFolder *) m->folder, "(match-all)", &mm->ex);
@@ -129,7 +78,7 @@ offline_downsync_free (CamelSession *session, CamelSessionThreadMsg *mm)
 	if (m->changes)
 		camel_folder_change_info_free (m->changes);
 
-	camel_object_unref (m->folder);
+	g_object_unref (m->folder);
 }
 
 static CamelSessionThreadOps offline_downsync_ops = {
@@ -150,27 +99,17 @@ offline_folder_changed (CamelFolder *folder, CamelFolderChangeInfo *changes, gpo
 		m = camel_session_thread_msg_new (session, &offline_downsync_ops, sizeof (*m));
 		m->changes = camel_folder_change_info_new ();
 		camel_folder_change_info_cat (m->changes, changes);
-		camel_object_ref (folder);
+		g_object_ref (folder);
 		m->folder = folder;
 
 		camel_session_thread_queue (session, &m->msg, 0);
 	}
 }
 
-static void
-camel_offline_folder_init (CamelOfflineFolder *folder, CamelOfflineFolderClass *klass)
-{
-	camel_object_hook_event (folder, "folder_changed", (CamelObjectEventHookFunc) offline_folder_changed, NULL);
-}
-
-static void
-camel_offline_folder_finalize (CamelObject *object)
-{
-	;
-}
-
 static gint
-offline_folder_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
+offline_folder_getv (CamelObject *object,
+                     CamelException *ex,
+                     CamelArgGetV *args)
 {
 	CamelArgGetV props;
 	gint i, count = 0;
@@ -207,7 +146,9 @@ offline_folder_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args
 }
 
 static gint
-offline_folder_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
+offline_folder_setv (CamelObject *object,
+                     CamelException *ex,
+                     CamelArgV *args)
 {
 	CamelOfflineFolder *folder = (CamelOfflineFolder *) object;
 	gboolean save = FALSE;
@@ -240,7 +181,9 @@ offline_folder_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
 }
 
 static void
-offline_folder_downsync (CamelOfflineFolder *offline, const gchar *expression, CamelException *ex)
+offline_folder_downsync (CamelOfflineFolder *offline,
+                         const gchar *expression,
+                         CamelException *ex)
 {
 	CamelFolder *folder = (CamelFolder *) offline;
 	GPtrArray *uids, *uncached_uids = NULL;
@@ -279,6 +222,55 @@ done:
 	camel_operation_end (NULL);
 }
 
+static void
+offline_folder_class_init (CamelOfflineFolderClass *class)
+{
+	CamelObjectClass *camel_object_class;
+	gint ii;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = offline_folder_getv;
+	camel_object_class->setv = offline_folder_setv;
+
+	class->downsync = offline_folder_downsync;
+
+	for (ii = 0; ii < G_N_ELEMENTS (offline_prop_list); ii++) {
+		offline_prop_list[ii].description =
+			_(offline_prop_list[ii].description);
+		offline_folder_props = g_slist_prepend (
+			offline_folder_props, &offline_prop_list[ii]);
+	}
+
+}
+
+static void
+offline_folder_init (CamelOfflineFolder *folder)
+{
+	camel_object_hook_event (
+		folder, "folder_changed",
+		(CamelObjectEventHookFunc) offline_folder_changed, NULL);
+}
+
+GType
+camel_offline_folder_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER,
+			"CamelOfflineFolder",
+			sizeof (CamelOfflineFolderClass),
+			(GClassInitFunc) offline_folder_class_init,
+			sizeof (CamelOfflineFolder),
+			(GInstanceInitFunc) offline_folder_init,
+			0);
+
+	return type;
+}
+
 /**
  * camel_offline_folder_downsync:
  * @offline: a #CamelOfflineFolder object
@@ -289,9 +281,16 @@ done:
  * the local machine for offline availability.
  **/
 void
-camel_offline_folder_downsync (CamelOfflineFolder *offline, const gchar *expression, CamelException *ex)
+camel_offline_folder_downsync (CamelOfflineFolder *offline,
+                               const gchar *expression,
+                               CamelException *ex)
 {
+	CamelOfflineFolderClass *class;
+
 	g_return_if_fail (CAMEL_IS_OFFLINE_FOLDER (offline));
 
-	CAMEL_OFFLINE_FOLDER_GET_CLASS (offline)->downsync (offline, expression, ex);
+	class = CAMEL_OFFLINE_FOLDER_GET_CLASS (offline);
+	g_return_if_fail (class->downsync != NULL);
+
+	class->downsync (offline, expression, ex);
 }
diff --git a/camel/camel-offline-folder.h b/camel/camel-offline-folder.h
index 34fa881..ea9d9e6 100644
--- a/camel/camel-offline-folder.h
+++ b/camel/camel-offline-folder.h
@@ -20,15 +20,33 @@
  *
  */
 
-#ifndef __CAMEL_OFFLINE_FOLDER_H__
-#define __CAMEL_OFFLINE_FOLDER_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_OFFLINE_FOLDER_H
+#define CAMEL_OFFLINE_FOLDER_H
 
 #include <camel/camel-folder.h>
 
-#define CAMEL_OFFLINE_FOLDER_TYPE     (camel_offline_folder_get_type ())
-#define CAMEL_OFFLINE_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_OFFLINE_FOLDER_TYPE, CamelOfflineFolder))
-#define CAMEL_OFFLINE_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_OFFLINE_FOLDER_TYPE, CamelOfflineFolderClass))
-#define CAMEL_IS_OFFLINE_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_OFFLINE_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_OFFLINE_FOLDER \
+	(camel_offline_folder_get_type ())
+#define CAMEL_OFFLINE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_OFFLINE_FOLDER, CamelOfflineFolder))
+#define CAMEL_OFFLINE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_OFFLINE_FOLDER, CamelOfflineFolderClass))
+#define CAMEL_IS_OFFLINE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_OFFLINE_FOLDER))
+#define CAMEL_IS_OFFLINE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_OFFLINE_FOLDER))
+#define CAMEL_OFFLINE_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_OFFLINE_FOLDER, CamelOfflineFolderClass))
 
 G_BEGIN_DECLS
 
@@ -45,7 +63,7 @@ enum {
 };
 
 struct _CamelOfflineFolder {
-	CamelFolder parent_object;
+	CamelFolder parent;
 
 	guint sync_offline:1;
 };
@@ -56,10 +74,10 @@ struct _CamelOfflineFolderClass {
 	void (* downsync) (CamelOfflineFolder *folder, const gchar *expression, CamelException *ex);
 };
 
-CamelType camel_offline_folder_get_type (void);
+GType camel_offline_folder_get_type (void);
 
 void camel_offline_folder_downsync (CamelOfflineFolder *offline, const gchar *expression, CamelException *ex);
 
 G_END_DECLS
 
-#endif /* __CAMEL_OFFLINE_FOLDER_H__ */
+#endif /* CAMEL_OFFLINE_FOLDER_H */
diff --git a/camel/camel-offline-journal.c b/camel/camel-offline-journal.c
index 09b36e0..85a0996 100644
--- a/camel/camel-offline-journal.c
+++ b/camel/camel-offline-journal.c
@@ -33,7 +33,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -46,55 +45,58 @@
 
 #define d(x)
 
-static void camel_offline_journal_class_init (CamelOfflineJournalClass *klass);
-static void camel_offline_journal_init (CamelOfflineJournal *journal, CamelOfflineJournalClass *klass);
-static void camel_offline_journal_finalize (CamelObject *object);
+static gpointer parent_class;
 
-static CamelObjectClass *parent_class = NULL;
-
-CamelType
-camel_offline_journal_get_type (void)
+static void
+offline_journal_finalize (GObject *object)
 {
-	static CamelType type = NULL;
-
-	if (!type) {
-		type = camel_type_register (camel_object_get_type (),
-					    "CamelOfflineJournal",
-					    sizeof (CamelOfflineJournal),
-					    sizeof (CamelOfflineJournalClass),
-					    (CamelObjectClassInitFunc) camel_offline_journal_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_offline_journal_init,
-					    (CamelObjectFinalizeFunc) camel_offline_journal_finalize);
-	}
+	CamelOfflineJournal *journal = CAMEL_OFFLINE_JOURNAL (object);
+	CamelDListNode *entry;
 
-	return type;
+	g_free (journal->filename);
+
+	while ((entry = camel_dlist_remhead (&journal->queue)))
+		CAMEL_OFFLINE_JOURNAL_GET_CLASS (journal)->entry_free (journal, entry);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_offline_journal_class_init (CamelOfflineJournalClass *klass)
+offline_journal_class_init (CamelOfflineJournalClass *class)
 {
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = offline_journal_finalize;
 }
 
 static void
-camel_offline_journal_init (CamelOfflineJournal *journal, CamelOfflineJournalClass *klass)
+offline_journal_init (CamelOfflineJournal *journal)
 {
 	journal->folder = NULL;
 	journal->filename = NULL;
 	camel_dlist_init (&journal->queue);
 }
 
-static void
-camel_offline_journal_finalize (CamelObject *object)
+GType
+camel_offline_journal_get_type (void)
 {
-	CamelOfflineJournal *journal = (CamelOfflineJournal *) object;
-	CamelDListNode *entry;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelOfflineJournal",
+			sizeof (CamelOfflineJournalClass),
+			(GClassInitFunc) offline_journal_class_init,
+			sizeof (CamelOfflineJournal),
+			(GInstanceInitFunc) offline_journal_init,
+			0);
 
-	g_free (journal->filename);
-
-	while ((entry = camel_dlist_remhead (&journal->queue)))
-		CAMEL_OFFLINE_JOURNAL_GET_CLASS (journal)->entry_free (journal, entry);
+	return type;
 }
 
 /**
diff --git a/camel/camel-offline-journal.h b/camel/camel-offline-journal.h
index ca05e59..ec21026 100644
--- a/camel/camel-offline-journal.h
+++ b/camel/camel-offline-journal.h
@@ -20,23 +20,37 @@
  *
  */
 
-#ifndef __CAMEL_OFFLINE_JOURNAL_H__
-#define __CAMEL_OFFLINE_JOURNAL_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_OFFLINE_JOURNAL_H
+#define CAMEL_OFFLINE_JOURNAL_H
 
 #include <stdio.h>
 #include <stdarg.h>
 
-#include <glib.h>
-
 #include <camel/camel-list-utils.h>
 #include <camel/camel-object.h>
 
-#define CAMEL_TYPE_OFFLINE_JOURNAL            (camel_offline_journal_get_type ())
-#define CAMEL_OFFLINE_JOURNAL(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_OFFLINE_JOURNAL, CamelOfflineJournal))
-#define CAMEL_OFFLINE_JOURNAL_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_OFFLINE_JOURNAL, CamelOfflineJournalClass))
-#define CAMEL_IS_OFFLINE_JOURNAL(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_OFFLINE_JOURNAL))
-#define CAMEL_IS_OFFLINE_JOURNAL_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_OFFLINE_JOURNAL))
-#define CAMEL_OFFLINE_JOURNAL_GET_CLASS(o) (CAMEL_OFFLINE_JOURNAL_CLASS (CAMEL_OBJECT_GET_CLASS (o)))
+/* Standard GObject macros */
+#define CAMEL_TYPE_OFFLINE_JOURNAL \
+	(camel_offline_journal_get_type ())
+#define CAMEL_OFFLINE_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_OFFLINE_JOURNAL, CamelOfflineJournal))
+#define CAMEL_OFFLINE_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_OFFLINE_JOURNAL, CamelOfflineJournalClass))
+#define CAMEL_IS_OFFLINE_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_OFFLINE_JOURNAL))
+#define CAMEL_IS_OFFLINE_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_OFFLINE_JOURNAL))
+#define CAMEL_OFFLINE_JOURNAL_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_OFFLINE_JOURNAL, CamelOfflineJournalClass))
 
 G_BEGIN_DECLS
 
@@ -47,7 +61,7 @@ typedef struct _CamelOfflineJournalEntry CamelOfflineJournalEntry;
 struct _CamelFolder;
 
 struct _CamelOfflineJournal {
-	CamelObject parent_object;
+	CamelObject parent;
 
 	struct _CamelFolder *folder;
 	gchar *filename;
@@ -65,7 +79,7 @@ struct _CamelOfflineJournalClass {
 	gint (* entry_play) (CamelOfflineJournal *journal, CamelDListNode *entry, CamelException *ex);
 };
 
-CamelType camel_offline_journal_get_type (void);
+GType camel_offline_journal_get_type (void);
 
 void camel_offline_journal_construct (CamelOfflineJournal *journal, struct _CamelFolder *folder, const gchar *filename);
 void camel_offline_journal_set_filename (CamelOfflineJournal *journal, const gchar *filename);
@@ -75,4 +89,4 @@ gint camel_offline_journal_replay (CamelOfflineJournal *journal, CamelException
 
 G_END_DECLS
 
-#endif /* __CAMEL_OFFLINE_JOURNAL_H__ */
+#endif /* CAMEL_OFFLINE_JOURNAL_H */
diff --git a/camel/camel-offline-store.c b/camel/camel-offline-store.c
index 4066bc8..eb7c0e1 100644
--- a/camel/camel-offline-store.c
+++ b/camel/camel-offline-store.c
@@ -24,7 +24,6 @@
 #include <config.h>
 #endif
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-folder.h"
@@ -32,68 +31,63 @@
 #include "camel-offline-store.h"
 #include "camel-session.h"
 
-static void camel_offline_store_class_init (CamelOfflineStoreClass *klass);
-static void camel_offline_store_init (CamelOfflineStore *store, CamelOfflineStoreClass *klass);
-static void camel_offline_store_finalize (CamelObject *object);
+static gpointer parent_class;
 
-static void offline_store_construct (CamelService *service, CamelSession *session,
-				     CamelProvider *provider, CamelURL *url,
-				     CamelException *ex);
+static void
+offline_store_construct (CamelService *service,
+                         CamelSession *session,
+                         CamelProvider *provider,
+                         CamelURL *url,
+                         CamelException *ex)
+{
+	CamelOfflineStore *store = CAMEL_OFFLINE_STORE (service);
+	CamelServiceClass *service_class;
 
-static CamelStoreClass *parent_class = NULL;
+	/* Chain up to parent's construct() method. */
+	service_class = CAMEL_SERVICE_CLASS (parent_class);
+	service_class->construct (service, session, provider, url, ex);
 
-CamelType
-camel_offline_store_get_type (void)
-{
-	static CamelType type = NULL;
-
-	if (!type) {
-		type = camel_type_register (CAMEL_STORE_TYPE,
-					    "CamelOfflineStore",
-					    sizeof (CamelOfflineStore),
-					    sizeof (CamelOfflineStoreClass),
-					    (CamelObjectClassInitFunc) camel_offline_store_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_offline_store_init,
-					    (CamelObjectFinalizeFunc) camel_offline_store_finalize);
-	}
+	if (camel_exception_is_set (ex))
+		return;
 
-	return type;
+	store->state = camel_session_is_online (session) ?
+		CAMEL_OFFLINE_STORE_NETWORK_AVAIL :
+		CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL;
 }
 
 static void
-camel_offline_store_class_init (CamelOfflineStoreClass *klass)
+offline_store_class_init (CamelOfflineStoreClass *class)
 {
-	parent_class = (CamelStoreClass *) camel_type_get_global_classfuncs (CAMEL_STORE_TYPE);
+	CamelServiceClass *service_class;
 
-	((CamelServiceClass *) klass)->construct = offline_store_construct;
-}
+	parent_class = g_type_class_peek_parent (class);
 
-static void
-camel_offline_store_init (CamelOfflineStore *store, CamelOfflineStoreClass *klass)
-{
-	store->state = CAMEL_OFFLINE_STORE_NETWORK_AVAIL;
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = offline_store_construct;
 }
 
 static void
-camel_offline_store_finalize (CamelObject *object)
+offline_store_init (CamelOfflineStore *store)
 {
-	;
+	store->state = CAMEL_OFFLINE_STORE_NETWORK_AVAIL;
 }
 
-static void
-offline_store_construct (CamelService *service, CamelSession *session,
-			  CamelProvider *provider, CamelURL *url,
-			  CamelException *ex)
+GType
+camel_offline_store_get_type (void)
 {
-	CamelOfflineStore *store = CAMEL_OFFLINE_STORE (service);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE,
+			"CamelOfflineStore",
+			sizeof (CamelOfflineStoreClass),
+			(GClassInitFunc) offline_store_class_init,
+			sizeof (CamelOfflineStore),
+			(GInstanceInitFunc) offline_store_init,
+			0);
 
-	CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
-	if (camel_exception_is_set (ex))
-		return;
-
-	store->state = camel_session_is_online (session) ?
-		CAMEL_OFFLINE_STORE_NETWORK_AVAIL : CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL;
+	return type;
 }
 
 /**
@@ -144,13 +138,13 @@ camel_offline_store_set_network_state (CamelOfflineStore *store, gint state, Cam
 				for (i = 0; i < folders->len; i++) {
 					folder = folders->pdata[i];
 
-					if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE)
+					if (G_TYPE_CHECK_INSTANCE_TYPE (folder, CAMEL_TYPE_OFFLINE_FOLDER)
 					    && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) {
 						camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex);
 						camel_exception_clear (&lex);
 					}
 
-					camel_object_unref (folder);
+					g_object_unref (folder);
 				}
 
 				g_ptr_array_free (folders, TRUE);
@@ -195,12 +189,12 @@ camel_offline_store_prepare_for_offline (CamelOfflineStore *store, CamelExceptio
 				for (i = 0; i < folders->len; i++) {
 					folder = folders->pdata[i];
 
-					if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE)
+					if (G_TYPE_CHECK_INSTANCE_TYPE (folder, CAMEL_TYPE_OFFLINE_FOLDER)
 					    && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) {
 						camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex);
 						camel_exception_clear (&lex);
 					}
-					camel_object_unref (folder);
+					g_object_unref (folder);
 				}
 				g_ptr_array_free (folders, TRUE);
 			}
diff --git a/camel/camel-offline-store.h b/camel/camel-offline-store.h
index 3fe60d1..4cde7c4 100644
--- a/camel/camel-offline-store.h
+++ b/camel/camel-offline-store.h
@@ -20,17 +20,33 @@
  *
  */
 
-#ifndef __CAMEL_OFFLINE_STORE_H__
-#define __CAMEL_OFFLINE_STORE_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_OFFLINE_STORE_H
+#define CAMEL_OFFLINE_STORE_H
 
 #include <camel/camel-store.h>
 
-#define CAMEL_TYPE_OFFLINE_STORE            (camel_offline_store_get_type ())
-#define CAMEL_OFFLINE_STORE(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_OFFLINE_STORE, CamelOfflineStore))
-#define CAMEL_OFFLINE_STORE_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_OFFLINE_STORE, CamelOfflineStoreClass))
-#define CAMEL_IS_OFFLINE_STORE(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_OFFLINE_STORE))
-#define CAMEL_IS_OFFLINE_STORE_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_OFFLINE_STORE))
-#define CAMEL_OFFLINE_STORE_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_OFFLINE_STORE, CamelOfflineStoreClass))
+/* Standard GObject macros */
+#define CAMEL_TYPE_OFFLINE_STORE \
+	(camel_offline_store_get_type ())
+#define CAMEL_OFFLINE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_OFFLINE_STORE, CamelOfflineStore))
+#define CAMEL_OFFLINE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_OFFLINE_STORE, CamelOfflineStoreClass))
+#define CAMEL_IS_OFFLINE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_OFFLINE_STORE))
+#define CAMEL_IS_OFFLINE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_OFFLINE_STORE))
+#define CAMEL_OFFLINE_STORE_GET_CLASS(obj) \
+	(CAMEL_CHECK_GET_CLASS \
+	((obj), CAMEL_TYPE_OFFLINE_STORE, CamelOfflineStoreClass))
 
 G_BEGIN_DECLS
 
@@ -47,7 +63,7 @@ enum {
 };
 
 struct _CamelOfflineStore {
-	CamelStore parent_object;
+	CamelStore parent;
 
 	gint state;
 };
@@ -58,7 +74,7 @@ struct _CamelOfflineStoreClass {
 	void (* set_network_state) (CamelOfflineStore *store, gint state, CamelException *ex);
 };
 
-CamelType camel_offline_store_get_type (void);
+GType camel_offline_store_get_type (void);
 
 void camel_offline_store_set_network_state (CamelOfflineStore *store, gint state, CamelException *ex);
 gint camel_offline_store_get_network_state (CamelOfflineStore *store, CamelException *ex);
@@ -67,4 +83,4 @@ void camel_offline_store_prepare_for_offline (CamelOfflineStore *store, CamelExc
 
 G_END_DECLS
 
-#endif /* __CAMEL_OFFLINE_STORE_H__ */
+#endif /* CAMEL_OFFLINE_STORE_H */
diff --git a/camel/camel-operation.c b/camel/camel-operation.c
index 2d87904..0a3e30e 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 5fff2af..0557fbf 100644
--- a/camel/camel-operation.h
+++ b/camel/camel-operation.h
@@ -19,8 +19,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_OPERATION_H
-#define CAMEL_OPERATION_H 1
+#define CAMEL_OPERATION_H
 
 #include <glib.h>
 
diff --git a/camel/camel-partition-table.c b/camel/camel-partition-table.c
index f721a34..66260e6 100644
--- a/camel/camel-partition-table.c
+++ b/camel/camel-partition-table.c
@@ -39,71 +39,80 @@
    tables consistent after program crash without sync */
 /*#define SYNC_UPDATES*/
 
-#define d(x) /*(printf("%s(%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
+#define d(x) /*(printf ("%s (%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
 /* key index debug */
-#define k(x) /*(printf("%s(%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
+#define k(x) /*(printf ("%s (%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
+
+#define CAMEL_PARTITION_TABLE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_PARTITION_TABLE, CamelPartitionTablePrivate))
 
 struct _CamelPartitionTablePrivate {
 	pthread_mutex_t lock;	/* for locking partition */
 };
 
-#define CAMEL_PARTITION_TABLE_LOCK(kf, lock) (pthread_mutex_lock(&(kf)->priv->lock))
-#define CAMEL_PARTITION_TABLE_UNLOCK(kf, lock) (pthread_mutex_unlock(&(kf)->priv->lock))
+#define CAMEL_PARTITION_TABLE_LOCK(kf, lock) (pthread_mutex_lock (&(kf)->priv->lock))
+#define CAMEL_PARTITION_TABLE_UNLOCK(kf, lock) (pthread_mutex_unlock (&(kf)->priv->lock))
 
-static void
-camel_partition_table_class_init(CamelPartitionTableClass *klass)
-{
-}
+static gpointer partition_table_parent_class;
 
 static void
-camel_partition_table_init(CamelPartitionTable *cpi)
+partition_table_finalize (GObject *object)
 {
-	struct _CamelPartitionTablePrivate *p;
+	CamelPartitionTable *table = CAMEL_PARTITION_TABLE (object);
+	CamelBlock *bl;
+
+	if (table->blocks) {
+		while ((bl = (CamelBlock *)camel_dlist_remhead (&table->partition))) {
+			camel_block_file_sync_block (table->blocks, bl);
+			camel_block_file_unref_block (table->blocks, bl);
+		}
+		camel_block_file_sync (table->blocks);
+
+		g_object_unref (table->blocks);
+	}
 
-	camel_dlist_init(&cpi->partition);
+	pthread_mutex_destroy (&table->priv->lock);
 
-	p = cpi->priv = g_malloc0(sizeof(*cpi->priv));
-	pthread_mutex_init(&p->lock, NULL);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (partition_table_parent_class)->finalize (object);
 }
 
 static void
-camel_partition_table_finalise(CamelPartitionTable *cpi)
+partition_table_class_init (CamelPartitionTableClass *class)
 {
-	CamelBlock *bl;
-	struct _CamelPartitionTablePrivate *p;
+	GObjectClass *object_class;
 
-	p = cpi->priv;
+	partition_table_parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelPartitionTablePrivate));
 
-	if (cpi->blocks) {
-		while ((bl = (CamelBlock *)camel_dlist_remhead(&cpi->partition))) {
-			camel_block_file_sync_block(cpi->blocks, bl);
-			camel_block_file_unref_block(cpi->blocks, bl);
-		}
-		camel_block_file_sync(cpi->blocks);
-
-		camel_object_unref((CamelObject *)cpi->blocks);
-	}
-
-	pthread_mutex_destroy(&p->lock);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = partition_table_finalize;
+}
 
-	g_free(p);
+static void
+partition_table_init (CamelPartitionTable *cpi)
+{
+	cpi->priv = CAMEL_PARTITION_TABLE_GET_PRIVATE (cpi);
 
+	camel_dlist_init (&cpi->partition);
+	pthread_mutex_init (&cpi->priv->lock, NULL);
 }
 
-CamelType
-camel_partition_table_get_type(void)
+GType
+camel_partition_table_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_object_get_type(), "CamelPartitionTable",
-					   sizeof (CamelPartitionTable),
-					   sizeof (CamelPartitionTableClass),
-					   (CamelObjectClassInitFunc) camel_partition_table_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_partition_table_init,
-					   (CamelObjectFinalizeFunc) camel_partition_table_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelPartitionTable",
+			sizeof (CamelPartitionTableClass),
+			(GClassInitFunc) partition_table_class_init,
+			sizeof (CamelPartitionTable),
+			(GInstanceInitFunc) partition_table_init,
+			0);
 
 	return type;
 }
@@ -126,7 +135,7 @@ lookup word, if nameid is deleted, mark it in wordlist as unused and mark for wr
 /* ********************************************************************** */
 
 /* This simple hash seems to work quite well */
-static camel_hash_t hash_key(const gchar *key)
+static camel_hash_t hash_key (const gchar *key)
 {
 	camel_hash_t hash = 0xABADF00D;
 
@@ -139,7 +148,7 @@ static camel_hash_t hash_key(const gchar *key)
 }
 
 /* Call with lock held */
-static CamelBlock *find_partition(CamelPartitionTable *cpi, camel_hash_t id, gint *indexp)
+static CamelBlock *find_partition (CamelPartitionTable *cpi, camel_hash_t id, gint *indexp)
 {
 	gint index, jump;
 	CamelBlock *bl;
@@ -179,40 +188,40 @@ static CamelBlock *find_partition(CamelPartitionTable *cpi, camel_hash_t id, gin
 		bl = bl->next;
 	}
 
-	g_warning("could not find a partition that could fit !  partition table corrupt!");
+	g_warning ("could not find a partition that could fit !  partition table corrupt!");
 
 	/* This should never be reached */
 
 	return NULL;
 }
 
-CamelPartitionTable *camel_partition_table_new(struct _CamelBlockFile *bs, camel_block_t root)
+CamelPartitionTable *camel_partition_table_new (struct _CamelBlockFile *bs, camel_block_t root)
 {
 	CamelPartitionTable *cpi;
 	CamelPartitionMapBlock *ptb;
 	CamelPartitionKeyBlock *kb;
 	CamelBlock *block, *pblock;
 
-	cpi = (CamelPartitionTable *)camel_object_new(camel_partition_table_get_type());
+	cpi = g_object_new (CAMEL_TYPE_PARTITION_TABLE, NULL);
 	cpi->rootid = root;
 	cpi->blocks = bs;
-	camel_object_ref((CamelObject *)bs);
+	g_object_ref (bs);
 
 	/* read the partition table into memory */
 	do {
-		block = camel_block_file_get_block(bs, root);
+		block = camel_block_file_get_block (bs, root);
 		if (block == NULL)
 			goto fail;
 
 		ptb = (CamelPartitionMapBlock *)&block->data;
 
-		d(printf("Adding partition block, used = %d, hashid = %08x\n", ptb->used, ptb->partition[0].hashid));
+		d (printf ("Adding partition block, used = %d, hashid = %08x\n", ptb->used, ptb->partition[0].hashid));
 
 		/* if we have no data, prime initial block */
-		if (ptb->used == 0 && camel_dlist_empty(&cpi->partition) && ptb->next == 0) {
-			pblock = camel_block_file_new_block(bs);
+		if (ptb->used == 0 && camel_dlist_empty (&cpi->partition) && ptb->next == 0) {
+			pblock = camel_block_file_new_block (bs);
 			if (pblock == NULL) {
-				camel_block_file_unref_block(bs, block);
+				camel_block_file_unref_block (bs, block);
 				goto fail;
 			}
 			kb = (CamelPartitionKeyBlock *)&pblock->data;
@@ -220,40 +229,40 @@ CamelPartitionTable *camel_partition_table_new(struct _CamelBlockFile *bs, camel
 			ptb->used = 1;
 			ptb->partition[0].hashid = 0xffffffff;
 			ptb->partition[0].blockid = pblock->id;
-			camel_block_file_touch_block(bs, pblock);
-			camel_block_file_unref_block(bs, pblock);
-			camel_block_file_touch_block(bs, block);
+			camel_block_file_touch_block (bs, pblock);
+			camel_block_file_unref_block (bs, pblock);
+			camel_block_file_touch_block (bs, block);
 #ifdef SYNC_UPDATES
-			camel_block_file_sync_block(bs, block);
+			camel_block_file_sync_block (bs, block);
 #endif
 		}
 
 		root = ptb->next;
-		camel_block_file_detach_block(bs, block);
-		camel_dlist_addtail(&cpi->partition, (CamelDListNode *)block);
+		camel_block_file_detach_block (bs, block);
+		camel_dlist_addtail (&cpi->partition, (CamelDListNode *)block);
 	} while (root);
 
 	return cpi;
 
 fail:
-	camel_object_unref((CamelObject *)cpi);
+	g_object_unref (cpi);
 	return NULL;
 }
 
 /* sync our blocks, the caller must still sync the blockfile itself */
 gint
-camel_partition_table_sync(CamelPartitionTable *cpi)
+camel_partition_table_sync (CamelPartitionTable *cpi)
 {
 	CamelBlock *bl, *bn;
 	gint ret = 0;
 
-	CAMEL_PARTITION_TABLE_LOCK(cpi, lock);
+	CAMEL_PARTITION_TABLE_LOCK (cpi, lock);
 
 	if (cpi->blocks) {
 		bl = (CamelBlock *)cpi->partition.head;
 		bn = bl->next;
 		while (bn) {
-			ret = camel_block_file_sync_block(cpi->blocks, bl);
+			ret = camel_block_file_sync_block (cpi->blocks, bl);
 			if (ret == -1)
 				goto fail;
 			bl = bn;
@@ -261,12 +270,12 @@ camel_partition_table_sync(CamelPartitionTable *cpi)
 		}
 	}
 fail:
-	CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+	CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 
 	return ret;
 }
 
-camel_key_t camel_partition_table_lookup(CamelPartitionTable *cpi, const gchar *key)
+camel_key_t camel_partition_table_lookup (CamelPartitionTable *cpi, const gchar *key)
 {
 	CamelPartitionKeyBlock *pkb;
 	CamelPartitionMapBlock *ptb;
@@ -275,19 +284,19 @@ camel_key_t camel_partition_table_lookup(CamelPartitionTable *cpi, const gchar *
 	camel_key_t keyid = 0;
 	gint index, i;
 
-	hashid = hash_key(key);
+	hashid = hash_key (key);
 
-	CAMEL_PARTITION_TABLE_LOCK(cpi, lock);
+	CAMEL_PARTITION_TABLE_LOCK (cpi, lock);
 
-	ptblock = find_partition(cpi, hashid, &index);
+	ptblock = find_partition (cpi, hashid, &index);
 	if (ptblock == NULL) {
-		CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+		CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 		return 0;
 	}
 	ptb = (CamelPartitionMapBlock *)&ptblock->data;
-	block = camel_block_file_get_block(cpi->blocks, ptb->partition[index].blockid);
+	block = camel_block_file_get_block (cpi->blocks, ptb->partition[index].blockid);
 	if (block == NULL) {
-		CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+		CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 		return 0;
 	}
 
@@ -297,20 +306,20 @@ camel_key_t camel_partition_table_lookup(CamelPartitionTable *cpi, const gchar *
 	for (i=0;i<pkb->used;i++) {
 		if (pkb->keys[i].hashid == hashid) {
 			/* !! need to: lookup and compare string value */
-			/* get_key() if key == key ... */
+			/* get_key () if key == key ... */
 			keyid = pkb->keys[i].keyid;
 			break;
 		}
 	}
 
-	CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+	CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 
-	camel_block_file_unref_block(cpi->blocks, block);
+	camel_block_file_unref_block (cpi->blocks, block);
 
 	return keyid;
 }
 
-void camel_partition_table_remove(CamelPartitionTable *cpi, const gchar *key)
+void camel_partition_table_remove (CamelPartitionTable *cpi, const gchar *key)
 {
 	CamelPartitionKeyBlock *pkb;
 	CamelPartitionMapBlock *ptb;
@@ -318,19 +327,19 @@ void camel_partition_table_remove(CamelPartitionTable *cpi, const gchar *key)
 	camel_hash_t hashid;
 	gint index, i;
 
-	hashid = hash_key(key);
+	hashid = hash_key (key);
 
-	CAMEL_PARTITION_TABLE_LOCK(cpi, lock);
+	CAMEL_PARTITION_TABLE_LOCK (cpi, lock);
 
-	ptblock = find_partition(cpi, hashid, &index);
+	ptblock = find_partition (cpi, hashid, &index);
 	if (ptblock == NULL) {
-		CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+		CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 		return;
 	}
 	ptb = (CamelPartitionMapBlock *)&ptblock->data;
-	block = camel_block_file_get_block(cpi->blocks, ptb->partition[index].blockid);
+	block = camel_block_file_get_block (cpi->blocks, ptb->partition[index].blockid);
 	if (block == NULL) {
-		CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+		CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 		return;
 	}
 	pkb = (CamelPartitionKeyBlock *)&block->data;
@@ -339,7 +348,7 @@ void camel_partition_table_remove(CamelPartitionTable *cpi, const gchar *key)
 	for (i=0;i<pkb->used;i++) {
 		if (pkb->keys[i].hashid == hashid) {
 			/* !! need to: lookup and compare string value */
-			/* get_key() if key == key ... */
+			/* get_key () if key == key ... */
 
 			/* remove this key */
 			pkb->used--;
@@ -347,18 +356,18 @@ void camel_partition_table_remove(CamelPartitionTable *cpi, const gchar *key)
 				pkb->keys[i].keyid = pkb->keys[i+1].keyid;
 				pkb->keys[i].hashid = pkb->keys[i+1].hashid;
 			}
-			camel_block_file_touch_block(cpi->blocks, block);
+			camel_block_file_touch_block (cpi->blocks, block);
 			break;
 		}
 	}
 
-	CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+	CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 
-	camel_block_file_unref_block(cpi->blocks, block);
+	camel_block_file_unref_block (cpi->blocks, block);
 }
 
 static gint
-keys_cmp(gconstpointer ap, gconstpointer bp)
+keys_cmp (gconstpointer ap, gconstpointer bp)
 {
 	const CamelPartitionKey *a = ap;
 	const CamelPartitionKey *b = bp;
@@ -372,7 +381,7 @@ keys_cmp(gconstpointer ap, gconstpointer bp)
 }
 
 gint
-camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_t keyid)
+camel_partition_table_add (CamelPartitionTable *cpi, const gchar *key, camel_key_t keyid)
 {
 	camel_hash_t hashid, partid;
 	gint index, newindex = 0; /* initialisation of this and pkb/nkb is just to silence compiler */
@@ -385,16 +394,16 @@ camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_
 
 	hashid = hash_key(key);
 
-	CAMEL_PARTITION_TABLE_LOCK(cpi, lock);
-	ptblock = find_partition(cpi, hashid, &index);
+	CAMEL_PARTITION_TABLE_LOCK (cpi, lock);
+	ptblock = find_partition (cpi, hashid, &index);
 	if (ptblock == NULL) {
-		CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+		CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 		return -1;
 	}
 	ptb = (CamelPartitionMapBlock *)&ptblock->data;
-	block = camel_block_file_get_block(cpi->blocks, ptb->partition[index].blockid);
+	block = camel_block_file_get_block (cpi->blocks, ptb->partition[index].blockid);
 	if (block == NULL) {
-		CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+		CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 		return -1;
 	}
 	kb = (CamelPartitionKeyBlock *)&block->data;
@@ -414,16 +423,16 @@ camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_
 		/* TODO: Should look at next/previous partition table block as well ... */
 
 		if (index > 0) {
-			pblock = camel_block_file_get_block(cpi->blocks, ptb->partition[index-1].blockid);
+			pblock = camel_block_file_get_block (cpi->blocks, ptb->partition[index-1].blockid);
 			if (pblock == NULL)
 				goto fail;
 			pkb = (CamelPartitionKeyBlock *)&pblock->data;
 		}
 		if (index < (ptb->used-1)) {
-			nblock = camel_block_file_get_block(cpi->blocks, ptb->partition[index+1].blockid);
+			nblock = camel_block_file_get_block (cpi->blocks, ptb->partition[index+1].blockid);
 			if (nblock == NULL) {
 				if (pblock)
-					camel_block_file_unref_block(cpi->blocks, pblock);
+					camel_block_file_unref_block (cpi->blocks, pblock);
 				goto fail;
 			}
 			nkb = (CamelPartitionKeyBlock *)&nblock->data;
@@ -454,15 +463,15 @@ camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_
 			/* See if we have room in the partition table for this block or need to split that too */
 			if (ptb->used >= G_N_ELEMENTS (ptb->partition)) {
 				/* TODO: Could check next block to see if it'll fit there first */
-				ptnblock = camel_block_file_new_block(cpi->blocks);
+				ptnblock = camel_block_file_new_block (cpi->blocks);
 				if (ptnblock == NULL) {
 					if (nblock)
-						camel_block_file_unref_block(cpi->blocks, nblock);
+						camel_block_file_unref_block (cpi->blocks, nblock);
 					if (pblock)
-						camel_block_file_unref_block(cpi->blocks, pblock);
+						camel_block_file_unref_block (cpi->blocks, pblock);
 					goto fail;
 				}
-				camel_block_file_detach_block(cpi->blocks, ptnblock);
+				camel_block_file_detach_block (cpi->blocks, ptnblock);
 
 				/* split block and link on-disk, always sorted */
 				ptn = (CamelPartitionMapBlock *)&ptnblock->data;
@@ -471,7 +480,7 @@ camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_
 				len = ptb->used / 2;
 				ptn->used = ptb->used - len;
 				ptb->used = len;
-				memcpy(ptn->partition, &ptb->partition[len], ptn->used * sizeof(ptb->partition[0]));
+				memcpy (ptn->partition, &ptb->partition[len], ptn->used * sizeof (ptb->partition[0]));
 
 				/* link in-memory */
 				ptnblock->next = ptblock->next;
@@ -480,14 +489,14 @@ camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_
 				ptnblock->prev = ptblock;
 
 				/* write in right order to ensure structure */
-				camel_block_file_touch_block(cpi->blocks, ptnblock);
+				camel_block_file_touch_block (cpi->blocks, ptnblock);
 #ifdef SYNC_UPDATES
-				camel_block_file_sync_block(cpi->blocks, ptnblock);
+				camel_block_file_sync_block (cpi->blocks, ptnblock);
 #endif
 				if (index > len) {
-					camel_block_file_touch_block(cpi->blocks, ptblock);
+					camel_block_file_touch_block (cpi->blocks, ptblock);
 #ifdef SYNC_UPDATES
-					camel_block_file_sync_block(cpi->blocks, ptblock);
+					camel_block_file_sync_block (cpi->blocks, ptblock);
 #endif
 					index -= len;
 					ptb = ptn;
@@ -496,12 +505,12 @@ camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_
 			}
 
 			/* try get newblock before modifying existing */
-			newblock = camel_block_file_new_block(cpi->blocks);
+			newblock = camel_block_file_new_block (cpi->blocks);
 			if (newblock == NULL) {
 				if (nblock)
-					camel_block_file_unref_block(cpi->blocks, nblock);
+					camel_block_file_unref_block (cpi->blocks, nblock);
 				if (pblock)
-					camel_block_file_unref_block(cpi->blocks, pblock);
+					camel_block_file_unref_block (cpi->blocks, pblock);
 				goto fail;
 			}
 
@@ -519,168 +528,178 @@ camel_partition_table_add(CamelPartitionTable *cpi, const gchar *key, camel_key_
 			ptb->partition[newindex].blockid = newblock->id;
 
 			if (nblock)
-				camel_block_file_unref_block(cpi->blocks, nblock);
+				camel_block_file_unref_block (cpi->blocks, nblock);
 			if (pblock)
-				camel_block_file_unref_block(cpi->blocks, pblock);
+				camel_block_file_unref_block (cpi->blocks, pblock);
 		} else {
 			newkb = (CamelPartitionKeyBlock *)&newblock->data;
 
 			if (newblock == pblock) {
 				if (nblock)
-					camel_block_file_unref_block(cpi->blocks, nblock);
+					camel_block_file_unref_block (cpi->blocks, nblock);
 			} else {
 				if (pblock)
-					camel_block_file_unref_block(cpi->blocks, pblock);
+					camel_block_file_unref_block (cpi->blocks, pblock);
 			}
 		}
 
 		/* sort keys to find midpoint */
 		len = kb->used;
-		memcpy(keys, kb->keys, sizeof(kb->keys[0])*len);
-		memcpy(keys+len, newkb->keys, sizeof(newkb->keys[0])*newkb->used);
+		memcpy (keys, kb->keys, sizeof (kb->keys[0])*len);
+		memcpy (keys+len, newkb->keys, sizeof (newkb->keys[0])*newkb->used);
 		len += newkb->used;
 		keys[len].hashid = hashid;
 		keys[len].keyid = keyid;
 		len++;
-		qsort(keys, len, sizeof(keys[0]), keys_cmp);
+		qsort (keys, len, sizeof (keys[0]), keys_cmp);
 
 		/* Split keys, fix partition table */
 		half = len/2;
 		partid = keys[half-1].hashid;
 
 		if (index < newindex) {
-			memcpy(kb->keys, keys, sizeof(keys[0])*half);
+			memcpy (kb->keys, keys, sizeof (keys[0])*half);
 			kb->used = half;
-			memcpy(newkb->keys, keys+half, sizeof(keys[0])*(len-half));
+			memcpy (newkb->keys, keys+half, sizeof (keys[0])*(len-half));
 			newkb->used = len-half;
 			ptb->partition[index].hashid = partid;
 		} else {
-			memcpy(newkb->keys, keys, sizeof(keys[0])*half);
+			memcpy (newkb->keys, keys, sizeof (keys[0])*half);
 			newkb->used = half;
-			memcpy(kb->keys, keys+half, sizeof(keys[0])*(len-half));
+			memcpy (kb->keys, keys+half, sizeof (keys[0])*(len-half));
 			kb->used = len-half;
 			ptb->partition[newindex].hashid = partid;
 		}
 
-		camel_block_file_touch_block(cpi->blocks, ptblock);
+		camel_block_file_touch_block (cpi->blocks, ptblock);
 #ifdef SYNC_UPDATES
-		camel_block_file_sync_block(cpi->blocks, ptblock);
+		camel_block_file_sync_block (cpi->blocks, ptblock);
 #endif
-		camel_block_file_touch_block(cpi->blocks, newblock);
-		camel_block_file_unref_block(cpi->blocks, newblock);
+		camel_block_file_touch_block (cpi->blocks, newblock);
+		camel_block_file_unref_block (cpi->blocks, newblock);
 	}
 
-	camel_block_file_touch_block(cpi->blocks, block);
-	camel_block_file_unref_block(cpi->blocks, block);
+	camel_block_file_touch_block (cpi->blocks, block);
+	camel_block_file_unref_block (cpi->blocks, block);
 
 	ret = 0;
 fail:
-	CAMEL_PARTITION_TABLE_UNLOCK(cpi, lock);
+	CAMEL_PARTITION_TABLE_UNLOCK (cpi, lock);
 
 	return ret;
 }
 
 /* ********************************************************************** */
 
+#define CAMEL_KEY_TABLE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_KEY_TABLE, CamelKeyTablePrivate))
+
 struct _CamelKeyTablePrivate {
 	pthread_mutex_t lock;	/* for locking key */
 };
 
-#define CAMEL_KEY_TABLE_LOCK(kf, lock) (pthread_mutex_lock(&(kf)->priv->lock))
-#define CAMEL_KEY_TABLE_UNLOCK(kf, lock) (pthread_mutex_unlock(&(kf)->priv->lock))
+#define CAMEL_KEY_TABLE_LOCK(kf, lock) (pthread_mutex_lock (&(kf)->priv->lock))
+#define CAMEL_KEY_TABLE_UNLOCK(kf, lock) (pthread_mutex_unlock (&(kf)->priv->lock))
 
-static void
-camel_key_table_class_init(CamelKeyTableClass *klass)
-{
-}
+static gpointer key_table_parent_class;
 
 static void
-camel_key_table_init(CamelKeyTable *ki)
+key_table_finalize (GObject *object)
 {
-	struct _CamelKeyTablePrivate *p;
+	CamelKeyTable *table = CAMEL_KEY_TABLE (object);
+
+	if (table->blocks) {
+		if (table->root_block) {
+			camel_block_file_sync_block (table->blocks, table->root_block);
+			camel_block_file_unref_block (table->blocks, table->root_block);
+		}
+		camel_block_file_sync (table->blocks);
+		g_object_unref (table->blocks);
+	}
+
+	pthread_mutex_destroy (&table->priv->lock);
 
-	p = ki->priv = g_malloc0(sizeof(*ki->priv));
-	pthread_mutex_init(&p->lock, NULL);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (key_table_parent_class)->finalize (object);
 }
 
 static void
-camel_key_table_finalise(CamelKeyTable *ki)
+key_table_class_init (CamelKeyTableClass *class)
 {
-	struct _CamelKeyTablePrivate *p;
-
-	p = ki->priv;
+	GObjectClass *object_class;
 
-	if (ki->blocks) {
-		if (ki->root_block) {
-			camel_block_file_sync_block(ki->blocks, ki->root_block);
-			camel_block_file_unref_block(ki->blocks, ki->root_block);
-		}
-		camel_block_file_sync(ki->blocks);
-		camel_object_unref((CamelObject *)ki->blocks);
-	}
+	key_table_parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelKeyTablePrivate));
 
-	pthread_mutex_destroy(&p->lock);
-
-	g_free(p);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = key_table_finalize;
+}
 
+static void
+key_table_init (CamelKeyTable *table)
+{
+	table->priv = CAMEL_KEY_TABLE_GET_PRIVATE (table);
+	pthread_mutex_init (&table->priv->lock, NULL);
 }
 
-CamelType
-camel_key_table_get_type(void)
+GType
+camel_key_table_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_object_get_type(), "CamelKeyTable",
-					   sizeof (CamelKeyTable),
-					   sizeof (CamelKeyTableClass),
-					   (CamelObjectClassInitFunc) camel_key_table_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_key_table_init,
-					   (CamelObjectFinalizeFunc) camel_key_table_finalise);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID)) {
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelKeyTable",
+			sizeof (CamelKeyTableClass),
+			(GClassInitFunc) key_table_class_init,
+			sizeof (CamelKeyTable),
+			(GInstanceInitFunc) key_table_init,
+			0);
 	}
 
 	return type;
 }
 
 CamelKeyTable *
-camel_key_table_new(CamelBlockFile *bs, camel_block_t root)
+camel_key_table_new (CamelBlockFile *bs, camel_block_t root)
 {
 	CamelKeyTable *ki;
 
-	ki = (CamelKeyTable *)camel_object_new(camel_key_table_get_type());
+	ki = g_object_new (CAMEL_TYPE_KEY_TABLE, NULL);
 
 	ki->blocks = bs;
-	camel_object_ref((CamelObject *)bs);
+	g_object_ref (bs);
 	ki->rootid = root;
 
-	ki->root_block = camel_block_file_get_block(bs, ki->rootid);
+	ki->root_block = camel_block_file_get_block (bs, ki->rootid);
 	if (ki->root_block == NULL) {
-		camel_object_unref((CamelObject *)ki);
+		g_object_unref (ki);
 		ki = NULL;
 	} else {
-		camel_block_file_detach_block(bs, ki->root_block);
+		camel_block_file_detach_block (bs, ki->root_block);
 		ki->root = (CamelKeyRootBlock *)&ki->root_block->data;
 
-		k(printf("Opening key index\n"));
-		k(printf(" first %u\n last %u\n free %u\n", ki->root->first, ki->root->last, ki->root->free));
+		k (printf ("Opening key index\n"));
+		k (printf (" first %u\n last %u\n free %u\n", ki->root->first, ki->root->last, ki->root->free));
 	}
 
 	return ki;
 }
 
 gint
-camel_key_table_sync(CamelKeyTable *ki)
+camel_key_table_sync (CamelKeyTable *ki)
 {
 #ifdef SYNC_UPDATES
 	return 0;
 #else
-	return camel_block_file_sync_block(ki->blocks, ki->root_block);
+	return camel_block_file_sync_block (ki->blocks, ki->root_block);
 #endif
 }
 
 camel_key_t
-camel_key_table_add(CamelKeyTable *ki, const gchar *key, camel_block_t data, guint flags)
+camel_key_table_add (CamelKeyTable *ki, const gchar *key, camel_block_t data, guint flags)
 {
 	CamelBlock *last, *next;
 	CamelKeyBlock *kblast, *kbnext;
@@ -689,21 +708,21 @@ camel_key_table_add(CamelKeyTable *ki, const gchar *key, camel_block_t data, gui
 	camel_key_t keyid = 0;
 
 	/* Maximum key size = 128 chars */
-	len = strlen(key);
+	len = strlen (key);
 	if (len > CAMEL_KEY_TABLE_MAX_KEY)
 		len = 128;
 
-	CAMEL_KEY_TABLE_LOCK(ki, lock);
+	CAMEL_KEY_TABLE_LOCK (ki, lock);
 
 	if (ki->root->last == 0) {
-		last = camel_block_file_new_block(ki->blocks);
+		last = camel_block_file_new_block (ki->blocks);
 		if (last == NULL)
 			goto fail;
 		ki->root->last = ki->root->first = last->id;
-		camel_block_file_touch_block(ki->blocks, ki->root_block);
-		k(printf("adding first block, first = %u\n", ki->root->first));
+		camel_block_file_touch_block (ki->blocks, ki->root_block);
+		k (printf ("adding first block, first = %u\n", ki->root->first));
 	} else {
-		last = camel_block_file_get_block(ki->blocks, ki->root->last);
+		last = camel_block_file_get_block (ki->blocks, ki->root->last);
 		if (last == NULL)
 			goto fail;
 	}
@@ -715,24 +734,24 @@ camel_key_table_add(CamelKeyTable *ki, const gchar *key, camel_block_t data, gui
 
 	if (kblast->used > 0) {
 		/*left = &kblast->u.keydata[kblast->u.keys[kblast->used-1].offset] - (gchar *)(&kblast->u.keys[kblast->used+1]);*/
-		left = kblast->u.keys[kblast->used-1].offset - sizeof(kblast->u.keys[0])*(kblast->used+1);
-		d(printf("key '%s' used = %d (%d), filled = %d, left = %d  len = %d?\n",
-			 key, kblast->used, kblast->used * sizeof(kblast->u.keys[0]),
-			 sizeof(kblast->u.keydata) - kblast->u.keys[kblast->used-1].offset,
+		left = kblast->u.keys[kblast->used-1].offset - sizeof (kblast->u.keys[0])*(kblast->used+1);
+		d (printf ("key '%s' used = %d (%d), filled = %d, left = %d  len = %d?\n",
+			 key, kblast->used, kblast->used * sizeof (kblast->u.keys[0]),
+			 sizeof (kblast->u.keydata) - kblast->u.keys[kblast->used-1].offset,
 			 left, len));
 		if (left < len) {
-			next = camel_block_file_new_block(ki->blocks);
+			next = camel_block_file_new_block (ki->blocks);
 			if (next == NULL) {
-				camel_block_file_unref_block(ki->blocks, last);
+				camel_block_file_unref_block (ki->blocks, last);
 				goto fail;
 			}
 			kbnext = (CamelKeyBlock *)&next->data;
 			kblast->next = next->id;
 			ki->root->last = next->id;
-			d(printf("adding new block, first = %u, last = %u\n", ki->root->first, ki->root->last));
-			camel_block_file_touch_block(ki->blocks, ki->root_block);
-			camel_block_file_touch_block(ki->blocks, last);
-			camel_block_file_unref_block(ki->blocks, last);
+			d (printf ("adding new block, first = %u, last = %u\n", ki->root->first, ki->root->last));
+			camel_block_file_touch_block (ki->blocks, ki->root_block);
+			camel_block_file_touch_block (ki->blocks, last);
+			camel_block_file_unref_block (ki->blocks, last);
 			kblast = kbnext;
 			last = next;
 		}
@@ -741,40 +760,40 @@ camel_key_table_add(CamelKeyTable *ki, const gchar *key, camel_block_t data, gui
 	if (kblast->used > 0)
 		offset = kblast->u.keys[kblast->used-1].offset - len;
 	else
-		offset = sizeof(kblast->u.keydata)-len;
+		offset = sizeof (kblast->u.keydata)-len;
 
 	kblast->u.keys[kblast->used].flags = flags;
 	kblast->u.keys[kblast->used].data = data;
 	kblast->u.keys[kblast->used].offset = offset;
-	memcpy(kblast->u.keydata + offset, key, len);
+	memcpy (kblast->u.keydata + offset, key, len);
 
 	keyid = (last->id & (~(CAMEL_BLOCK_SIZE-1))) | kblast->used;
 
 	kblast->used++;
 
 #if 0
-	g_assert(kblast->used < 127);
+	g_assert (kblast->used < 127);
 #else
 	if (kblast->used >=127) {
-		g_warning("Invalid value for used %d\n", kblast->used);
+		g_warning ("Invalid value for used %d\n", kblast->used);
 		return 0;
 	}
 #endif
 
-	camel_block_file_touch_block(ki->blocks, last);
-	camel_block_file_unref_block(ki->blocks, last);
+	camel_block_file_touch_block (ki->blocks, last);
+	camel_block_file_unref_block (ki->blocks, last);
 
 #ifdef SYNC_UPDATES
-	camel_block_file_sync_block(ki->blocks, ki->root_block);
+	camel_block_file_sync_block (ki->blocks, ki->root_block);
 #endif
 fail:
-	CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+	CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 
 	return keyid;
 }
 
 void
-camel_key_table_set_data(CamelKeyTable *ki, camel_key_t keyid, camel_block_t data)
+camel_key_table_set_data (CamelKeyTable *ki, camel_key_t keyid, camel_block_t data)
 {
 	CamelBlock *bl;
 	camel_block_t blockid;
@@ -787,25 +806,25 @@ camel_key_table_set_data(CamelKeyTable *ki, camel_key_t keyid, camel_block_t dat
 	blockid =  keyid & (~(CAMEL_BLOCK_SIZE-1));
 	index = keyid & (CAMEL_BLOCK_SIZE-1);
 
-	bl = camel_block_file_get_block(ki->blocks, blockid);
+	bl = camel_block_file_get_block (ki->blocks, blockid);
 	if (bl == NULL)
 		return;
 	kb = (CamelKeyBlock *)&bl->data;
 
-	CAMEL_KEY_TABLE_LOCK(ki, lock);
+	CAMEL_KEY_TABLE_LOCK (ki, lock);
 
 	if (kb->u.keys[index].data != data) {
 		kb->u.keys[index].data = data;
-		camel_block_file_touch_block(ki->blocks, bl);
+		camel_block_file_touch_block (ki->blocks, bl);
 	}
 
-	CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+	CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 
-	camel_block_file_unref_block(ki->blocks, bl);
+	camel_block_file_unref_block (ki->blocks, bl);
 }
 
 void
-camel_key_table_set_flags(CamelKeyTable *ki, camel_key_t keyid, guint flags, guint set)
+camel_key_table_set_flags (CamelKeyTable *ki, camel_key_t keyid, guint flags, guint set)
 {
 	CamelBlock *bl;
 	camel_block_t blockid;
@@ -819,36 +838,36 @@ camel_key_table_set_flags(CamelKeyTable *ki, camel_key_t keyid, guint flags, gui
 	blockid =  keyid & (~(CAMEL_BLOCK_SIZE-1));
 	index = keyid & (CAMEL_BLOCK_SIZE-1);
 
-	bl = camel_block_file_get_block(ki->blocks, blockid);
+	bl = camel_block_file_get_block (ki->blocks, blockid);
 	if (bl == NULL)
 		return;
 	kb = (CamelKeyBlock *)&bl->data;
 
 #if 0
-	g_assert(kb->used < 127); /* this should be more accurate */
-	g_assert(index < kb->used);
+	g_assert (kb->used < 127); /* this should be more accurate */
+	g_assert (index < kb->used);
 #else
 	if (kb->used >=127 || index >= kb->used) {
-		g_warning("Block %x: Invalid index or content: index %d used %d\n", blockid, index, kb->used);
+		g_warning ("Block %x: Invalid index or content: index %d used %d\n", blockid, index, kb->used);
 		return;
 	}
 #endif
 
-	CAMEL_KEY_TABLE_LOCK(ki, lock);
+	CAMEL_KEY_TABLE_LOCK (ki, lock);
 
 	old = kb->u.keys[index].flags;
 	if ((old & set) != (flags & set)) {
 		kb->u.keys[index].flags = (old & (~set)) | (flags & set);
-		camel_block_file_touch_block(ki->blocks, bl);
+		camel_block_file_touch_block (ki->blocks, bl);
 	}
 
-	CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+	CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 
-	camel_block_file_unref_block(ki->blocks, bl);
+	camel_block_file_unref_block (ki->blocks, bl);
 }
 
 camel_block_t
-camel_key_table_lookup(CamelKeyTable *ki, camel_key_t keyid, gchar **keyp, guint *flags)
+camel_key_table_lookup (CamelKeyTable *ki, camel_key_t keyid, gchar **keyp, guint *flags)
 {
 	CamelBlock *bl;
 	camel_block_t blockid;
@@ -866,23 +885,23 @@ camel_key_table_lookup(CamelKeyTable *ki, camel_key_t keyid, gchar **keyp, guint
 	blockid =  keyid & (~(CAMEL_BLOCK_SIZE-1));
 	index = keyid & (CAMEL_BLOCK_SIZE-1);
 
-	bl = camel_block_file_get_block(ki->blocks, blockid);
+	bl = camel_block_file_get_block (ki->blocks, blockid);
 	if (bl == NULL)
 		return 0;
 
 	kb = (CamelKeyBlock *)&bl->data;
 
 #if 0
-	g_assert(kb->used < 127); /* this should be more accurate */
-	g_assert(index < kb->used);
+	g_assert (kb->used < 127); /* this should be more accurate */
+	g_assert (index < kb->used);
 #else
 	if (kb->used >=127 || index >= kb->used) {
-		g_warning("Block %x: Invalid index or content: index %d used %d\n", blockid, index, kb->used);
+		g_warning ("Block %x: Invalid index or content: index %d used %d\n", blockid, index, kb->used);
 		return 0;
 	}
 #endif
 
-	CAMEL_KEY_TABLE_LOCK(ki, lock);
+	CAMEL_KEY_TABLE_LOCK (ki, lock);
 
 	blockid = kb->u.keys[index].data;
 	if (flags)
@@ -891,24 +910,24 @@ camel_key_table_lookup(CamelKeyTable *ki, camel_key_t keyid, gchar **keyp, guint
 	if (keyp) {
 		off = kb->u.keys[index].offset;
 		if (index == 0)
-			len = sizeof(kb->u.keydata) - off;
+			len = sizeof (kb->u.keydata) - off;
 		else
 			len = kb->u.keys[index-1].offset - off;
-		*keyp = key = g_malloc(len+1);
-		memcpy(key, kb->u.keydata + off, len);
+		*keyp = key = g_malloc (len+1);
+		memcpy (key, kb->u.keydata + off, len);
 		key[len] = 0;
 	}
 
-	CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+	CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 
-	camel_block_file_unref_block(ki->blocks, bl);
+	camel_block_file_unref_block (ki->blocks, bl);
 
 	return blockid;
 }
 
 /* iterate through all keys */
 camel_key_t
-camel_key_table_next(CamelKeyTable *ki, camel_key_t next, gchar **keyp, guint *flagsp, camel_block_t *datap)
+camel_key_table_next (CamelKeyTable *ki, camel_key_t next, gchar **keyp, guint *flagsp, camel_block_t *datap)
 {
 	CamelBlock *bl;
 	CamelKeyBlock *kb;
@@ -922,12 +941,12 @@ camel_key_table_next(CamelKeyTable *ki, camel_key_t next, gchar **keyp, guint *f
 	if (datap)
 		*datap = 0;
 
-	CAMEL_KEY_TABLE_LOCK(ki, lock);
+	CAMEL_KEY_TABLE_LOCK (ki, lock);
 
 	if (next == 0) {
 		next = ki->root->first;
 		if (next == 0) {
-			CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+			CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 			return 0;
 		}
 	} else
@@ -937,9 +956,9 @@ camel_key_table_next(CamelKeyTable *ki, camel_key_t next, gchar **keyp, guint *f
 		blockid =  next & (~(CAMEL_BLOCK_SIZE-1));
 		index = next & (CAMEL_BLOCK_SIZE-1);
 
-		bl = camel_block_file_get_block(ki->blocks, blockid);
+		bl = camel_block_file_get_block (ki->blocks, blockid);
 		if (bl == NULL) {
-			CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+			CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 			return 0;
 		}
 
@@ -949,22 +968,22 @@ camel_key_table_next(CamelKeyTable *ki, camel_key_t next, gchar **keyp, guint *f
 		if (index >= kb->used) {
 			/* FIXME: check for loops */
 			next = kb->next;
-			camel_block_file_unref_block(ki->blocks, bl);
+			camel_block_file_unref_block (ki->blocks, bl);
 			bl = NULL;
 		}
 	} while (bl == NULL);
 
 	/* invalid block data */
-	if ((kb->u.keys[index].offset >= sizeof(kb->u.keydata)
+	if ((kb->u.keys[index].offset >= sizeof (kb->u.keydata)
 	     /*|| kb->u.keys[index].offset < kb->u.keydata - (gchar *)&kb->u.keys[kb->used])*/
-	     || kb->u.keys[index].offset < sizeof(kb->u.keys[0]) * kb->used
+	     || kb->u.keys[index].offset < sizeof (kb->u.keys[0]) * kb->used
 	    || (index > 0 &&
-		(kb->u.keys[index-1].offset >= sizeof(kb->u.keydata)
+		(kb->u.keys[index-1].offset >= sizeof (kb->u.keydata)
 		 /*|| kb->u.keys[index-1].offset < kb->u.keydata - (gchar *)&kb->u.keys[kb->used]))) {*/
-		 || kb->u.keys[index-1].offset < sizeof(kb->u.keys[0]) * kb->used)))) {
-		g_warning("Block %u invalid scanning keys", bl->id);
-		camel_block_file_unref_block(ki->blocks, bl);
-		CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+		 || kb->u.keys[index-1].offset < sizeof (kb->u.keys[0]) * kb->used)))) {
+		g_warning ("Block %u invalid scanning keys", bl->id);
+		camel_block_file_unref_block (ki->blocks, bl);
+		CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 		return 0;
 	}
 
@@ -979,17 +998,17 @@ camel_key_table_next(CamelKeyTable *ki, camel_key_t next, gchar **keyp, guint *f
 		gchar *key;
 
 		if (index == 0)
-			len = sizeof(kb->u.keydata) - off;
+			len = sizeof (kb->u.keydata) - off;
 		else
 			len = kb->u.keys[index-1].offset - off;
-		*keyp = key = g_malloc(len+1);
-		memcpy(key, kb->u.keydata + off, len);
+		*keyp = key = g_malloc (len+1);
+		memcpy (key, kb->u.keydata + off, len);
 		key[len] = 0;
 	}
 
-	CAMEL_KEY_TABLE_UNLOCK(ki, lock);
+	CAMEL_KEY_TABLE_UNLOCK (ki, lock);
 
-	camel_block_file_unref_block(ki->blocks, bl);
+	camel_block_file_unref_block (ki->blocks, bl);
 
 	return next;
 }
diff --git a/camel/camel-partition-table.h b/camel/camel-partition-table.h
index 92c4419..8b22e57 100644
--- a/camel/camel-partition-table.h
+++ b/camel/camel-partition-table.h
@@ -18,15 +18,55 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_PARTITION_TABLE_H
-#define _CAMEL_PARTITION_TABLE_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_PARTITION_TABLE_H
+#define CAMEL_PARTITION_TABLE_H
 
 #include <camel/camel-object.h>
-#include <glib.h>
 
 #include "camel-block-file.h"
 #include "camel-list-utils.h"
 
+/* Standard GObject macros */
+#define CAMEL_TYPE_PARTITION_TABLE \
+	(camel_partition_table_get_type ())
+#define CAMEL_PARTITION_TABLE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_PARTITION_TABLE, CamelPartitionTable))
+#define CAMEL_PARTITION_TABLE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_PARTITION_TABLE, CamelPartitionTableClass))
+#define CAMEL_IS_PARTITION_TABLE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_PARTITION_TABLE))
+#define CAMEL_IS_PARTITION_TABLE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_PARTITION_TABLE))
+#define CAMEL_PARTITION_TABLE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_PARTITION_TABLE, CamelPartitionTableClass))
+
+#define CAMEL_TYPE_KEY_TABLE \
+	(camel_key_table_get_type ())
+#define CAMEL_KEY_TABLE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_KEY_TABLE, CamelKeyTable))
+#define CAMEL_KEY_TABLE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_KEY_TABLE, CamelKeyTableClass))
+#define CAMEL_IS_KEY_TABLE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_KEY_TABLE))
+#define CAMEL_IS_KEY_TABLE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_KEY_TABLE))
+#define CAMEL_KEY_TABLE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_KEY_TABLE, CamelKeyTableClass))
+
 G_BEGIN_DECLS
 
 /* ********************************************************************** */
@@ -42,6 +82,7 @@ typedef struct _CamelPartitionMapBlock CamelPartitionMapBlock;
 
 typedef struct _CamelPartitionTable CamelPartitionTable;
 typedef struct _CamelPartitionTableClass CamelPartitionTableClass;
+typedef struct _CamelPartitionTablePrivate CamelPartitionTablePrivate;
 
 struct _CamelPartitionKey {
 	camel_hash_t hashid;
@@ -66,8 +107,7 @@ struct _CamelPartitionMapBlock {
 
 struct _CamelPartitionTable {
 	CamelObject parent;
-
-	struct _CamelPartitionTablePrivate *priv;
+	CamelPartitionTablePrivate *priv;
 
 	CamelBlockFile *blocks;
 	camel_block_t rootid;
@@ -83,7 +123,7 @@ struct _CamelPartitionTableClass {
 	CamelObjectClass parent;
 };
 
-CamelType camel_partition_table_get_type(void);
+GType camel_partition_table_get_type(void);
 
 CamelPartitionTable *camel_partition_table_new(struct _CamelBlockFile *bs, camel_block_t root);
 gint camel_partition_table_sync(CamelPartitionTable *cpi);
@@ -100,6 +140,7 @@ typedef struct _CamelKeyRootBlock CamelKeyRootBlock;
 
 typedef struct _CamelKeyTable CamelKeyTable;
 typedef struct _CamelKeyTableClass CamelKeyTableClass;
+typedef struct _CamelKeyTablePrivate CamelKeyTablePrivate;
 
 struct _CamelKeyRootBlock {
 	camel_block_t first;
@@ -126,8 +167,7 @@ struct _CamelKeyBlock {
 
 struct _CamelKeyTable {
 	CamelObject parent;
-
-	struct _CamelKeyTablePrivate *priv;
+	CamelKeyTablePrivate *priv;
 
 	CamelBlockFile *blocks;
 
@@ -141,7 +181,7 @@ struct _CamelKeyTableClass {
 	CamelObjectClass parent;
 };
 
-CamelType camel_key_table_get_type(void);
+GType camel_key_table_get_type(void);
 
 CamelKeyTable * camel_key_table_new(CamelBlockFile *bs, camel_block_t root);
 gint camel_key_table_sync(CamelKeyTable *ki);
@@ -153,4 +193,4 @@ camel_key_t camel_key_table_next(CamelKeyTable *ki, camel_key_t next, gchar **ke
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_PARTITION_TABLE_H */
+#endif /* CAMEL_PARTITION_TABLE_H */
diff --git a/camel/camel-private.h b/camel/camel-private.h
index e6ddb84..0beef18 100644
--- a/camel/camel-private.h
+++ b/camel/camel-private.h
@@ -21,7 +21,7 @@
  */
 
 #ifndef CAMEL_PRIVATE_H
-#define CAMEL_PRIVATE_H 1
+#define CAMEL_PRIVATE_H
 
 /* need a way to configure and save this data, if this header is to
    be installed.  For now, dont install it */
@@ -30,6 +30,7 @@
 #include "config.h"
 #endif
 
+#include <glib.h>
 #include <pthread.h>
 
 G_BEGIN_DECLS
@@ -107,14 +108,14 @@ struct _CamelSessionPrivate {
 struct _CamelFolderSummaryPrivate {
 	GHashTable *filter_charset;	/* CamelMimeFilterCharset's indexed by source charset */
 
-	struct _CamelMimeFilterIndex *filter_index;
-	struct _CamelMimeFilterBasic *filter_64;
-	struct _CamelMimeFilterBasic *filter_qp;
-	struct _CamelMimeFilterBasic *filter_uu;
-	struct _CamelMimeFilterSave *filter_save;
-	struct _CamelMimeFilterHTML *filter_html;
+	struct _CamelMimeFilter *filter_index;
+	struct _CamelMimeFilter *filter_64;
+	struct _CamelMimeFilter *filter_qp;
+	struct _CamelMimeFilter *filter_uu;
+	struct _CamelMimeFilter *filter_save;
+	struct _CamelMimeFilter *filter_html;
 
-	struct _CamelStreamFilter *filter_stream;
+	struct _CamelStream *filter_stream;
 
 	struct _CamelIndex *index;
 
diff --git a/camel/camel-process.h b/camel/camel-process.h
index 4e6b0d7..adfff35 100644
--- a/camel/camel-process.h
+++ b/camel/camel-process.h
@@ -20,10 +20,14 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_DISABLE_DEPRECATED
 
-#ifndef __CAMEL_PROCESS_H__
-#define __CAMEL_PROCESS_H__
+#ifndef CAMEL_PROCESS_H
+#define CAMEL_PROCESS_H
 
 #include <sys/types.h>
 
@@ -37,6 +41,6 @@ gint camel_process_wait (pid_t pid);
 
 G_END_DECLS
 
-#endif /* __CAMEL_PROCESS_H__ */
+#endif /* CAMEL_PROCESS_H */
 
 #endif /* CAMEL_DISABLE_DEPRECATED */
diff --git a/camel/camel-provider.c b/camel/camel-provider.c
index c510ff3..83f49eb 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>
@@ -175,7 +174,7 @@ void
 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);
 
@@ -196,7 +195,7 @@ camel_provider_load(const gchar *path, CamelException *ex)
 	}
 
 	if (!g_module_symbol (module, "camel_provider_module_init",
-			      (gpointer *)&camel_provider_module_init)) {
+			      (gpointer *)&provider_module_init)) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not load %s: No initialization "
 					"code in module."), path);
@@ -204,7 +203,7 @@ camel_provider_load(const gchar *path, CamelException *ex)
 		return;
 	}
 
-	camel_provider_module_init ();
+	provider_module_init ();
 }
 
 /**
diff --git a/camel/camel-provider.h b/camel/camel-provider.h
index 36dc23b..6e556a6 100644
--- a/camel/camel-provider.h
+++ b/camel/camel-provider.h
@@ -24,10 +24,13 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_PROVIDER_H
-#define CAMEL_PROVIDER_H 1
+#define CAMEL_PROVIDER_H
 
-#include <camel/camel-types.h>
 #include <camel/camel-object.h>
 #include <camel/camel-exception.h>
 #include <camel/camel-url.h>
@@ -176,12 +179,12 @@ typedef struct {
 	/* auto-detection function */
 	CamelProviderAutoDetectFunc auto_detect;
 
-	/* CamelType(s) of its store and/or transport. If both are
+	/* GType(s) of its store and/or transport. If both are
 	 * set, then they are assumed to be linked together and the
 	 * transport type can only be used in an account that also
 	 * uses the store type (eg, Exchange or NNTP).
 	 */
-	CamelType object_types[CAMEL_NUM_PROVIDER_TYPES];
+	GType object_types[CAMEL_NUM_PROVIDER_TYPES];
 
 	/* GList of CamelServiceAuthTypes the provider supports */
 	GList *authtypes;
diff --git a/camel/camel-sasl-anonymous.c b/camel/camel-sasl-anonymous.c
index b730420..72f960d 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"
@@ -41,76 +40,12 @@ CamelServiceAuthType camel_sasl_anonymous_authtype = {
 	FALSE
 };
 
-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 GByteArray *anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
-static void
-camel_sasl_anonymous_class_init (CamelSaslAnonymousClass *camel_sasl_anonymous_class)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_anonymous_class);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = anon_challenge;
-}
-
-static void
-camel_sasl_anonymous_finalize (CamelObject *object)
-{
-	CamelSaslAnonymous *sasl = CAMEL_SASL_ANONYMOUS (object);
-
-	g_free (sasl->trace_info);
-}
-
-CamelType
-camel_sasl_anonymous_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_sasl_get_type (),
-					    "CamelSaslAnonymous",
-					    sizeof (CamelSaslAnonymous),
-					    sizeof (CamelSaslAnonymousClass),
-					    (CamelObjectClassInitFunc) camel_sasl_anonymous_class_init,
-					    NULL,
-					    NULL,
-					    (CamelObjectFinalizeFunc) camel_sasl_anonymous_finalize);
-	}
-
-	return type;
-}
-
-/**
- * camel_sasl_anonymous_new:
- * @type: trace type
- * @trace_info: trace info
- *
- * Create a new #CamelSaslAnonymous object.
- *
- * Returns: a new #CamelSasl object
- **/
-CamelSasl *
-camel_sasl_anonymous_new (CamelSaslAnonTraceType type, const gchar *trace_info)
-{
-	CamelSaslAnonymous *sasl_anon;
-
-	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);
-	sasl_anon->type = type;
-
-	return CAMEL_SASL (sasl_anon);
-}
+static gpointer parent_class;
 
 static GByteArray *
-anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+sasl_anonymous_challenge (CamelSasl *sasl,
+                          GByteArray *token,
+                          CamelException *ex)
 {
 	CamelSaslAnonymous *sasl_anon = CAMEL_SASL_ANONYMOUS (sasl);
 	CamelInternetAddress *cia;
@@ -129,10 +64,10 @@ anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
 					      _("Invalid email address trace information:\n%s"),
 					      sasl_anon->trace_info);
-			camel_object_unref (cia);
+			g_object_unref (cia);
 			return NULL;
 		}
-		camel_object_unref (cia);
+		g_object_unref (cia);
 		ret = g_byte_array_new ();
 		g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
 		break;
@@ -156,6 +91,74 @@ anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 		return NULL;
 	}
 
-	sasl->authenticated = TRUE;
+	camel_sasl_set_authenticated (sasl, TRUE);
 	return ret;
 }
+
+static void
+sasl_anonymous_finalize (GObject *object)
+{
+	CamelSaslAnonymous *sasl = CAMEL_SASL_ANONYMOUS (object);
+
+	g_free (sasl->trace_info);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+sasl_anonymous_class_init (CamelSaslAnonymousClass *class)
+{
+	GObjectClass *object_class;
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = sasl_anonymous_finalize;
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_anonymous_challenge;
+}
+
+GType
+camel_sasl_anonymous_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslAnonymous",
+			sizeof (CamelSaslAnonymousClass),
+			(GClassInitFunc) sasl_anonymous_class_init,
+			sizeof (CamelSaslAnonymous),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
+}
+
+/**
+ * camel_sasl_anonymous_new:
+ * @type: trace type
+ * @trace_info: trace info
+ *
+ * Create a new #CamelSaslAnonymous object.
+ *
+ * Returns: a new #CamelSasl object
+ **/
+CamelSasl *
+camel_sasl_anonymous_new (CamelSaslAnonTraceType type, const gchar *trace_info)
+{
+	CamelSaslAnonymous *sasl_anon;
+
+	if (!trace_info && type != CAMEL_SASL_ANON_TRACE_EMPTY)
+		return NULL;
+
+	sasl_anon = g_object_new (CAMEL_TYPE_SASL_ANONYMOUS, NULL);
+	sasl_anon->trace_info = g_strdup (trace_info);
+	sasl_anon->type = type;
+
+	return CAMEL_SASL (sasl_anon);
+}
diff --git a/camel/camel-sasl-anonymous.h b/camel/camel-sasl-anonymous.h
index ce2e82f..57844ab 100644
--- a/camel/camel-sasl-anonymous.h
+++ b/camel/camel-sasl-anonymous.h
@@ -20,38 +20,57 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_ANONYMOUS_H
 #define CAMEL_SASL_ANONYMOUS_H
 
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_ANONYMOUS_TYPE     (camel_sasl_anonymous_get_type ())
-#define CAMEL_SASL_ANONYMOUS(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_ANONYMOUS_TYPE, CamelSaslAnonymous))
-#define CAMEL_SASL_ANONYMOUS_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_ANONYMOUS_TYPE, CamelSaslAnonymousClass))
-#define CAMEL_IS_SASL_ANONYMOUS(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_ANONYMOUS_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_ANONYMOUS \
+	(camel_sasl_anonymous_get_type ())
+#define CAMEL_SASL_ANONYMOUS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_ANONYMOUS, CamelSaslAnonymous))
+#define CAMEL_SASL_ANONYMOUS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_ANONYMOUS, CamelSaslAnonymousClass))
+#define CAMEL_IS_SASL_ANONYMOUS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_ANONYMOUS))
+#define CAMEL_IS_SASL_ANONYMOUS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_ANONYMOUS))
+#define CAMEL_SASL_ANONYMOUS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_ANONYMOUS, CamelSaslAnonymousClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelSaslAnonymous CamelSaslAnonymous;
+typedef struct _CamelSaslAnonymousClass CamelSaslAnonymousClass;
+
 typedef enum {
 	CAMEL_SASL_ANON_TRACE_EMAIL,
 	CAMEL_SASL_ANON_TRACE_OPAQUE,
 	CAMEL_SASL_ANON_TRACE_EMPTY
 } CamelSaslAnonTraceType;
 
-typedef struct _CamelSaslAnonymous {
-	CamelSasl parent_object;
+struct _CamelSaslAnonymous {
+	CamelSasl parent;
 
 	gchar *trace_info;
 	CamelSaslAnonTraceType type;
-} CamelSaslAnonymous;
+};
 
-typedef struct _CamelSaslAnonymousClass {
+struct _CamelSaslAnonymousClass {
 	CamelSaslClass parent_class;
+};
 
-} CamelSaslAnonymousClass;
-
-/* Standard Camel function */
-CamelType camel_sasl_anonymous_get_type (void);
+GType camel_sasl_anonymous_get_type (void);
 
 /* public methods */
 CamelSasl *camel_sasl_anonymous_new (CamelSaslAnonTraceType type, const gchar *trace_info);
diff --git a/camel/camel-sasl-cram-md5.c b/camel/camel-sasl-cram-md5.c
index d8113c9..cb43fb1 100644
--- a/camel/camel-sasl-cram-md5.c
+++ b/camel/camel-sasl-cram-md5.c
@@ -27,13 +27,20 @@
 #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"
 
+#define CAMEL_SASL_CRAM_MD5_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL_CRAM_MD5, CamelSaslCramMd5Private))
+
+struct _CamelSaslCramMd5Private {
+	gint placeholder;  /* allow for future expansion */
+};
+
 CamelServiceAuthType camel_sasl_cram_md5_authtype = {
 	N_("CRAM-MD5"),
 
@@ -44,50 +51,18 @@ CamelServiceAuthType camel_sasl_cram_md5_authtype = {
 	TRUE
 };
 
-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;
-}
+static gpointer parent_class;
 
 /* 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 +77,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 +86,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 +120,49 @@ 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
+sasl_cram_md5_class_init (CamelSaslCramMd5Class *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslCramMd5Private));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_cram_md5_challenge;
+}
+
+static void
+sasl_cram_md5_init (CamelSaslCramMd5 *sasl)
+{
+	sasl->priv = CAMEL_SASL_CRAM_MD5_GET_PRIVATE (sasl);
+}
+
+GType
+camel_sasl_cram_md5_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslCramMd5",
+			sizeof (CamelSaslCramMd5Class),
+			(GClassInitFunc) sasl_cram_md5_class_init,
+			sizeof (CamelSaslCramMd5),
+			(GInstanceInitFunc) sasl_cram_md5_init,
+			0);
+
+	return type;
+}
diff --git a/camel/camel-sasl-cram-md5.h b/camel/camel-sasl-cram-md5.h
index 6c6e373..70145b5 100644
--- a/camel/camel-sasl-cram-md5.h
+++ b/camel/camel-sasl-cram-md5.h
@@ -20,30 +20,50 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_CRAM_MD5_H
 #define CAMEL_SASL_CRAM_MD5_H
 
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_CRAM_MD5_TYPE     (camel_sasl_cram_md5_get_type ())
-#define CAMEL_SASL_CRAM_MD5(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_CRAM_MD5_TYPE, CamelSaslCramMd5))
-#define CAMEL_SASL_CRAM_MD5_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_CRAM_MD5_TYPE, CamelSaslCramMd5Class))
-#define CAMEL_IS_SASL_CRAM_MD5(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_CRAM_MD5_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_CRAM_MD5 \
+	(camel_sasl_cram_md5_get_type ())
+#define CAMEL_SASL_CRAM_MD5(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_CRAM_MD5, CamelSaslCramMd5))
+#define CAMEL_SASL_CRAM_MD5_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_CRAM_MD5, CamelSaslCramMd5Class))
+#define CAMEL_IS_SASL_CRAM_MD5(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_CRAM_MD5))
+#define CAMEL_IS_SASL_CRAM_MD5_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_CRAM_MD5))
+#define CAMEL_SASL_CRAM_MD5_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_CRAM_MD5, CamelSaslCramMd5Class))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSaslCramMd5 {
-	CamelSasl parent_object;
+typedef struct _CamelSaslCramMd5 CamelSaslCramMd5;
+typedef struct _CamelSaslCramMd5Class CamelSaslCramMd5Class;
+typedef struct _CamelSaslCramMd5Private CamelSaslCramMd5Private;
 
-} CamelSaslCramMd5;
+struct _CamelSaslCramMd5 {
+	CamelSasl parent;
+	CamelSaslCramMd5Private *priv;
+};
 
-typedef struct _CamelSaslCramMd5Class {
+struct _CamelSaslCramMd5Class {
 	CamelSaslClass parent_class;
+};
 
-} CamelSaslCramMd5Class;
-
-/* Standard Camel function */
-CamelType camel_sasl_cram_md5_get_type (void);
+GType camel_sasl_cram_md5_get_type (void);
 
 extern CamelServiceAuthType camel_sasl_cram_md5_authtype;
 
diff --git a/camel/camel-sasl-digest-md5.c b/camel/camel-sasl-digest-md5.c
index cb2cd7f..5eab30d 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"
@@ -42,6 +41,10 @@
 
 #define PARANOID(x) x
 
+#define CAMEL_SASL_DIGEST_MD5_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL_DIGEST_MD5, CamelSaslDigestMd5Private))
+
 /* Implements rfc2831 */
 
 CamelServiceAuthType camel_sasl_digest_md5_authtype = {
@@ -54,12 +57,7 @@ CamelServiceAuthType camel_sasl_digest_md5_authtype = {
 	TRUE
 };
 
-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);
+static gpointer parent_class;
 
 enum {
 	STATE_AUTH,
@@ -169,91 +167,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 +731,62 @@ digest_response (struct _DigestResponse *resp)
 	return buffer;
 }
 
+static void
+sasl_digest_md5_finalize (GObject *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);
+	}
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
 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,12 +794,15 @@ 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:
@@ -863,15 +830,15 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 		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);
@@ -908,14 +875,14 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 			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_sasl_set_authenticated (sasl, TRUE);
 
 			return NULL;
 		}
@@ -926,7 +893,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 +902,43 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 	return ret;
 }
+
+static void
+sasl_digest_md5_class_init (CamelSaslDigestMd5Class *class)
+{
+	GObjectClass *object_class;
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslDigestMd5Private));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = sasl_digest_md5_finalize;
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_digest_md5_challenge;
+}
+
+static void
+sasl_digest_md5_init (CamelSaslDigestMd5 *sasl)
+{
+	sasl->priv = CAMEL_SASL_DIGEST_MD5_GET_PRIVATE (sasl);
+}
+
+GType
+camel_sasl_digest_md5_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslDigestMd5",
+			sizeof (CamelSaslDigestMd5Class),
+			(GClassInitFunc) sasl_digest_md5_class_init,
+			sizeof (CamelSaslDigestMd5),
+			(GInstanceInitFunc) sasl_digest_md5_init,
+			0);
+
+	return type;
+}
diff --git a/camel/camel-sasl-digest-md5.h b/camel/camel-sasl-digest-md5.h
index b305bfb..62e904e 100644
--- a/camel/camel-sasl-digest-md5.h
+++ b/camel/camel-sasl-digest-md5.h
@@ -20,32 +20,51 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_DIGEST_MD5_H
 #define CAMEL_SASL_DIGEST_MD5_H
 
 #include <sys/types.h>
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_DIGEST_MD5_TYPE     (camel_sasl_digest_md5_get_type ())
-#define CAMEL_SASL_DIGEST_MD5(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_DIGEST_MD5_TYPE, CamelSaslDigestMd5))
-#define CAMEL_SASL_DIGEST_MD5_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_DIGEST_MD5_TYPE, CamelSaslDigestMd5Class))
-#define CAMEL_IS_SASL_DIGEST_MD5(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_DIGEST_MD5_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_DIGEST_MD5 \
+	(camel_sasl_digest_md5_get_type ())
+#define CAMEL_SASL_DIGEST_MD5(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_DIGEST_MD5, CamelSaslDigestMd5))
+#define CAMEL_SASL_DIGEST_MD5_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_DIGEST_MD5, CamelSaslDigestMd5Class))
+#define CAMEL_IS_SASL_DIGEST_MD5(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_DIGEST_MD5))
+#define CAMEL_IS_SASL_DIGEST_MD5_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_DIGEST_MD5))
+#define CAMEL_SASL_DIGEST_MD5_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_DIGEST_MD5, CamelSaslDigestMd5Class))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSaslDigestMd5 {
-	CamelSasl parent_object;
-	struct _CamelSaslDigestMd5Private *priv;
+typedef struct _CamelSaslDigestMd5 CamelSaslDigestMd5;
+typedef struct _CamelSaslDigestMd5Class CamelSaslDigestMd5Class;
+typedef struct _CamelSaslDigestMd5Private CamelSaslDigestMd5Private;
 
-} CamelSaslDigestMd5;
+struct _CamelSaslDigestMd5 {
+	CamelSasl parent;
+	CamelSaslDigestMd5Private *priv;
+};
 
-typedef struct _CamelSaslDigestMd5Class {
+struct _CamelSaslDigestMd5Class {
 	CamelSaslClass parent_class;
+};
 
-} CamelSaslDigestMd5Class;
-
-/* Standard Camel function */
-CamelType camel_sasl_digest_md5_get_type (void);
+GType camel_sasl_digest_md5_get_type (void);
 
 extern CamelServiceAuthType camel_sasl_digest_md5_authtype;
 
diff --git a/camel/camel-sasl-gssapi.c b/camel/camel-sasl-gssapi.c
index 7363968..efcd2a0 100644
--- a/camel/camel-sasl-gssapi.c
+++ b/camel/camel-sasl-gssapi.c
@@ -59,6 +59,10 @@ extern gss_OID gss_nt_service_name;
 #include "camel-net-utils.h"
 #include "camel-sasl-gssapi.h"
 
+#define CAMEL_SASL_GSSAPI_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL_GSSAPI, CamelSaslGssapiPrivate))
+
 CamelServiceAuthType camel_sasl_gssapi_authtype = {
 	N_("GSSAPI"),
 
@@ -88,66 +92,7 @@ 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 gpointer parent_class;
 
 static void
 gssapi_set_exception (OM_uint32 major, OM_uint32 minor, CamelException *ex)
@@ -203,10 +148,30 @@ 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 (GObject *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);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
 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;
+	CamelService *service;
 	OM_uint32 major, minor, flags, time;
 	gss_buffer_desc inbuf, outbuf;
 	GByteArray *challenge = NULL;
@@ -216,16 +181,22 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	gss_OID mech;
 	gchar *str;
 	struct addrinfo *ai, hints;
+	const gchar *service_name;
+
+	priv = CAMEL_SASL_GSSAPI_GET_PRIVATE (sasl);
+
+	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;
@@ -313,11 +284,11 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 			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);
@@ -340,7 +311,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;
@@ -349,4 +320,48 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	return challenge;
 }
 
+static void
+sasl_gssapi_class_init (CamelSaslGssapiClass *class)
+{
+	GObjectClass *object_class;
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslGssapiPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = sasl_gssapi_finalize;
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_gssapi_challenge;
+}
+
+static void
+sasl_gssapi_init (CamelSaslGssapi *sasl)
+{
+	sasl->priv = CAMEL_SASL_GSSAPI_GET_PRIVATE (sasl);
+
+	sasl->priv->state = GSSAPI_STATE_INIT;
+	sasl->priv->ctx = GSS_C_NO_CONTEXT;
+	sasl->priv->target = GSS_C_NO_NAME;
+}
+
+GType
+camel_sasl_gssapi_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslGssapi",
+			sizeof (CamelSaslGssapiClass),
+			(GClassInitFunc) sasl_gssapi_class_init,
+			sizeof (CamelSaslGssapi),
+			(GInstanceInitFunc) sasl_gssapi_init,
+			0);
+
+	return type;
+}
+
 #endif /* HAVE_KRB5 */
diff --git a/camel/camel-sasl-gssapi.h b/camel/camel-sasl-gssapi.h
index f575c0e..a921211 100644
--- a/camel/camel-sasl-gssapi.h
+++ b/camel/camel-sasl-gssapi.h
@@ -20,39 +20,54 @@
  *
  */
 
-#ifndef __CAMEL_SASL_GSSAPI_H__
-#define __CAMEL_SASL_GSSAPI_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_SASL_GSSAPI_H
+#define CAMEL_SASL_GSSAPI_H
 
 #include <sys/types.h>
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_GSSAPI_TYPE     (camel_sasl_gssapi_get_type ())
-#define CAMEL_SASL_GSSAPI(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_GSSAPI_TYPE, CamelSaslGssapi))
-#define CAMEL_SASL_GSSAPI_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_GSSAPI_TYPE, CamelSaslGssapiClass))
-#define CAMEL_IS_SASL_GSSAPI(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_GSSAPI_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_GSSAPI \
+	(camel_sasl_gssapi_get_type ())
+#define CAMEL_SASL_GSSAPI(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_GSSAPI, CamelSaslGssapi))
+#define CAMEL_SASL_GSSAPI_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_GSSAPI, CamelSaslGssapiClass))
+#define CAMEL_IS_SASL_GSSAPI(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_GSSAPI))
+#define CAMEL_IS_SASL_GSSAPI_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_GSSAPI))
+#define CAMEL_SASL_GSSAPI_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_GSSAPI, CamelSaslGssapiClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelSaslGssapi CamelSaslGssapi;
 typedef struct _CamelSaslGssapiClass CamelSaslGssapiClass;
+typedef struct _CamelSaslGssapiPrivate CamelSaslGssapiPrivate;
 
 struct _CamelSaslGssapi {
-	CamelSasl parent_object;
-
-	struct _CamelSaslGssapiPrivate *priv;
-
+	CamelSasl parent;
+	CamelSaslGssapiPrivate *priv;
 };
 
 struct _CamelSaslGssapiClass {
 	CamelSaslClass parent_class;
-
 };
 
-/* Standard Camel function */
-CamelType camel_sasl_gssapi_get_type (void);
+GType camel_sasl_gssapi_get_type (void);
 
 extern CamelServiceAuthType camel_sasl_gssapi_authtype;
 
 G_END_DECLS
 
-#endif /* __CAMEL_SASL_GSSAPI_H__ */
+#endif /* CAMEL_SASL_GSSAPI_H */
diff --git a/camel/camel-sasl-login.c b/camel/camel-sasl-login.c
index 7f2d3f7..bfd8c4f 100644
--- a/camel/camel-sasl-login.c
+++ b/camel/camel-sasl-login.c
@@ -26,12 +26,15 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-login.h"
 #include "camel-service.h"
 
+#define CAMEL_SASL_LOGIN_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL_LOGIN, CamelSaslLoginPrivate))
+
 CamelServiceAuthType camel_sasl_login_authtype = {
 	N_("Login"),
 
@@ -47,70 +50,26 @@ enum {
 	LOGIN_PASSWD
 };
 
-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)
-{
-	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 gpointer parent_class;
 
 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;
 	GByteArray *buf = NULL;
-	CamelURL *url = sasl->service->url;
+	CamelService *service;
+	CamelURL *url;
+
+	priv = CAMEL_SASL_LOGIN_GET_PRIVATE (sasl);
 
+	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,7 +85,7 @@ 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)) {
@@ -139,3 +98,39 @@ login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 	return buf;
 }
+
+static void
+sasl_login_class_init (CamelSaslLoginClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslLoginPrivate));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_login_challenge;
+}
+
+static void
+sasl_login_init (CamelSaslLogin *sasl)
+{
+	sasl->priv = CAMEL_SASL_LOGIN_GET_PRIVATE (sasl);
+}
+
+GType
+camel_sasl_login_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslLogin",
+			sizeof (CamelSaslLoginClass),
+			(GClassInitFunc) sasl_login_class_init,
+			sizeof (CamelSaslLogin),
+			(GInstanceInitFunc) sasl_login_init,
+			0);
+
+	return type;
+}
diff --git a/camel/camel-sasl-login.h b/camel/camel-sasl-login.h
index 9725f8e..e17bbf8 100644
--- a/camel/camel-sasl-login.h
+++ b/camel/camel-sasl-login.h
@@ -20,32 +20,50 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_LOGIN_H
 #define CAMEL_SASL_LOGIN_H
 
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_LOGIN_TYPE     (camel_sasl_login_get_type ())
-#define CAMEL_SASL_LOGIN(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_LOGIN_TYPE, CamelSaslLogin))
-#define CAMEL_SASL_LOGIN_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_LOGIN_TYPE, CamelSaslLoginClass))
-#define CAMEL_IS_SASL_LOGIN(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_LOGIN_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_LOGIN \
+	(camel_sasl_login_get_type ())
+#define CAMEL_SASL_LOGIN(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_LOGIN, CamelSaslLogin))
+#define CAMEL_SASL_LOGIN_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_LOGIN, CamelSaslLoginClass))
+#define CAMEL_IS_SASL_LOGIN(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_LOGIN))
+#define CAMEL_IS_SASL_LOGIN_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_LOGIN))
+#define CAMEL_SASL_LOGIN_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_LOGIN, CamelSaslLoginClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSaslLogin {
-	CamelSasl parent_object;
-
-	struct _CamelSaslLoginPrivate *priv;
+typedef struct _CamelSaslLogin CamelSaslLogin;
+typedef struct _CamelSaslLoginClass CamelSaslLoginClass;
+typedef struct _CamelSaslLoginPrivate CamelSaslLoginPrivate;
 
-} CamelSaslLogin;
+struct _CamelSaslLogin {
+	CamelSasl parent;
+	CamelSaslLoginPrivate *priv;
+};
 
-typedef struct _CamelSaslLoginClass {
+struct _CamelSaslLoginClass {
 	CamelSaslClass parent_class;
+};
 
-} CamelSaslLoginClass;
-
-/* Standard Camel function */
-CamelType camel_sasl_login_get_type (void);
+GType camel_sasl_login_get_type (void);
 
 extern CamelServiceAuthType camel_sasl_login_authtype;
 
diff --git a/camel/camel-sasl-ntlm.c b/camel/camel-sasl-ntlm.c
index 88a8b9d..27a2d03 100644
--- a/camel/camel-sasl-ntlm.c
+++ b/camel/camel-sasl-ntlm.c
@@ -25,11 +25,18 @@
 #include <ctype.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-ntlm.h"
 
+#define CAMEL_SASL_NTLM_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL_NTLM, CamelSaslNTLMPrivate))
+
+struct _CamelSaslNTLMPrivate {
+	gint placeholder;  /* allow for future expansion */
+};
+
 CamelServiceAuthType camel_sasl_ntlm_authtype = {
 	N_("NTLM / SPA"),
 
@@ -40,37 +47,7 @@ CamelServiceAuthType camel_sasl_ntlm_authtype = {
 	TRUE
 };
 
-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;
-}
+static gpointer parent_class;
 
 #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"
 
@@ -135,64 +112,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 +657,103 @@ 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
+sasl_ntlm_class_init (CamelSaslNTLMClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslNTLMPrivate));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_ntlm_challenge;
+}
+
+static void
+sasl_ntlm_init (CamelSaslNTLM *sasl)
+{
+	sasl->priv = CAMEL_SASL_NTLM_GET_PRIVATE (sasl);
+}
+
+GType
+camel_sasl_ntlm_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslNTLM",
+			sizeof (CamelSaslNTLMClass),
+			(GClassInitFunc) sasl_ntlm_class_init,
+			sizeof (CamelSaslNTLM),
+			(GInstanceInitFunc) sasl_ntlm_init,
+			0);
+
+	return type;
+}
+
diff --git a/camel/camel-sasl-ntlm.h b/camel/camel-sasl-ntlm.h
index 2b894d2..c012895 100644
--- a/camel/camel-sasl-ntlm.h
+++ b/camel/camel-sasl-ntlm.h
@@ -18,30 +18,50 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_NTLM_H
 #define CAMEL_SASL_NTLM_H
 
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_NTLM_TYPE     (camel_sasl_ntlm_get_type ())
-#define CAMEL_SASL_NTLM(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_NTLM_TYPE, CamelSaslNTLM))
-#define CAMEL_SASL_NTLM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_NTLM_TYPE, CamelSaslNTLMClass))
-#define CAMEL_IS_SASL_NTLM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_NTLM_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_NTLM \
+	(camel_sasl_ntlm_get_type ())
+#define CAMEL_SASL_NTLM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_NTLM, CamelSaslNTLM))
+#define CAMEL_SASL_NTLM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_NTLM, CamelSaslNTLMClass))
+#define CAMEL_IS_SASL_NTLM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_NTLM))
+#define CAMEL_IS_SASL_NTLM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_NTLM))
+#define CAMEL_SASL_NTLM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_NTLM, CamelSaslNTLMClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSaslNTLM {
-	CamelSasl parent_object;
+typedef struct _CamelSaslNTLM CamelSaslNTLM;
+typedef struct _CamelSaslNTLMClass CamelSaslNTLMClass;
+typedef struct _CamelSaslNTLMPrivate CamelSaslNTLMPrivate;
 
-} CamelSaslNTLM;
+struct _CamelSaslNTLM {
+	CamelSasl parent;
+	CamelSaslNTLMPrivate *priv;
+};
 
-typedef struct _CamelSaslNTLMClass {
+struct _CamelSaslNTLMClass {
 	CamelSaslClass parent_class;
+};
 
-} CamelSaslNTLMClass;
-
-/* Standard Camel function */
-CamelType camel_sasl_ntlm_get_type (void);
+GType camel_sasl_ntlm_get_type (void);
 
 extern CamelServiceAuthType camel_sasl_ntlm_authtype;
 
diff --git a/camel/camel-sasl-plain.c b/camel/camel-sasl-plain.c
index 5bc47d7..7571ad4 100644
--- a/camel/camel-sasl-plain.c
+++ b/camel/camel-sasl-plain.c
@@ -26,12 +26,19 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-plain.h"
 #include "camel-service.h"
 
+#define CAMEL_SASL_PLAIN_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL_PLAIN, CamelSaslPlainPrivate))
+
+struct _CamelSaslPlainPrivate {
+	gint placeholder;  /* allow for future expansion */
+};
+
 CamelServiceAuthType camel_sasl_plain_authtype = {
 	N_("PLAIN"),
 
@@ -42,57 +49,19 @@ CamelServiceAuthType camel_sasl_plain_authtype = {
 	TRUE
 };
 
-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 *plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
-static void
-camel_sasl_plain_class_init (CamelSaslPlainClass *camel_sasl_plain_class)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_plain_class);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = plain_challenge;
-}
-
-CamelType
-camel_sasl_plain_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_sasl_get_type (),
-					    "CamelSaslPlain",
-					    sizeof (CamelSaslPlain),
-					    sizeof (CamelSaslPlainClass),
-					    (CamelObjectClassInitFunc) camel_sasl_plain_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static GByteArray *
-plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+sasl_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
+	CamelService *service;
+	CamelURL *url;
 
+	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" */
@@ -102,7 +71,43 @@ plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	g_byte_array_append (buf, (guint8 *) "", 1);
 	g_byte_array_append (buf, (guint8 *) url->passwd, strlen (url->passwd));
 
-	sasl->authenticated = TRUE;
+	camel_sasl_set_authenticated (sasl, TRUE);
 
 	return buf;
 }
+
+static void
+sasl_plain_class_init (CamelSaslPlainClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslPlainPrivate));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_plain_challenge;
+}
+
+static void
+sasl_plain_init (CamelSaslPlain *sasl)
+{
+	sasl->priv = CAMEL_SASL_PLAIN_GET_PRIVATE (sasl);
+}
+
+GType
+camel_sasl_plain_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslPlain",
+			sizeof (CamelSaslPlainClass),
+			(GClassInitFunc) sasl_plain_class_init,
+			sizeof (CamelSaslPlain),
+			(GInstanceInitFunc) sasl_plain_init,
+			0);
+
+	return type;
+}
diff --git a/camel/camel-sasl-plain.h b/camel/camel-sasl-plain.h
index 0ca11be..761eaad 100644
--- a/camel/camel-sasl-plain.h
+++ b/camel/camel-sasl-plain.h
@@ -20,30 +20,50 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_PLAIN_H
 #define CAMEL_SASL_PLAIN_H
 
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_PLAIN_TYPE     (camel_sasl_plain_get_type ())
-#define CAMEL_SASL_PLAIN(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_PLAIN_TYPE, CamelSaslPlain))
-#define CAMEL_SASL_PLAIN_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_PLAIN_TYPE, CamelSaslPlainClass))
-#define CAMEL_IS_SASL_PLAIN(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_PLAIN_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_PLAIN \
+	(camel_sasl_plain_get_type ())
+#define CAMEL_SASL_PLAIN(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_PLAIN, CamelSaslPlain))
+#define CAMEL_SASL_PLAIN_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_PLAIN, CamelSaslPlainClass))
+#define CAMEL_IS_SASL_PLAIN(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_PLAIN))
+#define CAMEL_IS_SASL_PLAIN_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_PLAIN))
+#define CAMEL_SASL_PLAIN_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_PLAIN, CamelSaslPlainClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSaslPlain {
-	CamelSasl parent_object;
+typedef struct _CamelSaslPlain CamelSaslPlain;
+typedef struct _CamelSaslPlainClass CamelSaslPlainClass;
+typedef struct _CamelSaslPlainPrivate CamelSaslPlainPrivate;
 
-} CamelSaslPlain;
+struct _CamelSaslPlain {
+	CamelSasl parent;
+	CamelSaslPlainPrivate *priv;
+};
 
-typedef struct _CamelSaslPlainClass {
+struct _CamelSaslPlainClass {
 	CamelSaslClass parent_class;
+};
 
-} CamelSaslPlainClass;
-
-/* Standard Camel function */
-CamelType camel_sasl_plain_get_type (void);
+GType camel_sasl_plain_get_type (void);
 
 extern CamelServiceAuthType camel_sasl_plain_authtype;
 
diff --git a/camel/camel-sasl-popb4smtp.c b/camel/camel-sasl-popb4smtp.c
index aca41d5..2e870ca 100644
--- a/camel/camel-sasl-popb4smtp.c
+++ b/camel/camel-sasl-popb4smtp.c
@@ -28,12 +28,20 @@
 #include <string.h>
 #include <time.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-popb4smtp.h"
 #include "camel-service.h"
 #include "camel-session.h"
+#include "camel-store.h"
+
+#define CAMEL_SASL_POPB4SMTP_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL_POPB4SMTP, CamelSaslPOPB4SMTPPrivate))
+
+struct _CamelSaslPOPB4SMTPPrivate {
+	gint placeholder;  /* allow for future expansion */
+};
 
 CamelServiceAuthType camel_sasl_popb4smtp_authtype = {
 	N_("POP before SMTP"),
@@ -54,56 +62,24 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 #define POPB4SMTP_LOCK(l) pthread_mutex_lock(&l)
 #define POPB4SMTP_UNLOCK(l) pthread_mutex_unlock(&l)
 
-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 gpointer parent_class;
 
 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"));
@@ -124,7 +100,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;
@@ -137,11 +113,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);
+		g_object_unref (store);
 		*timep = now;
 	} else {
-		sasl->authenticated = FALSE;
+		camel_sasl_set_authenticated (sasl, FALSE);
 		*timep = 0;
 	}
 
@@ -151,3 +127,42 @@ popb4smtp_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 	return NULL;
 }
+
+static void
+sasl_popb4smtp_class_init (CamelSaslPOPB4SMTPClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslPOPB4SMTPPrivate));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_popb4smtp_challenge;
+
+	poplast = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+static void
+sasl_popb4smtp_init (CamelSaslPOPB4SMTP *sasl)
+{
+	sasl->priv = CAMEL_SASL_POPB4SMTP_GET_PRIVATE (sasl);
+}
+
+GType
+camel_sasl_popb4smtp_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SASL,
+			"CamelSaslPOPB4SMTP",
+			sizeof (CamelSaslPOPB4SMTPClass),
+			(GClassInitFunc) sasl_popb4smtp_class_init,
+			sizeof (CamelSaslPOPB4SMTP),
+			(GInstanceInitFunc) sasl_popb4smtp_init,
+			0);
+
+	return type;
+}
+
diff --git a/camel/camel-sasl-popb4smtp.h b/camel/camel-sasl-popb4smtp.h
index 081c52f..7882223 100644
--- a/camel/camel-sasl-popb4smtp.h
+++ b/camel/camel-sasl-popb4smtp.h
@@ -20,30 +20,50 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_POPB4SMTP_H
 #define CAMEL_SASL_POPB4SMTP_H
 
 #include <camel/camel-sasl.h>
 
-#define CAMEL_SASL_POPB4SMTP_TYPE     (camel_sasl_popb4smtp_get_type ())
-#define CAMEL_SASL_POPB4SMTP(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_POPB4SMTP_TYPE, CamelSaslPOPB4SMTP))
-#define CAMEL_SASL_POPB4SMTP_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_POPB4SMTP_TYPE, CamelSaslPOPB4SMTPClass))
-#define CAMEL_IS_SASL_POPB4SMTP(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_POPB4SMTP_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL_POPB4SMTP \
+	(camel_sasl_popb4smtp_get_type ())
+#define CAMEL_SASL_POPB4SMTP(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL_POPB4SMTP, CamelSaslPOPB4SMTP))
+#define CAMEL_SASL_POPB4SMTP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL_POPB4SMTP, CamelSaslPOPB4SMTPClass))
+#define CAMEL_IS_SASL_POPB4SMTP(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL_POPB4SMTP))
+#define CAMEL_IS_SASL_POPB4SMTP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL_POPB4SMTP))
+#define CAMEL_SASL_POPB4SMTP_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL_POPB4SMTP, CamelSaslPOPB4SMTPClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSaslPOPB4SMTP {
-	CamelSasl parent_object;
+typedef struct _CamelSaslPOPB4SMTP CamelSaslPOPB4SMTP;
+typedef struct _CamelSaslPOPB4SMTPClass CamelSaslPOPB4SMTPClass;
+typedef struct _CamelSaslPOPB4SMTPPrivate CamelSaslPOPB4SMTPPrivate;
 
-} CamelSaslPOPB4SMTP;
+struct _CamelSaslPOPB4SMTP {
+	CamelSasl parent;
+	CamelSaslPOPB4SMTPPrivate *priv;
+};
 
-typedef struct _CamelSaslPOPB4SMTPClass {
+struct _CamelSaslPOPB4SMTPClass {
 	CamelSaslClass parent_class;
+};
 
-} CamelSaslPOPB4SMTPClass;
-
-/* Standard Camel function */
-CamelType camel_sasl_popb4smtp_get_type (void);
+GType camel_sasl_popb4smtp_get_type (void);
 
 extern CamelServiceAuthType camel_sasl_popb4smtp_authtype;
 
diff --git a/camel/camel-sasl.c b/camel/camel-sasl.c
index 908cb47..48b117c 100644
--- a/camel/camel-sasl.c
+++ b/camel/camel-sasl.c
@@ -39,54 +39,237 @@
 
 #define w(x)
 
-static CamelObjectClass *parent_class = NULL;
+#define CAMEL_SASL_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SASL, CamelSaslPrivate))
+
+struct _CamelSaslPrivate {
+	CamelService *service;
+	gboolean authenticated;
+	gchar *service_name;
+	gchar *mechanism;
+};
+
+enum {
+	PROP_0,
+	PROP_AUTHENTICATED,
+	PROP_MECHANISM,
+	PROP_SERVICE,
+	PROP_SERVICE_NAME
+};
+
+static gpointer parent_class;
 
-/* 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)
 {
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
+	g_return_if_fail (CAMEL_IS_SERVICE (service));
+	g_return_if_fail (sasl->priv->service == NULL);
 
-	/* virtual method definition */
-	camel_sasl_class->challenge = sasl_challenge;
+	sasl->priv->service = g_object_ref (service);
 }
 
 static void
-camel_sasl_finalize (CamelSasl *sasl)
+sasl_set_service_name (CamelSasl *sasl,
+                       const gchar *service_name)
 {
-	g_free (sasl->service_name);
-	g_free (sasl->mech);
-	camel_object_unref (sasl->service);
+	g_return_if_fail (service_name != NULL);
+	g_return_if_fail (sasl->priv->service_name == NULL);
+
+	sasl->priv->service_name = g_strdup (service_name);
 }
 
-CamelType
-camel_sasl_get_type (void)
+static void
+sasl_set_property (GObject *object,
+                   guint property_id,
+                   const GValue *value,
+                   GParamSpec *pspec)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_OBJECT_TYPE,
-					    "CamelSasl",
-					    sizeof (CamelSasl),
-					    sizeof (CamelSaslClass),
-					    (CamelObjectClassInitFunc) camel_sasl_class_init,
-					    NULL,
-					    NULL,
-					    (CamelObjectFinalizeFunc) camel_sasl_finalize);
+	switch (property_id) {
+		case PROP_AUTHENTICATED:
+			camel_sasl_set_authenticated (
+				CAMEL_SASL (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_MECHANISM:
+			sasl_set_mechanism (
+				CAMEL_SASL (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_SERVICE:
+			sasl_set_service (
+				CAMEL_SASL (object),
+				g_value_get_object (value));
+			return;
+
+		case PROP_SERVICE_NAME:
+			sasl_set_service_name (
+				CAMEL_SASL (object),
+				g_value_get_string (value));
+			return;
 	}
 
-	return type;
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+sasl_get_property (GObject *object,
+                   guint property_id,
+                   GValue *value,
+                   GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_AUTHENTICATED:
+			g_value_set_boolean (
+				value, camel_sasl_get_authenticated (
+				CAMEL_SASL (object)));
+			return;
+
+		case PROP_MECHANISM:
+			g_value_set_string (
+				value, camel_sasl_get_mechanism (
+				CAMEL_SASL (object)));
+			return;
+
+		case PROP_SERVICE:
+			g_value_set_object (
+				value, camel_sasl_get_service (
+				CAMEL_SASL (object)));
+			return;
+
+		case PROP_SERVICE_NAME:
+			g_value_set_string (
+				value, camel_sasl_get_service_name (
+				CAMEL_SASL (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
-static GByteArray *
-sasl_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+static void
+sasl_dispose (GObject *object)
 {
-	w(g_warning ("sasl_challenge: Using default implementation!"));
-	return NULL;
+	CamelSaslPrivate *priv;
+
+	priv = CAMEL_SASL_GET_PRIVATE (object);
+
+	if (priv->service != NULL) {
+		g_object_unref (priv->service);
+		priv->service = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+sasl_finalize (GObject *object)
+{
+	CamelSaslPrivate *priv;
+
+	priv = CAMEL_SASL_GET_PRIVATE (object);
+
+	g_free (priv->mechanism);
+	g_free (priv->service_name);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+sasl_class_init (CamelSaslClass *class)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSaslPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = sasl_set_property;
+	object_class->get_property = sasl_get_property;
+	object_class->dispose = sasl_dispose;
+	object_class->finalize = sasl_finalize;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_AUTHENTICATED,
+		g_param_spec_boolean (
+			"authenticated",
+			"Authenticated",
+			NULL,
+			FALSE,
+			G_PARAM_READWRITE));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_MECHANISM,
+		g_param_spec_string (
+			"mechanism",
+			"Mechanism",
+			NULL,
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_SERVICE,
+		g_param_spec_object (
+			"service",
+			"Service",
+			NULL,
+			CAMEL_TYPE_SERVICE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_SERVICE_NAME,
+		g_param_spec_string (
+			"service-name",
+			"Service Name",
+			NULL,
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+sasl_init (CamelSasl *sasl)
+{
+	sasl->priv = CAMEL_SASL_GET_PRIVATE (sasl);
+}
+
+GType
+camel_sasl_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelSasl",
+			sizeof (CamelSaslClass),
+			(GClassInitFunc) sasl_class_init,
+			sizeof (CamelSasl),
+			(GInstanceInitFunc) sasl_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -104,11 +287,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);
 }
 
 /**
@@ -157,21 +347,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,9 +357,11 @@ 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;
+	GType type;
 
 	g_return_val_if_fail (service_name != NULL, NULL);
 	g_return_val_if_fail (mechanism != NULL, NULL);
@@ -193,30 +370,79 @@ camel_sasl_new (const gchar *service_name, const gchar *mechanism, CamelService
 	/* We don't do ANONYMOUS here, because it's a little bit weird. */
 
 	if (!strcmp (mechanism, "CRAM-MD5"))
-		sasl = (CamelSasl *) camel_object_new (CAMEL_SASL_CRAM_MD5_TYPE);
+		type = CAMEL_TYPE_SASL_CRAM_MD5;
 	else if (!strcmp (mechanism, "DIGEST-MD5"))
-		sasl = (CamelSasl *) camel_object_new (CAMEL_SASL_DIGEST_MD5_TYPE);
+		type = CAMEL_TYPE_SASL_DIGEST_MD5;
 #ifdef HAVE_KRB5
 	else if (!strcmp (mechanism, "GSSAPI"))
-		sasl = (CamelSasl *) camel_object_new (CAMEL_SASL_GSSAPI_TYPE);
+		type = CAMEL_TYPE_SASL_GSSAPI;
 #endif
 	else if (!strcmp (mechanism, "PLAIN"))
-		sasl = (CamelSasl *) camel_object_new (CAMEL_SASL_PLAIN_TYPE);
+		type = CAMEL_TYPE_SASL_PLAIN;
 	else if (!strcmp (mechanism, "LOGIN"))
-		sasl = (CamelSasl *) camel_object_new (CAMEL_SASL_LOGIN_TYPE);
+		type = CAMEL_TYPE_SASL_LOGIN;
 	else if (!strcmp (mechanism, "POPB4SMTP"))
-		sasl = (CamelSasl *) camel_object_new (CAMEL_SASL_POPB4SMTP_TYPE);
+		type = CAMEL_TYPE_SASL_POPB4SMTP;
 	else if (!strcmp (mechanism, "NTLM"))
-		sasl = (CamelSasl *) camel_object_new (CAMEL_SASL_NTLM_TYPE);
+		type = CAMEL_TYPE_SASL_NTLM;
 	else
 		return NULL;
 
-	sasl->mech = g_strdup (mechanism);
-	sasl->service_name = g_strdup (service_name);
-	sasl->service = service;
-	camel_object_ref (service);
+	return g_object_new (
+		type, "mechanism", mechanism, "service",
+		service, "service-name", service_name, NULL);
+}
+
+/**
+ * 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;
+
+	g_object_notify (G_OBJECT (sasl), "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;
+	return sasl->priv->service_name;
 }
 
 /**
diff --git a/camel/camel-sasl.h b/camel/camel-sasl.h
index 0f7872b..4eca4c2 100644
--- a/camel/camel-sasl.h
+++ b/camel/camel-sasl.h
@@ -20,48 +20,71 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SASL_H
 #define CAMEL_SASL_H
 
-#include <glib.h>
 #include <camel/camel-object.h>
 #include <camel/camel-exception.h>
 #include <camel/camel-service.h>
 
-#define CAMEL_SASL_TYPE     (camel_sasl_get_type ())
-#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))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SASL \
+	(camel_sasl_get_type ())
+#define CAMEL_SASL(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SASL, CamelSasl))
+#define CAMEL_SASL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SASL, CamelSaslClass))
+#define CAMEL_IS_SASL(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SASL))
+#define CAMEL_IS_SASL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SASL))
+#define CAMEL_SASL_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SASL, CamelSaslClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSasl {
-	CamelObject parent_object;
+typedef struct _CamelSasl CamelSasl;
+typedef struct _CamelSaslClass CamelSaslClass;
+typedef struct _CamelSaslPrivate CamelSaslPrivate;
 
-	gchar *service_name;
-	gchar *mech;		/* mechanism */
-	CamelService *service;
-	gboolean authenticated;
-} CamelSasl;
+struct _CamelSasl {
+	CamelObject parent;
+	CamelSaslPrivate *priv;
+};
 
-typedef struct _CamelSaslClass {
+struct _CamelSaslClass {
 	CamelObjectClass parent_class;
 
-	GByteArray *    (*challenge)   (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
-} CamelSaslClass;
+	GByteArray *	(*challenge)		(CamelSasl *sasl,
+						 GByteArray *token,
+						 CamelException *ex);
+};
 
-/* Standard Camel function */
-CamelType  camel_sasl_get_type (void);
+GType  camel_sasl_get_type (void);
 
 /* public methods */
 GByteArray *camel_sasl_challenge        (CamelSasl *sasl, GByteArray *token, CamelException *ex);
 gchar       *camel_sasl_challenge_base64 (CamelSasl *sasl, const gchar *token, CamelException *ex);
 
-gboolean    camel_sasl_authenticated    (CamelSasl *sasl);
-
 /* utility functions */
-CamelSasl  *camel_sasl_new              (const gchar *service_name, const gchar *mechanism, CamelService *service);
+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 *camel_sasl_authtype      (const gchar *mechanism);
diff --git a/camel/camel-search-private.c b/camel/camel-search-private.c
index 3b8c83d..582cc24 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 <libedataserver/e-sexp.h>
@@ -46,43 +45,6 @@
 
 #define d(x)
 
-static inline guint32
-camel_utf8_getc(const guchar **ptr)
-{
-	register guchar *p = (guchar *)*ptr;
-	register guchar c, r;
-	register guint32 v, m;
-
-again:
-	r = *p++;
-loop:
-	if (r < 0x80) {
-		*ptr = p;
-		v = r;
-	} else if (r < 0xfe) { /* valid start char? */
-		v = r;
-		m = 0x7f80;	/* used to mask out the length bits */
-		do {
-			c = *p++;
-			if ((c & 0xc0) != 0x80) {
-				r = c;
-				goto loop;
-			}
-			v = (v<<6) | (c & 0x3f);
-			r<<=1;
-			m<<=5;
-		} while (r & 0x40);
-
-		*ptr = p;
-
-		v &= ~m;
-	} else {
-		goto again;
-	}
-
-	return v;
-}
-
 /* builds the regex into pattern */
 /* taken from camel-folder-search, with added isregex & exception parameter */
 /* Basically, we build a new regex, either based on subset regex's, or substrings,
@@ -476,7 +438,7 @@ camel_search_header_match (const gchar *value, const gchar *match, camel_search_
 		for (i=0; !truth && camel_internet_address_get(cia, i, &name, &addr);i++)
 			truth = (name && header_match(name, match, how)) || (addr && header_match(addr, match, how));
 
-		camel_object_unref (cia);
+		g_object_unref (cia);
 		break;
 	}
 
@@ -492,7 +454,7 @@ camel_search_message_body_contains (CamelDataWrapper *object, regex_t *pattern)
 	gint truth = FALSE;
 	gint parts, i;
 
-	containee = camel_medium_get_content_object (CAMEL_MEDIUM (object));
+	containee = camel_medium_get_content (CAMEL_MEDIUM (object));
 
 	if (containee == NULL)
 		return FALSE;
@@ -511,12 +473,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;
+		g_object_unref (stream);
 	}
 
 	return truth;
diff --git a/camel/camel-search-private.h b/camel/camel-search-private.h
index 3ab4fd2..17e9a6c 100644
--- a/camel/camel-search-private.h
+++ b/camel/camel-search-private.h
@@ -18,15 +18,16 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_SEARCH_PRIVATE_H
-#define _CAMEL_SEARCH_PRIVATE_H
+#ifndef CAMEL_SEARCH_PRIVATE_H
+#define CAMEL_SEARCH_PRIVATE_H
 
 /* POSIX requires <sys/types.h> be included before <regex.h> */
 #include <sys/types.h>
 
 #include <regex.h>
 
-#include "camel-exception.h"
+#include <camel/camel.h>
+
 #include "libedataserver/e-sexp.h"
 
 G_BEGIN_DECLS
@@ -89,4 +90,4 @@ void camel_search_words_free(struct _camel_search_words *);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_SEARCH_PRIVATE_H */
+#endif /* CAMEL_SEARCH_PRIVATE_H */
diff --git a/camel/camel-search-sql-sexp.c b/camel/camel-search-sql-sexp.c
index 97928d5..8f6b7c0 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"
 #include "libedataserver/e-sexp.h"
 #define d(x) /* x;printf("\n"); */
diff --git a/camel/camel-search-sql-sexp.h b/camel/camel-search-sql-sexp.h
index acce35c..2978103 100644
--- a/camel/camel-search-sql-sexp.h
+++ b/camel/camel-search-sql-sexp.h
@@ -19,8 +19,14 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_SEARCH_SQL_SEXP_H
-#define _CAMEL_SEARCH_SQL_SEXP_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_SEARCH_SQL_SEXP_H
+#define CAMEL_SEARCH_SQL_SEXP_H
+
+#include <glib.h>
 
 G_BEGIN_DECLS
 
@@ -29,4 +35,4 @@ gchar * camel_sexp_to_sql_sexp (const gchar *sexp);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_SEARCH_SQL_H */
+#endif /* CAMEL_SEARCH_SQL_H */
diff --git a/camel/camel-search-sql.c b/camel/camel-search-sql.c
index 9358c31..52c1285 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-search-sql.h b/camel/camel-search-sql.h
index f7421d3..1936f5b 100644
--- a/camel/camel-search-sql.h
+++ b/camel/camel-search-sql.h
@@ -19,8 +19,14 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_SEARCH_SQL_H
-#define _CAMEL_SEARCH_SQL_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_SEARCH_SQL_H
+#define CAMEL_SEARCH_SQL_H
+
+#include <glib.h>
 
 G_BEGIN_DECLS
 
@@ -28,4 +34,4 @@ gchar * camel_sexp_to_sql (const gchar *sexp);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_SEARCH_SQL_H */
+#endif /* CAMEL_SEARCH_SQL_H */
diff --git a/camel/camel-seekable-stream.c b/camel/camel-seekable-stream.c
index 6d22417..e18b34c 100644
--- a/camel/camel-seekable-stream.c
+++ b/camel/camel-seekable-stream.c
@@ -27,69 +27,79 @@
 
 #include "camel-seekable-stream.h"
 
-static CamelStreamClass *parent_class = NULL;
+static gpointer parent_class;
 
-/* Returns the class for a CamelSeekableStream */
-#define CSS_CLASS(so) CAMEL_SEEKABLE_STREAM_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gint
+seekable_stream_reset (CamelStream *stream)
+{
+	CamelSeekableStream *seekable_stream;
 
-static off_t seek        (CamelSeekableStream *stream, off_t offset,
-			  CamelStreamSeekPolicy policy);
-static off_t stream_tell (CamelSeekableStream *stream);
-static gint   reset       (CamelStream *stream);
-static gint   set_bounds  (CamelSeekableStream *stream, off_t start, off_t end);
+	seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
 
-static void
-camel_seekable_stream_class_init (CamelSeekableStreamClass *camel_seekable_stream_class)
+	return camel_seekable_stream_seek (
+		seekable_stream, seekable_stream->bound_start,
+		CAMEL_STREAM_SET);
+}
+
+static off_t
+seekable_stream_tell (CamelSeekableStream *stream)
 {
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_seekable_stream_class);
+	return stream->position;
+}
 
-	parent_class = CAMEL_STREAM_CLASS( camel_type_get_global_classfuncs( CAMEL_STREAM_TYPE ) );
+static gint
+seekable_stream_set_bounds (CamelSeekableStream *stream,
+                            off_t start,
+                            off_t end)
+{
+	/* store the bounds */
+	stream->bound_start = start;
+	stream->bound_end = end;
 
-	/* seekable stream methods */
-	camel_seekable_stream_class->seek = seek;
-	camel_seekable_stream_class->tell = stream_tell;
-	camel_seekable_stream_class->set_bounds = set_bounds;
+	if (start > stream->position)
+		return camel_seekable_stream_seek (
+			stream, start, CAMEL_STREAM_SET);
 
-	/* camel stream methods overload */
-	camel_stream_class->reset = reset;
+	return 0;
 }
 
 static void
-camel_seekable_stream_init (gpointer o)
+seekable_stream_class_init (CamelSeekableStreamClass *class)
 {
-	CamelSeekableStream *stream = (CamelSeekableStream *)o;
+	CamelStreamClass *stream_class;
 
-	stream->bound_start = 0;
-	stream->bound_end = CAMEL_STREAM_UNBOUND;
+	parent_class = g_type_class_peek_parent (class);
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->reset = seekable_stream_reset;
+
+	class->tell = seekable_stream_tell;
+	class->set_bounds = seekable_stream_set_bounds;
 }
 
-CamelType
-camel_seekable_stream_get_type (void)
+static void
+seekable_stream_init (CamelSeekableStream *stream)
 {
-	static CamelType camel_seekable_stream_type = CAMEL_INVALID_TYPE;
-
-	if (camel_seekable_stream_type == CAMEL_INVALID_TYPE) {
-		camel_seekable_stream_type = camel_type_register( CAMEL_STREAM_TYPE,
-								  "CamelSeekableStream",
-								  sizeof( CamelSeekableStream ),
-								  sizeof( CamelSeekableStreamClass ),
-								  (CamelObjectClassInitFunc) camel_seekable_stream_class_init,
-								  NULL,
-								  (CamelObjectInitFunc) camel_seekable_stream_init,
-								  NULL );
-	}
-
-	return camel_seekable_stream_type;
+	stream->bound_start = 0;
+	stream->bound_end = CAMEL_STREAM_UNBOUND;
 }
 
-static off_t
-seek (CamelSeekableStream *stream, off_t offset,
-      CamelStreamSeekPolicy policy)
+GType
+camel_seekable_stream_get_type (void)
 {
-	g_warning ("CamelSeekableStream::seek called on default "
-		   "implementation\n");
-	return -1;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelSeekableStream",
+			sizeof (CamelSeekableStreamClass),
+			(GClassInitFunc) seekable_stream_class_init,
+			sizeof (CamelSeekableStream),
+			(GInstanceInitFunc) seekable_stream_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -115,18 +125,18 @@ seek (CamelSeekableStream *stream, off_t offset,
  * Return value: new position, %-1 if operation failed.
  **/
 off_t
-camel_seekable_stream_seek (CamelSeekableStream *stream, off_t offset,
-			    CamelStreamSeekPolicy policy)
+camel_seekable_stream_seek (CamelSeekableStream *stream,
+                            off_t offset,
+                            CamelStreamSeekPolicy policy)
 {
+	CamelSeekableStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
 
-	return CSS_CLASS (stream)->seek (stream, offset, policy);
-}
+	class = CAMEL_SEEKABLE_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->seek != NULL, -1);
 
-static off_t
-stream_tell (CamelSeekableStream *stream)
-{
-	return stream->position;
+	return class->seek (stream, offset, policy);
 }
 
 /**
@@ -140,22 +150,14 @@ stream_tell (CamelSeekableStream *stream)
 off_t
 camel_seekable_stream_tell (CamelSeekableStream *stream)
 {
-	g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
+	CamelSeekableStreamClass *class;
 
-	return CSS_CLASS (stream)->tell (stream);
-}
-
-static gint
-set_bounds (CamelSeekableStream *stream, off_t start, off_t end)
-{
-	/* store the bounds */
-	stream->bound_start = start;
-	stream->bound_end = end;
+	g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
 
-	if (start > stream->position)
-		return camel_seekable_stream_seek (stream, start, CAMEL_STREAM_SET);
+	class = CAMEL_SEEKABLE_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->tell != NULL, -1);
 
-	return 0;
+	return class->tell (stream);
 }
 
 /**
@@ -172,24 +174,16 @@ set_bounds (CamelSeekableStream *stream, off_t start, off_t end)
  **/
 gint
 camel_seekable_stream_set_bounds (CamelSeekableStream *stream,
-				  off_t start, off_t end)
+                                  off_t start,
+                                  off_t end)
 {
+	CamelSeekableStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
 	g_return_val_if_fail (end == CAMEL_STREAM_UNBOUND || end >= start, -1);
 
-	return CSS_CLASS (stream)->set_bounds (stream, start, end);
-}
+	class = CAMEL_SEEKABLE_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->set_bounds != NULL, -1);
 
-/* a default implementation of reset for seekable streams */
-static gint
-reset (CamelStream *stream)
-{
-	CamelSeekableStream *seekable_stream;
-
-	seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
-
-	return camel_seekable_stream_seek (seekable_stream,
-					   seekable_stream->bound_start,
-					   CAMEL_STREAM_SET);
+	return class->set_bounds (stream, start, end);
 }
-
diff --git a/camel/camel-seekable-stream.h b/camel/camel-seekable-stream.h
index d6d3002..b7743a9 100644
--- a/camel/camel-seekable-stream.h
+++ b/camel/camel-seekable-stream.h
@@ -22,20 +22,41 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SEEKABLE_STREAM_H
-#define CAMEL_SEEKABLE_STREAM_H 1
+#define CAMEL_SEEKABLE_STREAM_H
 
 #include <sys/types.h>
 #include <unistd.h>
 #include <camel/camel-stream.h>
 
-#define CAMEL_SEEKABLE_STREAM_TYPE     (camel_seekable_stream_get_type ())
-#define CAMEL_SEEKABLE_STREAM(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SEEKABLE_STREAM_TYPE, CamelSeekableStream))
-#define CAMEL_SEEKABLE_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SEEKABLE_STREAM_TYPE, CamelSeekableStreamClass))
-#define CAMEL_IS_SEEKABLE_STREAM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SEEKABLE_STREAM_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SEEKABLE_STREAM \
+	(camel_seekable_stream_get_type ())
+#define CAMEL_SEEKABLE_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SEEKABLE_STREAM, CamelSeekableStream))
+#define CAMEL_SEEKABLE_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SEEKABLE_STREAM, CamelSeekableStreamClass))
+#define CAMEL_IS_SEEKABLE_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SEEKABLE_STREAM))
+#define CAMEL_IS_SEEKABLE_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SEEKABLE_STREAM))
+#define CAMEL_SEEKABLE_STREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SEEKABLE_STREAM, CamelSeekableStreamClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelSeekableStream CamelSeekableStream;
+typedef struct _CamelSeekableStreamClass CamelSeekableStreamClass;
+
 typedef enum {
 	CAMEL_STREAM_SET = SEEK_SET,
 	CAMEL_STREAM_CUR = SEEK_CUR,
@@ -45,14 +66,14 @@ typedef enum {
 #define CAMEL_STREAM_UNBOUND (~0)
 
 struct _CamelSeekableStream {
-	CamelStream parent_object;
+	CamelStream parent;
 
 	off_t position;		/* current postion in the stream */
 	off_t bound_start;	/* first valid position */
 	off_t bound_end;	/* first invalid position */
 };
 
-typedef struct {
+struct _CamelSeekableStreamClass {
 	CamelStreamClass parent_class;
 
 	/* Virtual methods */
@@ -61,10 +82,9 @@ typedef struct {
 	off_t (*tell)	    (CamelSeekableStream *stream);
 	gint  (*set_bounds)  (CamelSeekableStream *stream,
 			     off_t start, off_t end);
-} CamelSeekableStreamClass;
+};
 
-/* Standard Camel function */
-CamelType camel_seekable_stream_get_type (void);
+GType camel_seekable_stream_get_type (void);
 
 /* public methods */
 off_t    camel_seekable_stream_seek            (CamelSeekableStream *stream, off_t offset,
diff --git a/camel/camel-seekable-substream.c b/camel/camel-seekable-substream.c
index 4f5a3f9..7c8d8fe 100644
--- a/camel/camel-seekable-substream.c
+++ b/camel/camel-seekable-substream.c
@@ -27,122 +27,40 @@
 
 #include "camel-seekable-substream.h"
 
-static CamelSeekableStreamClass *parent_class = NULL;
+static gpointer parent_class;
 
-/* Returns the class for a CamelSeekableSubStream */
-#define CSS_CLASS(so) CAMEL_SEEKABLE_SUBSTREAM_CLASS (CAMEL_OBJECT(so)->klass)
-
-static	gssize	 stream_read  (CamelStream *stream, gchar *buffer, gsize n);
-static	gssize	 stream_write (CamelStream *stream, const gchar *buffer, gsize n);
-static	gint	 stream_flush (CamelStream *stream);
-static	gint	 stream_close (CamelStream *stream);
-static	gboolean eos	      (CamelStream *stream);
-static	off_t	 stream_seek  (CamelSeekableStream *stream, off_t offset,
-			       CamelStreamSeekPolicy policy);
-
-static void
-camel_seekable_substream_class_init (CamelSeekableSubstreamClass *camel_seekable_substream_class)
+static gboolean
+seekable_substream_parent_reset (CamelSeekableSubstream *seekable_substream,
+                                 CamelSeekableStream *parent)
 {
-	CamelSeekableStreamClass *camel_seekable_stream_class =
-		CAMEL_SEEKABLE_STREAM_CLASS (camel_seekable_substream_class);
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_seekable_substream_class);
-
-	parent_class = CAMEL_SEEKABLE_STREAM_CLASS (camel_type_get_global_classfuncs (camel_seekable_stream_get_type ()));
-
-	/* virtual method definition */
-
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->eos = eos;
+	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (seekable_substream);
 
-	camel_seekable_stream_class->seek = stream_seek;
+	if (camel_seekable_stream_tell (parent) == seekable_stream->position)
+		return TRUE;
 
+	return camel_seekable_stream_seek (parent, (off_t) seekable_stream->position, CAMEL_STREAM_SET) == seekable_stream->position;
 }
 
 static void
-camel_seekable_substream_finalize (CamelObject *object)
-{
-	CamelSeekableSubstream *seekable_substream =
-		CAMEL_SEEKABLE_SUBSTREAM (object);
-
-	if (seekable_substream->parent_stream)
-		camel_object_unref (seekable_substream->parent_stream);
-}
-
-CamelType
-camel_seekable_substream_get_type (void)
-{
-	static CamelType camel_seekable_substream_type = CAMEL_INVALID_TYPE;
-
-	if (camel_seekable_substream_type == CAMEL_INVALID_TYPE) {
-		camel_seekable_substream_type = camel_type_register (camel_seekable_stream_get_type (), "CamelSeekableSubstream",
-								     sizeof (CamelSeekableSubstream),
-								     sizeof (CamelSeekableSubstreamClass),
-								     (CamelObjectClassInitFunc) camel_seekable_substream_class_init,
-								     NULL,
-								     NULL,
-								     (CamelObjectFinalizeFunc) camel_seekable_substream_finalize);
-	}
-
-	return camel_seekable_substream_type;
-}
-
-/**
- * camel_seekable_substream_new:
- * @parent_stream: a #CamelSeekableStream object
- * @start: a lower bound
- * @end: an upper bound
- *
- * Creates a new CamelSeekableSubstream that references the portion
- * of @parent_stream from @inf_bound to @sup_bound. (If @sup_bound is
- * #CAMEL_STREAM_UNBOUND, it references to the end of stream, even if
- * the stream grows.)
- *
- * While the substream is open, the caller cannot assume anything about
- * the current position of @parent_stream. After the substream has been
- * closed, @parent_stream will stabilize again.
- *
- * Return value: the substream
- **/
-CamelStream *
-camel_seekable_substream_new(CamelSeekableStream *parent_stream, off_t start, off_t end)
+seekable_substream_dispose (GObject *object)
 {
 	CamelSeekableSubstream *seekable_substream;
 
-	g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (parent_stream), NULL);
-
-	/* Create the seekable substream. */
-	seekable_substream = CAMEL_SEEKABLE_SUBSTREAM (camel_object_new (camel_seekable_substream_get_type ()));
-
-	/* Initialize it. */
-	seekable_substream->parent_stream = parent_stream;
-	camel_object_ref (parent_stream);
-
-	/* Set the bound of the substream. We can ignore any possible error
-	 * here, because if we fail to seek now, it will try again later.
-	 */
-	camel_seekable_stream_set_bounds ((CamelSeekableStream *)seekable_substream, start, end);
-
-	return CAMEL_STREAM (seekable_substream);
-}
-
-static gboolean
-parent_reset (CamelSeekableSubstream *seekable_substream, CamelSeekableStream *parent)
-{
-	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (seekable_substream);
+	seekable_substream = CAMEL_SEEKABLE_SUBSTREAM (object);
 
-	if (camel_seekable_stream_tell (parent) == seekable_stream->position)
-		return TRUE;
+	if (seekable_substream->parent_stream) {
+		g_object_unref (seekable_substream->parent_stream);
+		seekable_substream = NULL;
+	}
 
-	return camel_seekable_stream_seek (parent, (off_t) seekable_stream->position, CAMEL_STREAM_SET) == seekable_stream->position;
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static gssize
-stream_read (CamelStream *stream, gchar *buffer, gsize n)
+seekable_substream_read (CamelStream *stream,
+                         gchar *buffer,
+                         gsize n)
 {
 	CamelSeekableStream *parent;
 	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
@@ -155,7 +73,7 @@ stream_read (CamelStream *stream, gchar *buffer, gsize n)
 	parent = seekable_substream->parent_stream;
 
 	/* Go to our position in the parent stream. */
-	if (!parent_reset (seekable_substream, parent)) {
+	if (!seekable_substream_parent_reset (seekable_substream, parent)) {
 		stream->eos = TRUE;
 		return 0;
 	}
@@ -179,7 +97,9 @@ stream_read (CamelStream *stream, gchar *buffer, gsize n)
 }
 
 static gssize
-stream_write (CamelStream *stream, const gchar *buffer, gsize n)
+seekable_substream_write (CamelStream *stream,
+                          const gchar *buffer,
+                          gsize n)
 {
 	CamelSeekableStream *parent;
 	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM(stream);
@@ -192,7 +112,7 @@ stream_write (CamelStream *stream, const gchar *buffer, gsize n)
 	parent = seekable_substream->parent_stream;
 
 	/* Go to our position in the parent stream. */
-	if (!parent_reset (seekable_substream, parent)) {
+	if (!seekable_substream_parent_reset (seekable_substream, parent)) {
 		stream->eos = TRUE;
 		return 0;
 	}
@@ -217,7 +137,7 @@ stream_write (CamelStream *stream, const gchar *buffer, gsize n)
 }
 
 static gint
-stream_flush (CamelStream *stream)
+seekable_substream_flush (CamelStream *stream)
 {
 	CamelSeekableSubstream *sus = (CamelSeekableSubstream *)stream;
 
@@ -225,14 +145,14 @@ stream_flush (CamelStream *stream)
 }
 
 static gint
-stream_close (CamelStream *stream)
+seekable_substream_close (CamelStream *stream)
 {
 	/* we dont really want to close the substream ... */
 	return 0;
 }
 
 static gboolean
-eos (CamelStream *stream)
+seekable_substream_eos (CamelStream *stream)
 {
 	CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM(stream);
 	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM(stream);
@@ -243,7 +163,7 @@ eos (CamelStream *stream)
 		eos = TRUE;
 	else {
 		parent = seekable_substream->parent_stream;
-		if (!parent_reset (seekable_substream, parent))
+		if (!seekable_substream_parent_reset (seekable_substream, parent))
 			return TRUE;
 
 		eos = camel_stream_eos (CAMEL_STREAM (parent));
@@ -256,8 +176,9 @@ eos (CamelStream *stream)
 }
 
 static off_t
-stream_seek (CamelSeekableStream *seekable_stream, off_t offset,
-	     CamelStreamSeekPolicy policy)
+seekable_substream_seek (CamelSeekableStream *seekable_stream,
+                         off_t offset,
+                         CamelStreamSeekPolicy policy)
 {
 	CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM(seekable_stream);
 	CamelStream *stream = CAMEL_STREAM(seekable_stream);
@@ -299,3 +220,84 @@ stream_seek (CamelSeekableStream *seekable_stream, off_t offset,
 	seekable_stream->position = real_offset;
 	return real_offset;
 }
+
+static void
+seekable_substream_class_init (CamelSeekableSubstreamClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+	CamelSeekableStreamClass *seekable_stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = seekable_substream_dispose;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = seekable_substream_read;
+	stream_class->write = seekable_substream_write;
+	stream_class->flush = seekable_substream_flush;
+	stream_class->close = seekable_substream_close;
+	stream_class->eos = seekable_substream_eos;
+
+	seekable_stream_class = CAMEL_SEEKABLE_STREAM_CLASS (class);
+	seekable_stream_class->seek = seekable_substream_seek;
+
+}
+
+GType
+camel_seekable_substream_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SEEKABLE_STREAM,
+			"CamelSeekableSubstream",
+			sizeof (CamelSeekableSubstreamClass),
+			(GClassInitFunc) seekable_substream_class_init,
+			sizeof (CamelSeekableSubstream),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
+}
+
+/**
+ * camel_seekable_substream_new:
+ * @parent_stream: a #CamelSeekableStream object
+ * @start: a lower bound
+ * @end: an upper bound
+ *
+ * Creates a new CamelSeekableSubstream that references the portion
+ * of @parent_stream from @inf_bound to @sup_bound. (If @sup_bound is
+ * #CAMEL_STREAM_UNBOUND, it references to the end of stream, even if
+ * the stream grows.)
+ *
+ * While the substream is open, the caller cannot assume anything about
+ * the current position of @parent_stream. After the substream has been
+ * closed, @parent_stream will stabilize again.
+ *
+ * Return value: the substream
+ **/
+CamelStream *
+camel_seekable_substream_new(CamelSeekableStream *parent_stream, off_t start, off_t end)
+{
+	CamelSeekableSubstream *seekable_substream;
+
+	g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (parent_stream), NULL);
+
+	/* Create the seekable substream. */
+	seekable_substream = g_object_new (CAMEL_TYPE_SEEKABLE_SUBSTREAM, NULL);
+
+	/* Initialize it. */
+	seekable_substream->parent_stream = parent_stream;
+	g_object_ref (parent_stream);
+
+	/* Set the bound of the substream. We can ignore any possible error
+	 * here, because if we fail to seek now, it will try again later.
+	 */
+	camel_seekable_stream_set_bounds ((CamelSeekableStream *)seekable_substream, start, end);
+
+	return CAMEL_STREAM (seekable_substream);
+}
diff --git a/camel/camel-seekable-substream.h b/camel/camel-seekable-substream.h
index 7ed8b94..877f939 100644
--- a/camel/camel-seekable-substream.h
+++ b/camel/camel-seekable-substream.h
@@ -22,32 +22,51 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SEEKABLE_SUBSTREAM_H
-#define CAMEL_SEEKABLE_SUBSTREAM_H 1
+#define CAMEL_SEEKABLE_SUBSTREAM_H
 
 #include <camel/camel-seekable-stream.h>
 
-#define CAMEL_SEEKABLE_SUBSTREAM_TYPE       (camel_seekable_substream_get_type ())
-#define CAMEL_SEEKABLE_SUBSTREAM(obj)       (CAMEL_CHECK_CAST((obj), CAMEL_SEEKABLE_SUBSTREAM_TYPE, CamelSeekableSubstream))
-#define CAMEL_SEEKABLE_SUBSTREAM_CLASS(k)   (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SEEKABLE_SUBSTREAM_TYPE, CamelSeekableSubstreamClass))
-#define CAMEL_IS_SEEKABLE_SUBSTREAM(o)      (CAMEL_CHECK_TYPE((o), CAMEL_SEEKABLE_SUBSTREAM_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SEEKABLE_SUBSTREAM \
+	(camel_seekable_substream_get_type ())
+#define CAMEL_SEEKABLE_SUBSTREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SEEKABLE_SUBSTREAM, CamelSeekableSubstream))
+#define CAMEL_SEEKABLE_SUBSTREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SEEKABLE_SUBSTREAM, CamelSeekableSubstreamClass))
+#define CAMEL_IS_SEEKABLE_SUBSTREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SEEKABLE_SUBSTREAM))
+#define CAMEL_IS_SEEKABLE_SUBSTREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SEEKABLE_SUBSTREAM))
+#define CAMEL_SEEKABLE_SUBSTREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SEEKABLE_SUBSTREAM, CamelSeekableSubstreamClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelSeekableSubstream CamelSeekableSubstream;
+typedef struct _CamelSeekableSubstreamClass CamelSeekableSubstreamClass;
+
 struct _CamelSeekableSubstream {
-	CamelSeekableStream parent_object;
+	CamelSeekableStream parent;
 
 	/*  --**-- Private fields --**--  */
 	CamelSeekableStream *parent_stream;
 };
 
-typedef struct {
+struct _CamelSeekableSubstreamClass {
 	CamelSeekableStreamClass parent_class;
+};
 
-} CamelSeekableSubstreamClass;
-
-/* Standard Camel function */
-CamelType camel_seekable_substream_get_type (void);
+GType camel_seekable_substream_get_type (void);
 
 /* public methods */
 
diff --git a/camel/camel-service.c b/camel/camel-service.c
index 3dc24f9..5708d59 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,58 +44,14 @@
 #define d(x)
 #define w(x)
 
-static CamelObjectClass *parent_class = NULL;
+#define CAMEL_SERVICE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SERVICE, CamelServicePrivate))
 
-/* 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 gpointer parent_class;
 
 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 void
-camel_service_finalize (CamelObject *object)
+service_finalize (GObject *object)
 {
 	CamelService *service = CAMEL_SERVICE (object);
 
@@ -104,9 +59,9 @@ 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",
+			w(g_warning ("service_finalize: silent disconnect failure: %s",
 				     camel_exception_get_description (&ex)));
 		}
 		camel_exception_clear (&ex);
@@ -114,37 +69,21 @@ camel_service_finalize (CamelObject *object)
 
 	if (service->url)
 		camel_url_free (service->url);
+
 	if (service->session)
-		camel_object_unref (service->session);
+		g_object_unref (service->session);
 
 	g_static_rec_mutex_free (&service->priv->connect_lock);
 	g_static_mutex_free (&service->priv->connect_op_lock);
 
-	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;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 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 +145,14 @@ service_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
 			camel_service_connect (service, ex);
 	}
 
+	/* Chain up to parent's setv() method. */
 	return CAMEL_OBJECT_CLASS (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 +194,16 @@ service_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
 		}
 	}
 
+	/* Chain up to parent's getv() method. */
 	return CAMEL_OBJECT_CLASS (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;
 
@@ -277,7 +224,7 @@ construct (CamelService *service, CamelSession *session, CamelProvider *provider
 	service->provider = provider;
 	service->url = camel_url_copy(url);
 	service->session = session;
-	camel_object_ref (session);
+	g_object_ref (session);
 
 	service->status = CAMEL_SERVICE_DISCONNECTED;
 
@@ -289,6 +236,144 @@ fail:
 	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()",
+		G_OBJECT_TYPE_NAME (service));
+
+	return g_strdup (G_OBJECT_TYPE_NAME (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
+service_class_init (CamelServiceClass *class)
+{
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelServicePrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = service_finalize;
+
+	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
+service_init (CamelService *service)
+{
+	service->priv = CAMEL_SERVICE_GET_PRIVATE (service);
+
+	g_static_rec_mutex_init (&service->priv->connect_lock);
+	g_static_mutex_init (&service->priv->connect_op_lock);
+}
+
+GType
+camel_service_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelService",
+			sizeof (CamelServiceClass),
+			(GClassInitFunc) service_class_init,
+			sizeof (CamelService),
+			(GInstanceInitFunc) service_init,
+			0);
+
+	return type;
+}
+
 /**
  * camel_service_construct:
  * @service: a #CamelService object
@@ -300,23 +385,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 +413,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 +425,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 +436,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 +448,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 +466,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 +478,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 +505,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 +523,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 +534,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 +560,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 +578,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);
-}
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_val_if_fail (class->get_name != NULL, NULL);
 
-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);
-
-	return path;
+	return class->get_name (service, brief);
 }
 
 /**
@@ -567,10 +607,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 +629,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 +645,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 +663,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 ad44173..2f112d9 100644
--- a/camel/camel-service.h
+++ b/camel/camel-service.h
@@ -22,21 +22,45 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SERVICE_H
-#define CAMEL_SERVICE_H 1
+#define CAMEL_SERVICE_H
 
 #include <camel/camel-object.h>
 #include <camel/camel-url.h>
 #include <camel/camel-provider.h>
 #include <camel/camel-operation.h>
 
-#define CAMEL_SERVICE_TYPE     (camel_service_get_type ())
-#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))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SERVICE \
+	(camel_service_get_type ())
+#define CAMEL_SERVICE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SERVICE, CamelService))
+#define CAMEL_SERVICE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SERVICE, CamelServiceClass))
+#define CAMEL_IS_SERVICE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SERVICE))
+#define CAMEL_IS_SERVICE_CLASS(obj) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SERVICE))
+#define CAMEL_SERVICE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SERVICE, CamelServiceClass))
 
 G_BEGIN_DECLS
 
+struct _CamelSession;
+
+typedef struct _CamelService CamelService;
+typedef struct _CamelServiceClass CamelServiceClass;
+typedef struct _CamelServicePrivate CamelServicePrivate;
+
 enum {
 	CAMEL_SERVICE_ARG_FIRST  = CAMEL_ARG_FIRST + 100,
 	CAMEL_SERVICE_ARG_USERNAME,
@@ -60,21 +84,21 @@ typedef enum {
 } CamelServiceConnectionStatus;
 
 struct _CamelService {
-	CamelObject parent_object;
-	struct _CamelServicePrivate *priv;
+	CamelObject parent;
+	CamelServicePrivate *priv;
 
-	CamelSession *session;
+	struct _CamelSession *session;
 	CamelProvider *provider;
 	CamelServiceConnectionStatus status;
 	CamelOperation *connect_op;
 	CamelURL *url;
 };
 
-typedef struct {
+struct _CamelServiceClass {
 	CamelObjectClass parent_class;
 
 	void      (*construct)         (CamelService *service,
-					CamelSession *session,
+					struct _CamelSession *session,
 					CamelProvider *provider,
 					CamelURL *url,
 					CamelException *ex);
@@ -92,8 +116,7 @@ typedef struct {
 	gchar *    (*get_name)          (CamelService *service,
 					gboolean brief);
 	gchar *    (*get_path)          (CamelService *service);
-
-} CamelServiceClass;
+};
 
 /* query_auth_types returns a GList of these */
 typedef struct {
@@ -106,7 +129,7 @@ typedef struct {
 
 /* public methods */
 void                camel_service_construct          (CamelService *service,
-						      CamelSession *session,
+						      struct _CamelSession *session,
 						      CamelProvider *provider,
 						      CamelURL *url,
 						      CamelException *ex);
@@ -120,13 +143,12 @@ gchar *              camel_service_get_url            (CamelService *service);
 gchar *              camel_service_get_name           (CamelService *service,
 						      gboolean brief);
 gchar *              camel_service_get_path           (CamelService *service);
-CamelSession *      camel_service_get_session        (CamelService *service);
+struct _CamelSession *      camel_service_get_session        (CamelService *service);
 CamelProvider *     camel_service_get_provider       (CamelService *service);
 GList *             camel_service_query_auth_types   (CamelService *service,
 						      CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_service_get_type (void);
+GType camel_service_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/camel-session.c b/camel/camel-session.c
index f5f8b23..adad849 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -34,7 +34,6 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -53,117 +52,60 @@
 
 #define d(x)
 
-#define CS_CLASS(so) ((CamelSessionClass *)((CamelObject *)so)->klass)
+#define CAMEL_SESSION_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SESSION, CamelSessionPrivate))
 
-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 gpointer parent_class;
 
 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 (GObject *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);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 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;
@@ -198,12 +140,12 @@ get_service (CamelSession *session, const gchar *url_string,
 	/* Now look up the service in the provider's cache */
 	service = camel_object_bag_reserve(provider->service_cache[type], url);
 	if (service == NULL) {
-		service = (CamelService *)camel_object_new (provider->object_types[type]);
+		service = g_object_new (provider->object_types[type], NULL);
 		camel_exception_init (&internal_ex);
 		camel_service_construct (service, session, provider, url, &internal_ex);
 		if (camel_exception_is_set (&internal_ex)) {
 			camel_exception_xfer (ex, &internal_ex);
-			camel_object_unref (service);
+			g_object_unref (service);
 			service = NULL;
 			camel_object_bag_abort(provider->service_cache[type], url);
 		} else {
@@ -216,6 +158,231 @@ 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;
+	g_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);
+	g_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
+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."));
+}
+
+static void
+session_class_init (CamelSessionClass *class)
+{
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSessionPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = session_finalize;
+
+	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;
+	class->forward_to = session_forward_to;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class_add_event (camel_object_class, "online", NULL);
+}
+
+static void
+session_init (CamelSession *session)
+{
+	session->priv = CAMEL_SESSION_GET_PRIVATE (session);
+
+	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;
+}
+
+GType
+camel_session_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelSession",
+			sizeof (CamelSessionClass),
+			(GClassInitFunc) session_class_init,
+			sizeof (CamelSession),
+			(GInstanceInitFunc) session_init,
+			0);
+
+	return 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
@@ -236,16 +403,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;
@@ -266,9 +439,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;
 
@@ -278,7 +451,7 @@ camel_session_get_service_connected (CamelSession *session,
 
 	if (svc->status != CAMEL_SERVICE_CONNECTED) {
 		if (camel_service_connect (svc, ex) == FALSE) {
-			camel_object_unref (svc);
+			g_object_unref (svc);
 			return NULL;
 		}
 	}
@@ -286,33 +459,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
@@ -329,13 +475,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);
 }
 
 /**
@@ -371,16 +523,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);
 }
 
 /**
@@ -400,13 +561,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);
 }
 
 /**
@@ -424,21 +593,34 @@ 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);
 }
 
 gboolean
 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);
 }
 
 /**
@@ -522,127 +704,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)
-{
-	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)
+                                 const gchar *type,
+                                 CamelException *ex)
 {
-	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);
-
-	id = msg->id;
-	g_thread_pool_push(thread_pool, msg, NULL);
-
-	return id;
-}
-
-static void
-session_thread_wait (CamelSession *session,
-                     gint id)
-{
-	gint wait;
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+	g_return_val_if_fail (type != NULL, NULL);
 
-	/* 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);
-}
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->get_filter_driver != NULL, NULL);
 
-static void
-session_thread_status (CamelSession *session,
-                       CamelSessionThreadMsg *msg,
-                       const gchar *text,
-                       gint pc)
-{
+	return class->get_filter_driver (session, type, ex);
 }
 
 /**
@@ -664,11 +737,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);
 }
 
 /**
@@ -683,10 +761,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);
 }
 
 /**
@@ -706,10 +789,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);
 }
 
 /**
@@ -723,12 +811,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);
 }
 
 /**
@@ -810,13 +903,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.
@@ -827,9 +913,21 @@ session_forward_to (CamelSession *session, CamelFolder *folder, CamelMimeMessage
  * @ex Exception.
  **/
 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 e6d6455..215ef39 100644
--- a/camel/camel-session.h
+++ b/camel/camel-session.h
@@ -23,21 +23,45 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_SESSION_H
-#define CAMEL_SESSION_H 1
+#define CAMEL_SESSION_H
 
+#include <camel/camel-filter-driver.h>
+#include <camel/camel-junk-plugin.h>
 #include <camel/camel-msgport.h>
 #include <camel/camel-object.h>
 #include <camel/camel-provider.h>
-#include <camel/camel-junk-plugin.h>
-
-#define CAMEL_SESSION_TYPE     (camel_session_get_type ())
-#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))
+#include <camel/camel-service.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_SESSION \
+	(camel_session_get_type ())
+#define CAMEL_SESSION(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SESSION, CamelSession))
+#define CAMEL_SESSION_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SESSION, CamelSessionClass))
+#define CAMEL_IS_SESSION(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SESSION))
+#define CAMEL_IS_SESSION_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SESSION))
+#define CAMEL_SESSION_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SESSION, CamelSessionClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelSession CamelSession;
+typedef struct _CamelSessionClass CamelSessionClass;
+typedef struct _CamelSessionPrivate CamelSessionPrivate;
+
 typedef gboolean (*CamelTimeoutCallback) (gpointer data);
 typedef enum {
 	CAMEL_SESSION_ALERT_INFO,
@@ -52,10 +76,9 @@ enum {
 	CAMEL_SESSION_PASSPHRASE = 1 << 4
 };
 
-struct _CamelSession
-{
-	CamelObject parent_object;
-	struct _CamelSessionPrivate *priv;
+struct _CamelSession {
+	CamelObject parent;
+	CamelSessionPrivate *priv;
 
 	gchar *storage_path;
 	CamelJunkPlugin *junk_plugin;
@@ -68,7 +91,7 @@ struct _CamelSession
 typedef struct _CamelSessionThreadOps CamelSessionThreadOps;
 typedef struct _CamelSessionThreadMsg CamelSessionThreadMsg;
 
-typedef struct {
+struct _CamelSessionClass {
 	CamelObjectClass parent_class;
 
 	CamelService *  (*get_service)       (CamelSession *session,
@@ -122,12 +145,9 @@ typedef struct {
 					      struct _CamelMimeMessage *message,
 					      const gchar *address,
 					      CamelException *ex);
-} CamelSessionClass;
-
-/* public methods */
+};
 
-/* Standard Camel function */
-CamelType camel_session_get_type (void);
+GType camel_session_get_type (void);
 
 void            camel_session_construct             (CamelSession *session,
 						     const gchar *storage_path);
diff --git a/camel/camel-smime-context.c b/camel/camel-smime-context.c
index 99ad6d8..62342c1 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,8 +62,9 @@
 
 #define d(x)
 
-void smime_cert_data_free (gpointer cert_data);
-gpointer smime_cert_data_clone (gpointer cert_data);
+#define CAMEL_SMIME_CONTEXT_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_SMIME_CONTEXT, CamelSMIMEContextPrivate))
 
 struct _CamelSMIMEContextPrivate {
 	CERTCertDBHandle *certdb;
@@ -75,156 +76,26 @@ struct _CamelSMIMEContextPrivate {
 	guint send_encrypt_key_prefs:1;
 };
 
-static CamelCipherContextClass *parent_class = NULL;
+static gpointer parent_class;
 
 /* used for decode content callback, for streaming decode */
 static void
-sm_write_stream(gpointer arg, const gchar *buf, gulong len)
+sm_write_stream (gpointer arg, const gchar *buf, gulong len)
 {
-	camel_stream_write((CamelStream *)arg, buf, len);
+	camel_stream_write ((CamelStream *)arg, buf, len);
 }
 
 static PK11SymKey *
-sm_decrypt_key(gpointer arg, SECAlgorithmID *algid)
+sm_decrypt_key (gpointer arg, SECAlgorithmID *algid)
 {
-	printf("Decrypt key called\n");
+	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)
-{
-	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)
-{
-	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_object((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");
-		}
-	}
-
-	return flags;
-}
-
-static const gchar *
-sm_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
-sm_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 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 +257,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")
@@ -430,70 +301,70 @@ set_nss_error (CamelException *ex, const gchar *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_FALSE,
 					     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) {
-		fprintf(stderr, "ERROR: cannot add SMIMECaps attribute.\n");
+	if (NSS_CMSSignerInfo_AddSMIMECaps (signerinfo) != SECSuccess) {
+		fprintf (stderr, "ERROR: cannot add SMIMECaps attribute.\n");
 		goto loser;
 	}
 #endif
@@ -504,195 +375,73 @@ sm_signing_cmsmessage(CamelSMIMEContext *context, const gchar *nick, SECOidTag h
 
 		if (p->encrypt_key) {
 			/* encrypt key has its own nick */
-			if ((ekpcert = CERT_FindUserCertByUsage(
+			if ((ekpcert = CERT_FindUserCertByUsage (
 				     p->certdb,
 				     p->encrypt_key,
 				     certUsageEmailRecipient, PR_FALSE, 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_FALSE, 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_object((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_object((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_object((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 +468,10 @@ 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 +480,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 +512,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);
+			g_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 +548,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 +583,35 @@ 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 (valid, CAMEL_CIPHER_VALIDITY_SIGN, cn, em);
 
 					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,62 +620,231 @@ 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 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);
+		g_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);
+	}
+
+	g_object_unref (dw);
+fail:
+	g_object_unref (ostream);
+	g_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_object((CamelMedium *)ipart);
+	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)) {
+		    || (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"));
 			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,
@@ -948,34 +852,39 @@ sm_verify(CamelCipherContext *context, CamelMimePart *ipart, CamelException *ex)
 		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_object((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 ((CamelMedium *)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);
+	g_object_unref (mem);
 	if (constream)
-		camel_object_unref(constream);
+		g_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 +897,94 @@ 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,98 +997,104 @@ 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);
+		g_object_unref (mem);
 		set_nss_error (ex, _("Failed to add data to encoder"));
 		goto fail;
 	}
-	camel_object_unref(mem);
+	g_object_unref (mem);
 
-	if (NSS_CMSEncoder_Finish(enc) != SECSuccess) {
+	if (NSS_CMSEncoder_Finish (enc) != SECSuccess) {
 		set_nss_error (ex, _("Failed to encode data"));
 		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);
+	g_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_object((CamelMedium *)opart, dw);
-	camel_object_unref(dw);
+	camel_medium_set_content ((CamelMedium *)opart, dw);
+	g_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);
+		g_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);
+	PORT_FreeArena (poolp, PR_FALSE);
 
 	return -1;
 }
 
 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_object((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 (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);
+	g_object_unref (istream);
 
 	if (cmsg == NULL) {
 		set_nss_error (ex, _("Decoder failed"));
@@ -1187,109 +1103,179 @@ 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);
+	g_object_unref (ostream);
 
 	return valid;
 }
 
-static gint
-sm_import_keys(CamelCipherContext *context, CamelStream *istream, CamelException *ex)
+static void
+smime_context_class_init (CamelSMIMEContextClass *class)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("import keys: unimplemented"));
-
-	return -1;
+	CamelCipherContextClass *cipher_context_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelSMIMEContextPrivate));
+
+	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 gint
-sm_export_keys(CamelCipherContext *context, GPtrArray *keys, CamelStream *ostream, CamelException *ex)
+static void
+smime_context_init (CamelSMIMEContext *smime_context)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("export keys: unimplemented"));
+	smime_context->priv = CAMEL_SMIME_CONTEXT_GET_PRIVATE (smime_context);
 
-	return -1;
+	smime_context->priv->certdb = CERT_GetDefaultCertDB ();
+	smime_context->priv->sign_mode = CAMEL_SMIME_SIGN_CLEARSIGN;
+	smime_context->priv->password_tries = 0;
 }
 
-/* ********************************************************************** */
-
-static void
-camel_smime_context_class_init(CamelSMIMEContextClass *klass)
+GType
+camel_smime_context_get_type (void)
 {
-	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 = 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 GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_CIPHER_CONTEXT,
+			"CamelSMIMEContext",
+			sizeof (CamelSMIMEContextClass),
+			(GClassInitFunc) smime_context_class_init,
+			sizeof (CamelSMIMEContext),
+			(GInstanceInitFunc) smime_context_init,
+			0);
+
+	return type;
 }
 
-static void
-camel_smime_context_init(CamelSMIMEContext *context)
+/**
+ * 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 =(CamelCipherContext *) context;
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
 
-	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;
+	return g_object_new (
+		CAMEL_TYPE_SMIME_CONTEXT,
+		"session", session, NULL);
 }
 
-static void
-camel_smime_context_finalise(CamelObject *object)
+void
+camel_smime_context_set_encrypt_key (CamelSMIMEContext *context, gboolean use, const gchar *key)
 {
-	CamelSMIMEContext *context = (CamelSMIMEContext *)object;
-
-	/* FIXME: do we have to free the certdb? */
+	context->priv->send_encrypt_key_prefs = use;
+	g_free (context->priv->encrypt_key);
+	context->priv->encrypt_key = g_strdup (key);
+}
 
-	g_free(context->priv);
+/* 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;
 }
 
-CamelType
-camel_smime_context_get_type(void)
+/* 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 CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_cipher_context_get_type(),
-					   "CamelSMIMEContext",
-					   sizeof(CamelSMIMEContext),
-					   sizeof(CamelSMIMEContextClass),
-					   (CamelObjectClassInitFunc) camel_smime_context_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_smime_context_init,
-					   (CamelObjectFinalizeFunc) camel_smime_context_finalise);
+	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);
+		g_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 type;
+	return flags;
 }
 
 #endif /* ENABLE_SMIME */
diff --git a/camel/camel-smime-context.h b/camel/camel-smime-context.h
index 2275a64..35cf2b8 100644
--- a/camel/camel-smime-context.h
+++ b/camel/camel-smime-context.h
@@ -21,15 +21,33 @@
  *
  */
 
-#ifndef __CAMEL_SMIME_CONTEXT_H__
-#define __CAMEL_SMIME_CONTEXT_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_SMIME_CONTEXT_H
+#define CAMEL_SMIME_CONTEXT_H
 
 #include <camel/camel-cipher-context.h>
 
-#define CAMEL_SMIME_CONTEXT_TYPE    (camel_smime_context_get_type())
-#define CAMEL_SMIME_CONTEXT(obj)    (CAMEL_CHECK_CAST((obj), CAMEL_SMIME_CONTEXT_TYPE, CamelSMIMEContext))
-#define CAMEL_SMIME_CONTEXT_CLASS(k)(CAMEL_CHECK_CLASS_CAST((k), CAMEL_SMIME_CONTEXT_TYPE, CamelSMIMEContextClass))
-#define CAMEL_IS_SMIME_CONTEXT(o)   (CAMEL_CHECK_TYPE((o), CAMEL_SMIME_CONTEXT_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SMIME_CONTEXT \
+	(camel_smime_context_get_type())
+#define CAMEL_SMIME_CONTEXT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SMIME_CONTEXT, CamelSMIMEContext))
+#define CAMEL_SMIME_CONTEXT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SMIME_CONTEXT, CamelSMIMEContextClass))
+#define CAMEL_IS_SMIME_CONTEXT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SMIME_CONTEXT))
+#define CAMEL_IS_SMIME_CONTEXT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SMIME_CONTEXT))
+#define CAMEL_SMIME_CONTEXT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SMIME_CONTEXT, CamelSMIMEContextClass))
 
 G_BEGIN_DECLS
 
@@ -45,22 +63,24 @@ typedef enum _camel_smime_describe_t {
 	CAMEL_SMIME_CRLS = 1<<3
 } camel_smime_describe_t;
 
+struct _CamelSession;
+
 typedef struct _CamelSMIMEContext CamelSMIMEContext;
 typedef struct _CamelSMIMEContextClass CamelSMIMEContextClass;
+typedef struct _CamelSMIMEContextPrivate CamelSMIMEContextPrivate;
 
 struct _CamelSMIMEContext {
-	CamelCipherContext cipher;
-
-	struct _CamelSMIMEContextPrivate *priv;
+	CamelCipherContext parent;
+	CamelSMIMEContextPrivate *priv;
 };
 
 struct _CamelSMIMEContextClass {
-	CamelCipherContextClass cipher_class;
+	CamelCipherContextClass parent_class;
 };
 
-CamelType camel_smime_context_get_type(void);
+GType camel_smime_context_get_type(void);
 
-CamelCipherContext *camel_smime_context_new(CamelSession *session);
+CamelCipherContext *camel_smime_context_new(struct _CamelSession *session);
 
 /* nick to use for SMIMEEncKeyPrefs attribute for signed data */
 void camel_smime_context_set_encrypt_key(CamelSMIMEContext *context, gboolean use, const gchar *key);
@@ -71,4 +91,4 @@ guint32 camel_smime_context_describe_part(CamelSMIMEContext *, struct _CamelMime
 
 G_END_DECLS
 
-#endif /* __CAMEL_SMIME_CONTEXT_H__ */
+#endif /* CAMEL_SMIME_CONTEXT_H */
diff --git a/camel/camel-store-summary.c b/camel/camel-store-summary.c
index 4515af0..df22096 100644
--- a/camel/camel-store-summary.c
+++ b/camel/camel-store-summary.c
@@ -32,7 +32,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
 #include <libedataserver/e-memory.h>
@@ -52,106 +51,302 @@
 /* current version */
 #define CAMEL_STORE_SUMMARY_VERSION (2)
 
-#define _PRIVATE(o) (((CamelStoreSummary *)(o))->priv)
+#define CAMEL_STORE_SUMMARY_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummaryPrivate))
 
-static gint summary_header_load(CamelStoreSummary *, FILE *);
-static gint summary_header_save(CamelStoreSummary *, FILE *);
+static gpointer parent_class;
 
-static CamelStoreInfo * store_info_new(CamelStoreSummary *, const gchar *);
-static CamelStoreInfo * store_info_load(CamelStoreSummary *, FILE *);
-static gint		 store_info_save(CamelStoreSummary *, FILE *, CamelStoreInfo *);
-static void		 store_info_free(CamelStoreSummary *, CamelStoreInfo *);
+static void
+store_summary_finalize (GObject *object)
+{
+	CamelStoreSummary *summary = CAMEL_STORE_SUMMARY (object);
 
-static const gchar *store_info_string(CamelStoreSummary *, const CamelStoreInfo *, gint);
-static void store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int, const gchar *);
+	camel_store_summary_clear (summary);
+	g_ptr_array_free (summary->folders, TRUE);
+	g_hash_table_destroy (summary->folders_path);
 
-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);
+	g_free (summary->summary_path);
 
-static CamelObjectClass *camel_store_summary_parent;
+	if (summary->store_info_chunks != NULL)
+		e_memchunk_destroy (summary->store_info_chunks);
 
-static void
-camel_store_summary_class_init (CamelStoreSummaryClass *klass)
+	g_mutex_free (summary->priv->summary_lock);
+	g_mutex_free (summary->priv->io_lock);
+	g_mutex_free (summary->priv->alloc_lock);
+	g_mutex_free (summary->priv->ref_lock);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static gint
+store_summary_summary_header_load (CamelStoreSummary *summary,
+                                   FILE *in)
+{
+	gint32 version, flags, count;
+	time_t time;
+
+	fseek (in, 0, SEEK_SET);
+
+	io (printf ("Loading header\n"));
+
+	if (camel_file_util_decode_fixed_int32 (in, &version) == -1
+	    || camel_file_util_decode_fixed_int32 (in, &flags) == -1
+	    || camel_file_util_decode_time_t (in, &time) == -1
+	    || camel_file_util_decode_fixed_int32 (in, &count) == -1) {
+		return -1;
+	}
+
+	summary->flags = flags;
+	summary->time = time;
+	summary->count = count;
+	summary->version = version;
+
+	if (version < CAMEL_STORE_SUMMARY_VERSION_0) {
+		g_warning ("Store summary header version too low");
+		return -1;
+	}
+
+	return 0;
+}
+
+static gint
+store_summary_summary_header_save (CamelStoreSummary *summary,
+                                   FILE *out)
 {
-	camel_store_summary_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
+	fseek (out, 0, SEEK_SET);
 
-	klass->summary_header_load = summary_header_load;
-	klass->summary_header_save = summary_header_save;
+	io (printf ("Savining header\n"));
 
-	klass->store_info_new  = store_info_new;
-	klass->store_info_load = store_info_load;
-	klass->store_info_save = store_info_save;
-	klass->store_info_free = store_info_free;
+	/* always write latest version */
+	camel_file_util_encode_fixed_int32 (out, CAMEL_STORE_SUMMARY_VERSION);
+	camel_file_util_encode_fixed_int32 (out, summary->flags);
+	camel_file_util_encode_time_t (out, summary->time);
 
-	klass->store_info_string = store_info_string;
-	klass->store_info_set_string = store_info_set_string;
+	return camel_file_util_encode_fixed_int32 (
+		out, camel_store_summary_count (summary));
 }
 
-static void
-camel_store_summary_init (CamelStoreSummary *s)
+static CamelStoreInfo *
+store_summary_store_info_new (CamelStoreSummary *summary,
+                              const gchar *path)
+{
+	CamelStoreInfo *info;
+
+	info = camel_store_summary_info_new (summary);
+
+	info->path = g_strdup (path);
+	info->unread = CAMEL_STORE_INFO_FOLDER_UNKNOWN;
+	info->total = CAMEL_STORE_INFO_FOLDER_UNKNOWN;
+
+	return info;
+}
+
+static CamelStoreInfo *
+store_summary_store_info_load (CamelStoreSummary *summary,
+                               FILE *in)
 {
-	struct _CamelStoreSummaryPrivate *p;
+	CamelStoreInfo *info;
+
+	info = camel_store_summary_info_new (summary);
+
+	io (printf ("Loading folder info\n"));
+
+	camel_file_util_decode_string (in, &info->path);
+	camel_file_util_decode_uint32 (in, &info->flags);
+	camel_file_util_decode_uint32 (in, &info->unread);
+	camel_file_util_decode_uint32 (in, &info->total);
+
+	/* Ok, brown paper bag bug - prior to version 2 of the file, flags are
+	   stored using the bit number, not the bit. Try to recover as best we can */
+	if (summary->version < CAMEL_STORE_SUMMARY_VERSION_2) {
+		guint32 flags = 0;
+
+		if (info->flags & 1)
+			flags |= CAMEL_STORE_INFO_FOLDER_NOSELECT;
+		if (info->flags & 2)
+			flags |= CAMEL_STORE_INFO_FOLDER_READONLY;
+		if (info->flags & 3)
+			flags |= CAMEL_STORE_INFO_FOLDER_SUBSCRIBED;
+		if (info->flags & 4)
+			flags |= CAMEL_STORE_INFO_FOLDER_FLAGGED;
 
-	p = _PRIVATE(s) = g_malloc0(sizeof(*p));
+		info->flags = flags;
+	}
+
+	if (!ferror (in))
+		return info;
 
-	s->store_info_size = sizeof(CamelStoreInfo);
+	camel_store_summary_info_free (summary, info);
 
-	s->store_info_chunks = NULL;
+	return NULL;
+}
 
-	s->version = CAMEL_STORE_SUMMARY_VERSION;
-	s->flags = 0;
-	s->count = 0;
-	s->time = 0;
+static gint
+store_summary_store_info_save (CamelStoreSummary *summary,
+                               FILE *out,
+                               CamelStoreInfo *info)
+{
+	io (printf ("Saving folder info\n"));
 
-	s->folders = g_ptr_array_new();
-	s->folders_path = g_hash_table_new(g_str_hash, g_str_equal);
+	camel_file_util_encode_string (
+		out, camel_store_info_path (summary, info));
+	camel_file_util_encode_uint32 (out, info->flags);
+	camel_file_util_encode_uint32 (out, info->unread);
+	camel_file_util_encode_uint32 (out, info->total);
 
-	p->summary_lock = g_mutex_new();
-	p->io_lock = g_mutex_new();
-	p->alloc_lock = g_mutex_new();
-	p->ref_lock = g_mutex_new();
+	return ferror (out);
 }
 
 static void
-camel_store_summary_finalise (CamelObject *obj)
+store_summary_store_info_free (CamelStoreSummary *summary,
+                               CamelStoreInfo *info)
 {
-	struct _CamelStoreSummaryPrivate *p;
-	CamelStoreSummary *s = (CamelStoreSummary *)obj;
+	g_free (info->path);
+	g_free (info->uri);
+	g_slice_free1 (summary->store_info_size, info);
+}
 
-	p = _PRIVATE(obj);
+static const gchar *
+store_summary_store_info_string (CamelStoreSummary *summary,
+                                 const CamelStoreInfo *info,
+                                 gint type)
+{
+	const gchar *p;
 
-	camel_store_summary_clear(s);
-	g_ptr_array_free(s->folders, TRUE);
-	g_hash_table_destroy(s->folders_path);
+	/* FIXME: Locks? */
 
-	g_free(s->summary_path);
+	g_assert (info != NULL);
 
-	if (s->store_info_chunks)
-		e_memchunk_destroy(s->store_info_chunks);
+	switch (type) {
+	case CAMEL_STORE_INFO_PATH:
+		return info->path;
+	case CAMEL_STORE_INFO_NAME:
+		p = strrchr (info->path, '/');
+		if (p)
+			return p+1;
+		else
+			return info->path;
+	case CAMEL_STORE_INFO_URI:
+		if (info->uri == NULL) {
+			CamelURL *uri;
 
-	g_mutex_free(p->summary_lock);
-	g_mutex_free(p->io_lock);
-	g_mutex_free(p->alloc_lock);
-	g_mutex_free(p->ref_lock);
+			uri = camel_url_new_with_base (summary->uri_base, info->path);
+			((CamelStoreInfo *)info)->uri = camel_url_to_string (uri, 0);
+			camel_url_free (uri);
+		}
+		return info->uri;
+	}
 
-	g_free(p);
+	return "";
 }
 
-CamelType
-camel_store_summary_get_type (void)
+static void
+store_summary_store_info_set_string (CamelStoreSummary *summary,
+                                     CamelStoreInfo *info,
+                                     gint type,
+                                     const gchar *str)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	const gchar *p;
+	gchar *v;
+	gint len;
+
+	g_assert (info != NULL);
 
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (), "CamelStoreSummary",
-					    sizeof (CamelStoreSummary),
-					    sizeof (CamelStoreSummaryClass),
-					    (CamelObjectClassInitFunc) camel_store_summary_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_store_summary_init,
-					    (CamelObjectFinalizeFunc) camel_store_summary_finalise);
+	switch (type) {
+	case CAMEL_STORE_INFO_PATH:
+		CAMEL_STORE_SUMMARY_LOCK (summary, summary_lock);
+		g_hash_table_remove (summary->folders_path, (gchar *)camel_store_info_path (summary, info));
+		g_free (info->path);
+		g_free (info->uri);
+		info->path = g_strdup (str);
+		g_hash_table_insert (summary->folders_path, (gchar *)camel_store_info_path (summary, info), info);
+		summary->flags |= CAMEL_STORE_SUMMARY_DIRTY;
+		CAMEL_STORE_SUMMARY_UNLOCK (summary, summary_lock);
+		break;
+	case CAMEL_STORE_INFO_NAME:
+		CAMEL_STORE_SUMMARY_LOCK (summary, summary_lock);
+		g_hash_table_remove (summary->folders_path, (gchar *)camel_store_info_path (summary, info));
+		p = strrchr (info->path, '/');
+		if (p) {
+			len = p-info->path+1;
+			v = g_malloc (len+strlen (str)+1);
+			memcpy (v, info->path, len);
+			strcpy (v+len, str);
+		} else {
+			v = g_strdup (str);
+		}
+		g_free (info->path);
+		info->path = v;
+		g_hash_table_insert (summary->folders_path, (gchar *)camel_store_info_path (summary, info), info);
+		CAMEL_STORE_SUMMARY_UNLOCK (summary, summary_lock);
+		break;
+	case CAMEL_STORE_INFO_URI:
+		g_warning ("Cannot set store info uri, aborting");
+		abort ();
+		break;
 	}
+}
+
+static void
+store_summary_class_init (CamelStoreSummaryClass *class)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelStoreSummaryPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = store_summary_finalize;
+
+	class->summary_header_load = store_summary_summary_header_load;
+	class->summary_header_save = store_summary_summary_header_save;
+	class->store_info_new  = store_summary_store_info_new;
+	class->store_info_load = store_summary_store_info_load;
+	class->store_info_save = store_summary_store_info_save;
+	class->store_info_free = store_summary_store_info_free;
+	class->store_info_string = store_summary_store_info_string;
+	class->store_info_set_string = store_summary_store_info_set_string;
+}
+
+static void
+store_summary_init (CamelStoreSummary *summary)
+{
+	summary->priv = CAMEL_STORE_SUMMARY_GET_PRIVATE (summary);
+
+	summary->store_info_size = sizeof (CamelStoreInfo);
+
+	summary->store_info_chunks = NULL;
+
+	summary->version = CAMEL_STORE_SUMMARY_VERSION;
+	summary->flags = 0;
+	summary->count = 0;
+	summary->time = 0;
+
+	summary->folders = g_ptr_array_new ();
+	summary->folders_path = g_hash_table_new (g_str_hash, g_str_equal);
+
+	summary->priv->summary_lock = g_mutex_new ();
+	summary->priv->io_lock = g_mutex_new ();
+	summary->priv->alloc_lock = g_mutex_new ();
+	summary->priv->ref_lock = g_mutex_new ();
+}
+
+GType
+camel_store_summary_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelStoreSummary",
+			sizeof (CamelStoreSummaryClass),
+			(GClassInitFunc) store_summary_class_init,
+			sizeof (CamelStoreSummary),
+			(GInstanceInitFunc) store_summary_init,
+			0);
 
 	return type;
 }
@@ -166,7 +361,7 @@ camel_store_summary_get_type (void)
 CamelStoreSummary *
 camel_store_summary_new (void)
 {
-	CamelStoreSummary *new = CAMEL_STORE_SUMMARY ( camel_object_new (camel_store_summary_get_type ()));	return new;
+	return g_object_new (CAMEL_TYPE_STORE_SUMMARY, NULL);
 }
 
 /**
@@ -177,14 +372,14 @@ camel_store_summary_new (void)
  * Set the filename where the summary will be loaded to/saved from.
  **/
 void
-camel_store_summary_set_filename(CamelStoreSummary *s, const gchar *name)
+camel_store_summary_set_filename (CamelStoreSummary *s, const gchar *name)
 {
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 
-	g_free(s->summary_path);
-	s->summary_path = g_strdup(name);
+	g_free (s->summary_path);
+	s->summary_path = g_strdup (name);
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 }
 
 /**
@@ -195,15 +390,15 @@ camel_store_summary_set_filename(CamelStoreSummary *s, const gchar *name)
  * Sets the base URI for the summary.
  **/
 void
-camel_store_summary_set_uri_base(CamelStoreSummary *s, CamelURL *base)
+camel_store_summary_set_uri_base (CamelStoreSummary *s, CamelURL *base)
 {
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 
 	if (s->uri_base)
-		camel_url_free(s->uri_base);
-	s->uri_base = camel_url_new_with_base(base, "");
+		camel_url_free (s->uri_base);
+	s->uri_base = camel_url_new_with_base (base, "");
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 }
 
 /**
@@ -215,7 +410,7 @@ camel_store_summary_set_uri_base(CamelStoreSummary *s, CamelURL *base)
  * Returns: the number of items gint he summary.
  **/
 gint
-camel_store_summary_count(CamelStoreSummary *s)
+camel_store_summary_count (CamelStoreSummary *s)
 {
 	return s->folders->len;
 }
@@ -235,22 +430,22 @@ camel_store_summary_count(CamelStoreSummary *s)
  * Returns: the summary item, or %NULL if @index is out of range
  **/
 CamelStoreInfo *
-camel_store_summary_index(CamelStoreSummary *s, gint i)
+camel_store_summary_index (CamelStoreSummary *s, gint i)
 {
 	CamelStoreInfo *info = NULL;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, ref_lock);
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, ref_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 
 	if (i<s->folders->len)
-		info = g_ptr_array_index(s->folders, i);
+		info = g_ptr_array_index (s->folders, i);
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 
 	if (info)
 		info->refcount++;
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
 
 	return info;
 }
@@ -267,23 +462,23 @@ camel_store_summary_index(CamelStoreSummary *s, gint i)
  * Returns: the summary array
  **/
 GPtrArray *
-camel_store_summary_array(CamelStoreSummary *s)
+camel_store_summary_array (CamelStoreSummary *s)
 {
 	CamelStoreInfo *info;
-	GPtrArray *res = g_ptr_array_new();
+	GPtrArray *res = g_ptr_array_new ();
 	gint i;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, ref_lock);
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, ref_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 
-	g_ptr_array_set_size(res, s->folders->len);
+	g_ptr_array_set_size (res, s->folders->len);
 	for (i=0;i<s->folders->len;i++) {
-		info = res->pdata[i] = g_ptr_array_index(s->folders, i);
+		info = res->pdata[i] = g_ptr_array_index (s->folders, i);
 		info->refcount++;
 	}
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
-	CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
 
 	return res;
 }
@@ -296,14 +491,14 @@ camel_store_summary_array(CamelStoreSummary *s)
  * Free the folder summary array.
  **/
 void
-camel_store_summary_array_free(CamelStoreSummary *s, GPtrArray *array)
+camel_store_summary_array_free (CamelStoreSummary *s, GPtrArray *array)
 {
 	gint i;
 
 	for (i=0;i<array->len;i++)
-		camel_store_summary_info_free(s, array->pdata[i]);
+		camel_store_summary_info_free (s, array->pdata[i]);
 
-	g_ptr_array_free(array, TRUE);
+	g_ptr_array_free (array, TRUE);
 }
 
 /**
@@ -322,21 +517,21 @@ camel_store_summary_array_free(CamelStoreSummary *s, GPtrArray *array)
  * available
  **/
 CamelStoreInfo *
-camel_store_summary_path(CamelStoreSummary *s, const gchar *path)
+camel_store_summary_path (CamelStoreSummary *s, const gchar *path)
 {
 	CamelStoreInfo *info;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, ref_lock);
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, ref_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 
-	info = g_hash_table_lookup(s->folders_path, path);
+	info = g_hash_table_lookup (s->folders_path, path);
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 
 	if (info)
 		info->refcount++;
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
 
 	return info;
 }
@@ -350,33 +545,38 @@ camel_store_summary_path(CamelStoreSummary *s, const gchar *path)
  * Returns: %0 on success or %-1 on fail
  **/
 gint
-camel_store_summary_load(CamelStoreSummary *s)
+camel_store_summary_load (CamelStoreSummary *s)
 {
 	FILE *in;
 	gint i;
 	CamelStoreInfo *info;
+	CamelStoreSummaryClass *class;
 
-	g_assert(s->summary_path);
+	g_return_val_if_fail (CAMEL_IS_STORE_SUMMARY (s), -1);
+	g_return_val_if_fail (s->summary_path != NULL, -1);
 
-	in = g_fopen(s->summary_path, "rb");
+	in = g_fopen (s->summary_path, "rb");
 	if (in == NULL)
 		return -1;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, io_lock);
-	if ( ((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in) == -1)
+	class = CAMEL_STORE_SUMMARY_GET_CLASS (s);
+	g_return_val_if_fail (class->store_info_load != NULL, -1);
+
+	CAMEL_STORE_SUMMARY_LOCK (s, io_lock);
+	if (class->summary_header_load (s, in) == -1)
 		goto error;
 
 	/* now read in each message ... */
 	for (i=0;i<s->count;i++) {
-		info = ((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->store_info_load(s, in);
+		info = class->store_info_load (s, in);
 
 		if (info == NULL)
 			goto error;
 
-		camel_store_summary_add(s, info);
+		camel_store_summary_add (s, info);
 	}
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, io_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, io_lock);
 
 	if (fclose (in) != 0)
 		return -1;
@@ -388,7 +588,7 @@ camel_store_summary_load(CamelStoreSummary *s)
 error:
 	i = ferror (in);
 	g_warning ("Cannot load summary file: %s", g_strerror (ferror (in)));
-	CAMEL_STORE_SUMMARY_UNLOCK(s, io_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, io_lock);
 	fclose (in);
 	s->flags |= ~CAMEL_STORE_SUMMARY_DIRTY;
 	errno = i;
@@ -406,46 +606,51 @@ error:
  * Returns: %0 on succes or %-1 on fail
  **/
 gint
-camel_store_summary_save(CamelStoreSummary *s)
+camel_store_summary_save (CamelStoreSummary *s)
 {
 	FILE *out;
 	gint fd;
 	gint i;
 	guint32 count;
 	CamelStoreInfo *info;
+	CamelStoreSummaryClass *class;
 
-	g_assert(s->summary_path);
+	g_return_val_if_fail (CAMEL_IS_STORE_SUMMARY (s), -1);
+	g_return_val_if_fail (s->summary_path != NULL, -1);
 
-	io(printf("** saving summary\n"));
+	io (printf ("** saving summary\n"));
 
 	if ((s->flags & CAMEL_STORE_SUMMARY_DIRTY) == 0) {
-		io(printf("**  summary clean no save\n"));
+		io (printf ("**  summary clean no save\n"));
 		return 0;
 	}
 
-	fd = g_open(s->summary_path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
+	fd = g_open (s->summary_path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
 	if (fd == -1) {
-		io(printf("**  open error: %s\n", g_strerror (errno)));
+		io (printf ("**  open error: %s\n", g_strerror (errno)));
 		return -1;
 	}
 
-	out = fdopen(fd, "wb");
+	out = fdopen (fd, "wb");
 	if ( out == NULL ) {
 		i = errno;
-		printf("**  fdopen error: %s\n", g_strerror (errno));
-		close(fd);
+		printf ("**  fdopen error: %s\n", g_strerror (errno));
+		close (fd);
 		errno = i;
 		return -1;
 	}
 
-	io(printf("saving header\n"));
+	class = CAMEL_STORE_SUMMARY_GET_CLASS (s);
+	g_return_val_if_fail (class->summary_header_save != NULL, -1);
 
-	CAMEL_STORE_SUMMARY_LOCK(s, io_lock);
+	io (printf ("saving header\n"));
 
-	if ( ((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_save(s, out) == -1) {
+	CAMEL_STORE_SUMMARY_LOCK (s, io_lock);
+
+	if (class->summary_header_save (s, out) == -1) {
 		i = errno;
-		fclose(out);
-		CAMEL_STORE_SUMMARY_UNLOCK(s, io_lock);
+		fclose (out);
+		CAMEL_STORE_SUMMARY_UNLOCK (s, io_lock);
 		errno = i;
 		return -1;
 	}
@@ -457,10 +662,10 @@ camel_store_summary_save(CamelStoreSummary *s)
 	count = s->folders->len;
 	for (i=0;i<count;i++) {
 		info = s->folders->pdata[i];
-		((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->store_info_save(s, out, info);
+		class->store_info_save (s, out, info);
 	}
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, io_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, io_lock);
 
 	if (fflush (out) != 0 || fsync (fileno (out)) == -1) {
 		i = errno;
@@ -487,22 +692,27 @@ camel_store_summary_save(CamelStoreSummary *s)
  * Returns: %0 on success or %-1 on fail
  **/
 gint
-camel_store_summary_header_load(CamelStoreSummary *s)
+camel_store_summary_header_load (CamelStoreSummary *s)
 {
+	CamelStoreSummaryClass *class;
 	FILE *in;
 	gint ret;
 
-	g_assert(s->summary_path);
+	g_return_val_if_fail (CAMEL_IS_STORE_SUMMARY (s), -1);
+	g_return_val_if_fail (s->summary_path != NULL, -1);
 
-	in = g_fopen(s->summary_path, "rb");
+	in = g_fopen (s->summary_path, "rb");
 	if (in == NULL)
 		return -1;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, io_lock);
-	ret = ((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in);
-	CAMEL_STORE_SUMMARY_UNLOCK(s, io_lock);
+	class = CAMEL_STORE_SUMMARY_GET_CLASS (s);
+	g_return_val_if_fail (class->summary_header_load != NULL, -1);
 
-	fclose(in);
+	CAMEL_STORE_SUMMARY_LOCK (s, io_lock);
+	ret = class->summary_header_load (s, in);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, io_lock);
+
+	fclose (in);
 	s->flags &= ~CAMEL_STORE_SUMMARY_DIRTY;
 	return ret;
 }
@@ -521,23 +731,23 @@ camel_store_summary_header_load(CamelStoreSummary *s)
  * class.  And MUST NOT be allocated directly using malloc.
  **/
 void
-camel_store_summary_add(CamelStoreSummary *s, CamelStoreInfo *info)
+camel_store_summary_add (CamelStoreSummary *s, CamelStoreInfo *info)
 {
 	if (info == NULL)
 		return;
 
-	if (camel_store_info_path(s, info) == NULL) {
-		g_warning("Trying to add a folder info with missing required path name\n");
+	if (camel_store_info_path (s, info) == NULL) {
+		g_warning ("Trying to add a folder info with missing required path name\n");
 		return;
 	}
 
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 
-	g_ptr_array_add(s->folders, info);
-	g_hash_table_insert(s->folders_path, (gchar *)camel_store_info_path(s, info), info);
+	g_ptr_array_add (s->folders, info);
+	g_hash_table_insert (s->folders_path, (gchar *)camel_store_info_path (s, info), info);
 	s->flags |= CAMEL_STORE_SUMMARY_DIRTY;
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 }
 
 /**
@@ -550,24 +760,24 @@ camel_store_summary_add(CamelStoreSummary *s, CamelStoreInfo *info)
  * Returns: the newly added record
  **/
 CamelStoreInfo *
-camel_store_summary_add_from_path(CamelStoreSummary *s, const gchar *path)
+camel_store_summary_add_from_path (CamelStoreSummary *s, const gchar *path)
 {
 	CamelStoreInfo *info;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 
-	info = g_hash_table_lookup(s->folders_path, path);
+	info = g_hash_table_lookup (s->folders_path, path);
 	if (info != NULL) {
-		g_warning("Trying to add folder '%s' to summary that already has it", path);
+		g_warning ("Trying to add folder '%s' to summary that already has it", path);
 		info = NULL;
 	} else {
-		info = camel_store_summary_info_new_from_path(s, path);
-		g_ptr_array_add(s->folders, info);
-		g_hash_table_insert(s->folders_path, (gchar *)camel_store_info_path(s, info), info);
+		info = camel_store_summary_info_new_from_path (s, path);
+		g_ptr_array_add (s->folders, info);
+		g_hash_table_insert (s->folders_path, (gchar *)camel_store_info_path (s, info), info);
 		s->flags |= CAMEL_STORE_SUMMARY_DIRTY;
 	}
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 
 	return info;
 }
@@ -586,9 +796,18 @@ camel_store_summary_add_from_path(CamelStoreSummary *s, const gchar *path)
  * Returns: the #CamelStoreInfo associated with @path
  **/
 CamelStoreInfo *
-camel_store_summary_info_new_from_path(CamelStoreSummary *s, const gchar *path)
+camel_store_summary_info_new_from_path (CamelStoreSummary *s,
+                                        const gchar *path)
 {
-	return ((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->store_info_new(s, path);
+	CamelStoreSummaryClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_STORE_SUMMARY (s), NULL);
+	g_return_val_if_fail (path != NULL, NULL);
+
+	class = CAMEL_STORE_SUMMARY_GET_CLASS (s);
+	g_return_val_if_fail (class->store_info_new != NULL, NULL);
+
+	return class->store_info_new (s, path);
 }
 
 /**
@@ -599,24 +818,29 @@ camel_store_summary_info_new_from_path(CamelStoreSummary *s, const gchar *path)
  * Unref and potentially free @info, and all associated memory.
  **/
 void
-camel_store_summary_info_free(CamelStoreSummary *s, CamelStoreInfo *info)
+camel_store_summary_info_free (CamelStoreSummary *s, CamelStoreInfo *info)
 {
-	g_assert(info);
-	g_assert(s);
+	CamelStoreSummaryClass *class;
+
+	g_return_if_fail (CAMEL_IS_STORE_SUMMARY (s));
+	g_return_if_fail (info != NULL);
 
-	CAMEL_STORE_SUMMARY_LOCK(s, ref_lock);
+	class = CAMEL_STORE_SUMMARY_GET_CLASS (s);
+	g_return_if_fail (class->store_info_free != NULL);
 
-	g_assert(info->refcount >= 1);
+	CAMEL_STORE_SUMMARY_LOCK (s, ref_lock);
+
+	g_assert (info->refcount >= 1);
 
 	info->refcount--;
 	if (info->refcount > 0) {
-		CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
+		CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
 		return;
 	}
 
-	CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
 
-	((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->store_info_free(s, info);
+	class->store_info_free (s, info);
 }
 
 /**
@@ -627,15 +851,15 @@ camel_store_summary_info_free(CamelStoreSummary *s, CamelStoreInfo *info)
  * Add an extra reference to @info.
  **/
 void
-camel_store_summary_info_ref(CamelStoreSummary *s, CamelStoreInfo *info)
+camel_store_summary_info_ref (CamelStoreSummary *s, CamelStoreInfo *info)
 {
-	g_assert(info);
-	g_assert(s);
+	g_assert (info);
+	g_assert (s);
 
-	CAMEL_STORE_SUMMARY_LOCK(s, ref_lock);
-	g_assert(info->refcount >= 1);
+	CAMEL_STORE_SUMMARY_LOCK (s, ref_lock);
+	g_assert (info->refcount >= 1);
 	info->refcount++;
-	CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
 }
 
 /**
@@ -646,11 +870,11 @@ camel_store_summary_info_ref(CamelStoreSummary *s, CamelStoreInfo *info)
  * written back to disk.
  **/
 void
-camel_store_summary_touch(CamelStoreSummary *s)
+camel_store_summary_touch (CamelStoreSummary *s)
 {
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 	s->flags |= CAMEL_STORE_SUMMARY_DIRTY;
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 }
 
 /**
@@ -660,24 +884,24 @@ camel_store_summary_touch(CamelStoreSummary *s)
  * Empty the summary contents.
  **/
 void
-camel_store_summary_clear(CamelStoreSummary *s)
+camel_store_summary_clear (CamelStoreSummary *s)
 {
 	gint i;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
-	if (camel_store_summary_count(s) == 0) {
-		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
+	if (camel_store_summary_count (s) == 0) {
+		CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 		return;
 	}
 
 	for (i=0;i<s->folders->len;i++)
-		camel_store_summary_info_free(s, s->folders->pdata[i]);
+		camel_store_summary_info_free (s, s->folders->pdata[i]);
 
-	g_ptr_array_set_size(s->folders, 0);
-	g_hash_table_destroy(s->folders_path);
-	s->folders_path = g_hash_table_new(g_str_hash, g_str_equal);
+	g_ptr_array_set_size (s->folders, 0);
+	g_hash_table_destroy (s->folders_path);
+	s->folders_path = g_hash_table_new (g_str_hash, g_str_equal);
 	s->flags |= CAMEL_STORE_SUMMARY_DIRTY;
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 }
 
 /**
@@ -688,15 +912,15 @@ camel_store_summary_clear(CamelStoreSummary *s)
  * Remove a specific @info record from the summary.
  **/
 void
-camel_store_summary_remove(CamelStoreSummary *s, CamelStoreInfo *info)
+camel_store_summary_remove (CamelStoreSummary *s, CamelStoreInfo *info)
 {
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
-	g_hash_table_remove(s->folders_path, camel_store_info_path(s, info));
-	g_ptr_array_remove(s->folders, info);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
+	g_hash_table_remove (s->folders_path, camel_store_info_path (s, info));
+	g_ptr_array_remove (s->folders, info);
 	s->flags |= CAMEL_STORE_SUMMARY_DIRTY;
-	CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 
-	camel_store_summary_info_free(s, info);
+	camel_store_summary_info_free (s, info);
 }
 
 /**
@@ -707,23 +931,23 @@ camel_store_summary_remove(CamelStoreSummary *s, CamelStoreInfo *info)
  * Remove a specific info record from the summary, by @path.
  **/
 void
-camel_store_summary_remove_path(CamelStoreSummary *s, const gchar *path)
+camel_store_summary_remove_path (CamelStoreSummary *s, const gchar *path)
 {
         CamelStoreInfo *oldinfo;
         gchar *oldpath;
 
-	CAMEL_STORE_SUMMARY_LOCK(s, ref_lock);
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
-        if (g_hash_table_lookup_extended(s->folders_path, path, (gpointer)&oldpath, (gpointer)&oldinfo)) {
+	CAMEL_STORE_SUMMARY_LOCK (s, ref_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
+        if (g_hash_table_lookup_extended (s->folders_path, path, (gpointer)&oldpath, (gpointer)&oldinfo)) {
 		/* make sure it doesn't vanish while we're removing it */
 		oldinfo->refcount++;
-		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
-		CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
-		camel_store_summary_remove(s, oldinfo);
-		camel_store_summary_info_free(s, oldinfo);
+		CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
+		CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
+		camel_store_summary_remove (s, oldinfo);
+		camel_store_summary_info_free (s, oldinfo);
         } else {
-		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
-		CAMEL_STORE_SUMMARY_UNLOCK(s, ref_lock);
+		CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
+		CAMEL_STORE_SUMMARY_UNLOCK (s, ref_lock);
 	}
 }
 
@@ -735,65 +959,21 @@ camel_store_summary_remove_path(CamelStoreSummary *s, const gchar *path)
  * Remove a specific info record from the summary, by index.
  **/
 void
-camel_store_summary_remove_index(CamelStoreSummary *s, gint index)
+camel_store_summary_remove_index (CamelStoreSummary *s, gint index)
 {
-	CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
+	CAMEL_STORE_SUMMARY_LOCK (s, summary_lock);
 	if (index < s->folders->len) {
 		CamelStoreInfo *info = s->folders->pdata[index];
 
-		g_hash_table_remove(s->folders_path, camel_store_info_path(s, info));
-		g_ptr_array_remove_index(s->folders, index);
+		g_hash_table_remove (s->folders_path, camel_store_info_path (s, info));
+		g_ptr_array_remove_index (s->folders, index);
 		s->flags |= CAMEL_STORE_SUMMARY_DIRTY;
 
-		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
-		camel_store_summary_info_free(s, info);
+		CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
+		camel_store_summary_info_free (s, info);
 	} else {
-		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
-	}
-}
-
-static gint
-summary_header_load(CamelStoreSummary *s, FILE *in)
-{
-	gint32 version, flags, count;
-	time_t time;
-
-	fseek(in, 0, SEEK_SET);
-
-	io(printf("Loading header\n"));
-
-	if (camel_file_util_decode_fixed_int32(in, &version) == -1
-	    || camel_file_util_decode_fixed_int32(in, &flags) == -1
-	    || camel_file_util_decode_time_t(in, &time) == -1
-	    || camel_file_util_decode_fixed_int32(in, &count) == -1) {
-		return -1;
-	}
-
-	s->flags = flags;
-	s->time = time;
-	s->count = count;
-	s->version = version;
-
-	if (version < CAMEL_STORE_SUMMARY_VERSION_0) {
-		g_warning("Store summary header version too low");
-		return -1;
+		CAMEL_STORE_SUMMARY_UNLOCK (s, summary_lock);
 	}
-
-	return 0;
-}
-
-static gint
-summary_header_save(CamelStoreSummary *s, FILE *out)
-{
-	fseek(out, 0, SEEK_SET);
-
-	io(printf("Savining header\n"));
-
-	/* always write latest version */
-	camel_file_util_encode_fixed_int32(out, CAMEL_STORE_SUMMARY_VERSION);
-	camel_file_util_encode_fixed_int32(out, s->flags);
-	camel_file_util_encode_time_t(out, s->time);
-	return camel_file_util_encode_fixed_int32(out, camel_store_summary_count(s));
 }
 
 /**
@@ -806,11 +986,11 @@ summary_header_save(CamelStoreSummary *s, FILE *out)
  * Returns: the newly allocated #CamelStoreInfo
  **/
 CamelStoreInfo *
-camel_store_summary_info_new(CamelStoreSummary *s)
+camel_store_summary_info_new (CamelStoreSummary *s)
 {
 	CamelStoreInfo *info;
 
-	info = g_slice_alloc0(s->store_info_size);
+	info = g_slice_alloc0 (s->store_info_size);
 	info->refcount = 1;
 	return info;
 }
@@ -826,9 +1006,19 @@ camel_store_summary_info_new(CamelStoreSummary *s)
  * Returns: the string value
  **/
 const gchar *
-camel_store_info_string(CamelStoreSummary *s, const CamelStoreInfo *info, gint type)
+camel_store_info_string (CamelStoreSummary *s,
+                         const CamelStoreInfo *info,
+                         gint type)
 {
-	return ((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->store_info_string(s, info, type);
+	CamelStoreSummaryClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_STORE_SUMMARY (s), NULL);
+	g_return_val_if_fail (info != NULL, NULL);
+
+	class = CAMEL_STORE_SUMMARY_GET_CLASS (s);
+	g_return_val_if_fail (class->store_info_string != NULL, NULL);
+
+	return class->store_info_string (s, info, type);
 }
 
 /**
@@ -841,157 +1031,20 @@ camel_store_info_string(CamelStoreSummary *s, const CamelStoreInfo *info, gint t
  * Set a specific string on the @info.
  **/
 void
-camel_store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *info, gint type, const gchar *value)
-{
-	((CamelStoreSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->store_info_set_string(s, info, type, value);
-}
-
-static CamelStoreInfo *
-store_info_new(CamelStoreSummary *s, const gchar *f)
-{
-	CamelStoreInfo *info;
-
-	info = camel_store_summary_info_new(s);
-
-	info->path = g_strdup(f);
-	info->unread = CAMEL_STORE_INFO_FOLDER_UNKNOWN;
-	info->total = CAMEL_STORE_INFO_FOLDER_UNKNOWN;
-
-	return info;
-}
-
-static CamelStoreInfo *
-store_info_load(CamelStoreSummary *s, FILE *in)
-{
-	CamelStoreInfo *info;
-
-	info = camel_store_summary_info_new(s);
-
-	io(printf("Loading folder info\n"));
-
-	camel_file_util_decode_string(in, &info->path);
-	camel_file_util_decode_uint32(in, &info->flags);
-	camel_file_util_decode_uint32(in, &info->unread);
-	camel_file_util_decode_uint32(in, &info->total);
-
-	/* Ok, brown paper bag bug - prior to version 2 of the file, flags are
-	   stored using the bit number, not the bit. Try to recover as best we can */
-	if (s->version < CAMEL_STORE_SUMMARY_VERSION_2) {
-		guint32 flags = 0;
-
-		if (info->flags & 1)
-			flags |= CAMEL_STORE_INFO_FOLDER_NOSELECT;
-		if (info->flags & 2)
-			flags |= CAMEL_STORE_INFO_FOLDER_READONLY;
-		if (info->flags & 3)
-			flags |= CAMEL_STORE_INFO_FOLDER_SUBSCRIBED;
-		if (info->flags & 4)
-			flags |= CAMEL_STORE_INFO_FOLDER_FLAGGED;
-
-		info->flags = flags;
-	}
-
-	if (!ferror(in))
-		return info;
-
-	camel_store_summary_info_free(s, info);
-
-	return NULL;
-}
-
-static gint
-store_info_save(CamelStoreSummary *s, FILE *out, CamelStoreInfo *info)
-{
-	io(printf("Saving folder info\n"));
-
-	camel_file_util_encode_string(out, camel_store_info_path(s, info));
-	camel_file_util_encode_uint32(out, info->flags);
-	camel_file_util_encode_uint32(out, info->unread);
-	camel_file_util_encode_uint32(out, info->total);
-
-	return ferror(out);
-}
-
-static void
-store_info_free(CamelStoreSummary *s, CamelStoreInfo *info)
-{
-	g_free(info->path);
-	g_free(info->uri);
-	g_slice_free1(s->store_info_size, info);
-}
-
-static const gchar *
-store_info_string(CamelStoreSummary *s, const CamelStoreInfo *info, gint type)
+camel_store_info_set_string (CamelStoreSummary *s,
+                             CamelStoreInfo *info,
+                             gint type,
+                             const gchar *value)
 {
-	const gchar *p;
-
-	/* FIXME: Locks? */
+	CamelStoreSummaryClass *class;
 
-	g_assert (info != NULL);
-
-	switch (type) {
-	case CAMEL_STORE_INFO_PATH:
-		return info->path;
-	case CAMEL_STORE_INFO_NAME:
-		p = strrchr(info->path, '/');
-		if (p)
-			return p+1;
-		else
-			return info->path;
-	case CAMEL_STORE_INFO_URI:
-		if (info->uri == NULL) {
-			CamelURL *uri;
+	/* XXX Can 'value' be NULL? */
+	g_return_if_fail (CAMEL_IS_STORE_SUMMARY (s));
+	g_return_if_fail (info != NULL);
 
-			uri = camel_url_new_with_base(s->uri_base, info->path);
-			((CamelStoreInfo *)info)->uri = camel_url_to_string(uri, 0);
-			camel_url_free(uri);
-		}
-		return info->uri;
-	}
+	class = CAMEL_STORE_SUMMARY_GET_CLASS (s);
+	g_return_if_fail (class->store_info_set_string != NULL);
 
-	return "";
+	class->store_info_set_string (s, info, type, value);
 }
 
-static void
-store_info_set_string (CamelStoreSummary *s, CamelStoreInfo *info, gint type, const gchar *str)
-{
-	const gchar *p;
-	gchar *v;
-	gint len;
-
-	g_assert (info != NULL);
-
-	switch (type) {
-	case CAMEL_STORE_INFO_PATH:
-		CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
-		g_hash_table_remove(s->folders_path, (gchar *)camel_store_info_path(s, info));
-		g_free(info->path);
-		g_free(info->uri);
-		info->path = g_strdup(str);
-		g_hash_table_insert(s->folders_path, (gchar *)camel_store_info_path(s, info), info);
-		s->flags |= CAMEL_STORE_SUMMARY_DIRTY;
-		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
-		break;
-	case CAMEL_STORE_INFO_NAME:
-		CAMEL_STORE_SUMMARY_LOCK(s, summary_lock);
-		g_hash_table_remove(s->folders_path, (gchar *)camel_store_info_path(s, info));
-		p = strrchr(info->path, '/');
-		if (p) {
-			len = p-info->path+1;
-			v = g_malloc(len+strlen(str)+1);
-			memcpy(v, info->path, len);
-			strcpy(v+len, str);
-		} else {
-			v = g_strdup(str);
-		}
-		g_free(info->path);
-		info->path = v;
-		g_hash_table_insert(s->folders_path, (gchar *)camel_store_info_path(s, info), info);
-		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
-		break;
-	case CAMEL_STORE_INFO_URI:
-		g_warning("Cannot set store info uri, aborting");
-		abort();
-		break;
-	}
-}
diff --git a/camel/camel-store-summary.h b/camel/camel-store-summary.h
index 1a79f00..58105e1 100644
--- a/camel/camel-store-summary.h
+++ b/camel/camel-store-summary.h
@@ -19,25 +19,43 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_STORE_SUMMARY_H
-#define _CAMEL_STORE_SUMMARY_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
 
-#include <stdio.h>
+#ifndef CAMEL_STORE_SUMMARY_H
+#define CAMEL_STORE_SUMMARY_H
 
-#include <glib.h>
+#include <stdio.h>
 
 #include <camel/camel-mime-parser.h>
 #include <camel/camel-object.h>
 #include <camel/camel-url.h>
 
-#define CAMEL_STORE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_store_summary_get_type (), CamelStoreSummary)
-#define CAMEL_STORE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_store_summary_get_type (), CamelStoreSummaryClass)
-#define CAMEL_IS_STORE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_store_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_STORE_SUMMARY \
+	(camel_store_summary_get_type ())
+#define CAMEL_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummary))
+#define CAMEL_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummaryClass))
+#define CAMEL_IS_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STORE_SUMMARY))
+#define CAMEL_IS_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STORE_SUMMARY))
+#define CAMEL_STORE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STORE_SUMMARY, CamelStoreSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelStoreSummary      CamelStoreSummary;
+typedef struct _CamelStoreSummary CamelStoreSummary;
 typedef struct _CamelStoreSummaryClass CamelStoreSummaryClass;
+typedef struct _CamelStoreSummaryPrivate CamelStoreSummaryPrivate;
 
 typedef struct _CamelStoreInfo CamelStoreInfo;
 
@@ -87,7 +105,7 @@ typedef enum _CamelStoreSummaryFlags {
 struct _CamelStoreSummary {
 	CamelObject parent;
 
-	struct _CamelStoreSummaryPrivate *priv;
+	CamelStoreSummaryPrivate *priv;
 
 	/* header info */
 	guint32 version;	/* version of base part of file */
@@ -126,7 +144,7 @@ struct _CamelStoreSummaryClass {
 	void (*store_info_set_string)(CamelStoreSummary *, CamelStoreInfo *, int, const gchar *);
 };
 
-CamelType			 camel_store_summary_get_type	(void);
+GType			 camel_store_summary_get_type	(void);
 CamelStoreSummary      *camel_store_summary_new	(void);
 
 void camel_store_summary_set_filename(CamelStoreSummary *summary, const gchar *filename);
@@ -180,4 +198,4 @@ void camel_store_info_set_string(CamelStoreSummary *summary, CamelStoreInfo *inf
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_STORE_SUMMARY_H */
+#endif /* CAMEL_STORE_SUMMARY_H */
diff --git a/camel/camel-store.c b/camel/camel-store.c
index 9b8d26f..66ce274 100644
--- a/camel/camel-store.c
+++ b/camel/camel-store.c
@@ -31,7 +31,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-db.h"
@@ -46,174 +45,78 @@
 #define d(x)
 #define w(x)
 
-static CamelServiceClass *parent_class = NULL;
+#define CAMEL_STORE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_STORE, CamelStorePrivate))
 
-/* Returns the class for a CamelStore */
-#define CS_CLASS(so) ((CamelStoreClass *)((CamelObject *)(so))->klass)
-
-static CamelFolder *get_folder (CamelStore *store, const gchar *folder_name,
-				guint32 flags, CamelException *ex);
-static CamelFolder *get_inbox (CamelStore *store, CamelException *ex);
-
-static CamelFolder *get_trash (CamelStore *store, CamelException *ex);
-static CamelFolder *get_junk (CamelStore *store, CamelException *ex);
-
-static CamelFolderInfo *create_folder (CamelStore *store,
-				       const gchar *parent_name,
-				       const gchar *folder_name,
-				       CamelException *ex);
-static void delete_folder (CamelStore *store, const gchar *folder_name,
-			   CamelException *ex);
-static void rename_folder (CamelStore *store, const gchar *old_name,
-			   const gchar *new_name, CamelException *ex);
-
-static void store_sync (CamelStore *store, gint expunge, CamelException *ex);
-static CamelFolderInfo *get_folder_info (CamelStore *store, const gchar *top,
-					 guint32 flags, CamelException *ex);
-static void free_folder_info (CamelStore *store, CamelFolderInfo *tree);
-
-static gboolean folder_subscribed (CamelStore *store, const gchar *folder_name);
-static void subscribe_folder (CamelStore *store, const gchar *folder_name, CamelException *ex);
-static void unsubscribe_folder (CamelStore *store, const gchar *folder_name, CamelException *ex);
-
-static void noop (CamelStore *store, CamelException *ex);
-
-static gboolean can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex);
-
-static void construct (CamelService *service, CamelSession *session,
-		       CamelProvider *provider, CamelURL *url,
-		       CamelException *ex);
-
-static gint store_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
-static gint store_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
+static gpointer parent_class;
 
+/**
+ * ignore_no_such_table_exception:
+ * Clears the exception 'ex' when it's the 'no such table' exception.
+ **/
 static void
-camel_store_class_init (CamelStoreClass *camel_store_class)
+ignore_no_such_table_exception (CamelException *ex)
 {
-	CamelObjectClass *camel_object_class = CAMEL_OBJECT_CLASS (camel_store_class);
-	CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS(camel_store_class);
-
-	parent_class = CAMEL_SERVICE_CLASS (camel_type_get_global_classfuncs (camel_service_get_type ()));
-
-	/* virtual method definition */
-	camel_store_class->hash_folder_name = g_str_hash;
-	camel_store_class->compare_folder_name = g_str_equal;
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->get_inbox = get_inbox;
-	camel_store_class->get_trash = get_trash;
-	camel_store_class->get_junk = get_junk;
-	camel_store_class->create_folder = create_folder;
-	camel_store_class->delete_folder = delete_folder;
-	camel_store_class->rename_folder = rename_folder;
-	camel_store_class->sync = store_sync;
-	camel_store_class->get_folder_info = get_folder_info;
-	camel_store_class->free_folder_info = free_folder_info;
-	camel_store_class->folder_subscribed = folder_subscribed;
-	camel_store_class->subscribe_folder = subscribe_folder;
-	camel_store_class->unsubscribe_folder = unsubscribe_folder;
-	camel_store_class->noop = noop;
-	camel_store_class->can_refresh_folder = can_refresh_folder;
-
-	/* virtual method overload */
-	camel_service_class->construct = construct;
-
-	camel_object_class->setv = store_setv;
-	camel_object_class->getv = store_getv;
-
-	camel_object_class_add_event(camel_object_class, "folder_opened", NULL);
-	camel_object_class_add_event(camel_object_class, "folder_created", NULL);
-	camel_object_class_add_event(camel_object_class, "folder_deleted", NULL);
-	camel_object_class_add_event(camel_object_class, "folder_renamed", NULL);
-	camel_object_class_add_event(camel_object_class, "folder_subscribed", NULL);
-	camel_object_class_add_event(camel_object_class, "folder_unsubscribed", NULL);
+	if (ex && camel_exception_is_set (ex) && g_ascii_strncasecmp (camel_exception_get_description (ex), "no such table", 13) == 0)
+		camel_exception_clear (ex);
 }
 
-static void
-camel_store_init (gpointer o)
+static CamelFolder *
+store_get_special (CamelStore *store,
+                   camel_vtrash_folder_t type)
 {
-	CamelStore *store = o;
-	CamelStoreClass *store_class = (CamelStoreClass *)CAMEL_OBJECT_GET_CLASS (o);
-
-	if (store_class->hash_folder_name) {
-		store->folders = camel_object_bag_new(store_class->hash_folder_name,
-						      store_class->compare_folder_name,
-						      (CamelCopyFunc)g_strdup, g_free);
-	} else
-		store->folders = NULL;
+	CamelFolder *folder;
+	GPtrArray *folders;
+	gint i;
 
-	/* set vtrash and vjunk on by default */
-	store->flags = CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK;
-	store->mode = CAMEL_STORE_READ|CAMEL_STORE_WRITE;
+	folder = camel_vtrash_folder_new(store, type);
+	folders = camel_object_bag_list(store->folders);
+	for (i=0;i<folders->len;i++) {
+		if (!CAMEL_IS_VTRASH_FOLDER(folders->pdata[i]))
+			camel_vee_folder_add_folder((CamelVeeFolder *)folder, (CamelFolder *)folders->pdata[i]);
+		g_object_unref (folders->pdata[i]);
+	}
+	g_ptr_array_free(folders, TRUE);
 
-	store->priv = g_malloc0 (sizeof (*store->priv));
-	g_static_rec_mutex_init (&store->priv->folder_lock);
+	return folder;
 }
 
 static void
-camel_store_finalize (CamelObject *object)
+store_finalize (GObject *object)
 {
 	CamelStore *store = CAMEL_STORE (object);
 
-	d(printf ("\ncamel_store_finalize called \n"));
-	if (store->folders)
-		camel_object_bag_destroy(store->folders);
+	if (store->folders != NULL)
+		camel_object_bag_destroy (store->folders);
 
 	g_static_rec_mutex_free (&store->priv->folder_lock);
 
-	if (store->cdb_r) {
+	if (store->cdb_r != NULL) {
 		camel_db_close (store->cdb_r);
 		store->cdb_r = NULL;
 	}
 
-	if (store->cdb_w) {
+	if (store->cdb_w != NULL) {
 		camel_db_close (store->cdb_w);
 		store->cdb_w = NULL;
 	}
 
-	g_free (store->priv);
-}
-
-CamelType
-camel_store_get_type (void)
-{
-	static CamelType camel_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_store_type == CAMEL_INVALID_TYPE) {
-		camel_store_type = camel_type_register (CAMEL_SERVICE_TYPE, "CamelStore",
-							sizeof (CamelStore),
-							sizeof (CamelStoreClass),
-							(CamelObjectClassInitFunc) camel_store_class_init,
-							NULL,
-							(CamelObjectInitFunc) camel_store_init,
-							(CamelObjectFinalizeFunc) camel_store_finalize );
-	}
-
-	return camel_store_type;
-}
-
-static gint
-store_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
-{
-	/* CamelStore doesn't currently have anything to set */
-	return CAMEL_OBJECT_CLASS (parent_class)->setv (object, ex, args);
-}
-
-static gint
-store_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
-{
-	/* CamelStore doesn't currently have anything to get */
-	return CAMEL_OBJECT_CLASS (parent_class)->getv (object, ex, args);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-construct (CamelService *service, CamelSession *session,
-	   CamelProvider *provider, CamelURL *url,
-	   CamelException *ex)
+store_construct (CamelService *service,
+                 CamelSession *session,
+                 CamelProvider *provider,
+                 CamelURL *url,
+                 CamelException *ex)
 {
 	CamelStore *store = CAMEL_STORE(service);
 	gchar *store_db_path, *store_path = NULL;
 
-	parent_class->construct(service, session, provider, url, ex);
+	CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
 	if (camel_exception_is_set (ex))
 		return;
 
@@ -274,15 +177,147 @@ construct (CamelService *service, CamelSession *session,
 }
 
 static CamelFolder *
-get_folder (CamelStore *store, const gchar *folder_name, guint32 flags, CamelException *ex)
+store_get_inbox (CamelStore *store,
+                 CamelException *ex)
 {
-	w(g_warning ("CamelStore::get_folder not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
+	CamelStoreClass *class;
 
-	camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_INVALID,
-			      _("Cannot get folder: Invalid operation on this store"));
+	/* Assume the inbox's name is "inbox" and open with default flags. */
+	class = CAMEL_STORE_GET_CLASS (store);
+	return class->get_folder (store, "inbox", 0, ex);
+}
+
+static CamelFolder *
+store_get_trash (CamelStore *store,
+                 CamelException *ex)
+{
+	return store_get_special (store, CAMEL_VTRASH_FOLDER_TRASH);
+}
 
-	return NULL;
+static CamelFolder *
+store_get_junk (CamelStore *store,
+                CamelException *ex)
+{
+	return store_get_special (store, CAMEL_VTRASH_FOLDER_JUNK);
+}
+
+static void
+store_sync (CamelStore *store,
+            gint expunge,
+            CamelException *ex)
+{
+	GPtrArray *folders;
+	CamelFolder *folder;
+	CamelException x;
+	gint i;
+
+	if (store->folders == NULL)
+		return;
+
+	/* We don't sync any vFolders, that is used to update certain
+	 * vfolder queries mainly, and we're really only interested in
+	 * storing/expunging the physical mails. */
+	camel_exception_init(&x);
+	folders = camel_object_bag_list(store->folders);
+	for (i=0;i<folders->len;i++) {
+		folder = folders->pdata[i];
+		if (!CAMEL_IS_VEE_FOLDER(folder)
+		    && !camel_exception_is_set(&x)) {
+			camel_folder_sync(folder, expunge, &x);
+			ignore_no_such_table_exception (&x);
+		} else if (CAMEL_IS_VEE_FOLDER(folder))
+			camel_vee_folder_sync_headers(folder, NULL); /* Literally don't care of vfolder exceptions */
+		g_object_unref (folder);
+	}
+	camel_exception_xfer(ex, &x);
+	g_ptr_array_free(folders, TRUE);
+}
+
+static void
+store_noop (CamelStore *store,
+            CamelException *ex)
+{
+	/* no-op */
+}
+
+static gboolean
+store_can_refresh_folder (CamelStore *store,
+                          CamelFolderInfo *info,
+                          CamelException *ex)
+{
+	return ((info->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX);
+}
+
+static void
+store_class_init (CamelStoreClass *class)
+{
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+	CamelServiceClass *service_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelStorePrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = store_finalize;
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = store_construct;
+
+	class->hash_folder_name = g_str_hash;
+	class->compare_folder_name = g_str_equal;
+	class->get_inbox = store_get_inbox;
+	class->get_trash = store_get_trash;
+	class->get_junk = store_get_junk;
+	class->sync = store_sync;
+	class->noop = store_noop;
+	class->can_refresh_folder = store_can_refresh_folder;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class_add_event(camel_object_class, "folder_opened", NULL);
+	camel_object_class_add_event(camel_object_class, "folder_created", NULL);
+	camel_object_class_add_event(camel_object_class, "folder_deleted", NULL);
+	camel_object_class_add_event(camel_object_class, "folder_renamed", NULL);
+	camel_object_class_add_event(camel_object_class, "folder_subscribed", NULL);
+	camel_object_class_add_event(camel_object_class, "folder_unsubscribed", NULL);
+}
+
+static void
+store_init (CamelStore *store,
+            CamelStoreClass *store_class)
+{
+	store->priv = CAMEL_STORE_GET_PRIVATE (store);
+
+	if (store_class->hash_folder_name) {
+		store->folders = camel_object_bag_new(store_class->hash_folder_name,
+						      store_class->compare_folder_name,
+						      (CamelCopyFunc)g_strdup, g_free);
+	} else
+		store->folders = NULL;
+
+	/* set vtrash and vjunk on by default */
+	store->flags = CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK;
+	store->mode = CAMEL_STORE_READ | CAMEL_STORE_WRITE;
+
+	g_static_rec_mutex_init (&store->priv->folder_lock);
+}
+
+GType
+camel_store_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SERVICE,
+			"CamelStore",
+			sizeof (CamelStoreClass),
+			(GClassInitFunc) store_class_init,
+			sizeof (CamelStore),
+			(GInstanceInitFunc) store_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -316,7 +351,7 @@ camel_store_get_folder (CamelStore *store, const gchar *folder_name, guint32 fla
 					      _("Cannot create folder '%s': folder exists"),
 					      folder_name);
                         camel_object_bag_abort (store->folders, folder_name);
-			camel_object_unref (folder);
+			g_object_unref (folder);
 			return NULL;
 		}
 	}
@@ -338,24 +373,24 @@ camel_store_get_folder (CamelStore *store, const gchar *folder_name, guint32 fla
 		}
 
 		if ((store->flags & CAMEL_STORE_VTRASH) && strcmp(folder_name, CAMEL_VTRASH_NAME) == 0) {
-			folder = CS_CLASS(store)->get_trash(store, ex);
+			folder = CAMEL_STORE_GET_CLASS(store)->get_trash(store, ex);
 		} else if ((store->flags & CAMEL_STORE_VJUNK) && strcmp(folder_name, CAMEL_VJUNK_NAME) == 0) {
-			folder = CS_CLASS(store)->get_junk(store, ex);
+			folder = CAMEL_STORE_GET_CLASS(store)->get_junk(store, ex);
 		} else {
-			folder = CS_CLASS (store)->get_folder(store, folder_name, flags, ex);
+			folder = CAMEL_STORE_GET_CLASS (store)->get_folder(store, folder_name, flags, ex);
 			if (folder) {
 				CamelVeeFolder *vfolder;
 
 				if ((store->flags & CAMEL_STORE_VTRASH)
 				    && (vfolder = camel_object_bag_get(store->folders, CAMEL_VTRASH_NAME))) {
 					camel_vee_folder_add_folder(vfolder, folder);
-					camel_object_unref(vfolder);
+					g_object_unref (vfolder);
 				}
 
 				if ((store->flags & CAMEL_STORE_VJUNK)
 				    && (vfolder = camel_object_bag_get(store->folders, CAMEL_VJUNK_NAME))) {
 					camel_vee_folder_add_folder(vfolder, folder);
-					camel_object_unref(vfolder);
+					g_object_unref (vfolder);
 				}
 			}
 		}
@@ -384,19 +419,6 @@ camel_store_get_folder (CamelStore *store, const gchar *folder_name, guint32 fla
 	return folder;
 }
 
-static CamelFolderInfo *
-create_folder (CamelStore *store, const gchar *parent_name,
-	       const gchar *folder_name, CamelException *ex)
-{
-	w(g_warning ("CamelStore::create_folder not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
-
-	camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_INVALID,
-			      _("Cannot create folder: Invalid operation on this store"));
-
-	return NULL;
-}
-
 /**
  * camel_store_create_folder:
  * @store: a #CamelStore object
@@ -411,11 +433,17 @@ create_folder (CamelStore *store, const gchar *parent_name,
  * free with #camel_store_free_folder_info, or %NULL.
  **/
 CamelFolderInfo *
-camel_store_create_folder (CamelStore *store, const gchar *parent_name,
-			   const gchar *folder_name, CamelException *ex)
+camel_store_create_folder (CamelStore *store,
+                           const gchar *parent_name,
+                           const gchar *folder_name,
+                           CamelException *ex)
 {
+	CamelStoreClass *class;
 	CamelFolderInfo *fi;
 
+	g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
+	g_return_val_if_fail (folder_name != NULL, NULL);
+
 	if ((parent_name == NULL || parent_name[0] == 0)
 	    && (((store->flags & CAMEL_STORE_VTRASH) && strcmp(folder_name, CAMEL_VTRASH_NAME) == 0)
 		|| ((store->flags & CAMEL_STORE_VJUNK) && strcmp(folder_name, CAMEL_VJUNK_NAME) == 0))) {
@@ -424,8 +452,11 @@ camel_store_create_folder (CamelStore *store, const gchar *parent_name,
 		return NULL;
 	}
 
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_val_if_fail (class->create_folder != NULL, NULL);
+
 	CAMEL_STORE_LOCK(store, folder_lock);
-	fi = CS_CLASS (store)->create_folder (store, parent_name, folder_name, ex);
+	fi = class->create_folder (store, parent_name, folder_name, ex);
 	CAMEL_STORE_UNLOCK(store, folder_lock);
 
 	return fi;
@@ -444,29 +475,22 @@ cs_delete_cached_folder(CamelStore *store, const gchar *folder_name)
 		if ((store->flags & CAMEL_STORE_VTRASH)
 		    && (vfolder = camel_object_bag_get(store->folders, CAMEL_VTRASH_NAME))) {
 			camel_vee_folder_remove_folder(vfolder, folder);
-			camel_object_unref(vfolder);
+			g_object_unref (vfolder);
 		}
 
 		if ((store->flags & CAMEL_STORE_VJUNK)
 		    && (vfolder = camel_object_bag_get(store->folders, CAMEL_VJUNK_NAME))) {
 			camel_vee_folder_remove_folder(vfolder, folder);
-			camel_object_unref(vfolder);
+			g_object_unref (vfolder);
 		}
 
 		camel_folder_delete(folder);
 
 		camel_object_bag_remove(store->folders, folder);
-		camel_object_unref(folder);
+		g_object_unref (folder);
 	}
 }
 
-static void
-delete_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
-{
-	w(g_warning ("CamelStore::delete_folder not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
-}
-
 /**
  * camel_store_delete_folder:
  * @store: a #CamelStore object
@@ -476,10 +500,16 @@ delete_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
  * Deletes the named folder. The folder must be empty.
  **/
 void
-camel_store_delete_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
+camel_store_delete_folder (CamelStore *store,
+                           const gchar *folder_name,
+                           CamelException *ex)
 {
+	CamelStoreClass *class;
 	CamelException local;
 
+	g_return_if_fail (CAMEL_IS_STORE (store));
+	g_return_if_fail (folder_name != NULL);
+
 	/* TODO: should probably be a parameter/bit on the storeinfo */
 	if (((store->flags & CAMEL_STORE_VTRASH) && strcmp(folder_name, CAMEL_VTRASH_NAME) == 0)
 	    || ((store->flags & CAMEL_STORE_VJUNK) && strcmp(folder_name, CAMEL_VJUNK_NAME) == 0)) {
@@ -488,11 +518,14 @@ camel_store_delete_folder (CamelStore *store, const gchar *folder_name, CamelExc
 		return;
 	}
 
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->delete_folder != NULL);
+
 	camel_exception_init(&local);
 
 	CAMEL_STORE_LOCK(store, folder_lock);
 
-	CS_CLASS(store)->delete_folder(store, folder_name, &local);
+	class->delete_folder(store, folder_name, &local);
 
 	/* ignore 'no such table' errors */
 	if (camel_exception_is_set (&local) && camel_exception_get_description (&local) &&
@@ -509,13 +542,6 @@ camel_store_delete_folder (CamelStore *store, const gchar *folder_name, CamelExc
 	CAMEL_STORE_UNLOCK(store, folder_lock);
 }
 
-static void
-rename_folder (CamelStore *store, const gchar *old_name, const gchar *new_name, CamelException *ex)
-{
-	w(g_warning ("CamelStore::rename_folder not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
-}
-
 /**
  * camel_store_rename_folder:
  * @store: a #CamelStore object
@@ -526,8 +552,12 @@ rename_folder (CamelStore *store, const gchar *old_name, const gchar *new_name,
  * Rename a named folder to a new name.
  **/
 void
-camel_store_rename_folder (CamelStore *store, const gchar *old_namein, const gchar *new_name, CamelException *ex)
+camel_store_rename_folder (CamelStore *store,
+                           const gchar *old_namein,
+                           const gchar *new_name,
+                           CamelException *ex)
 {
+	CamelStoreClass *class;
 	CamelFolder *folder;
 	gint i, oldlen, namelen;
 	GPtrArray *folders = NULL;
@@ -545,6 +575,9 @@ camel_store_rename_folder (CamelStore *store, const gchar *old_namein, const gch
 		return;
 	}
 
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->rename_folder != NULL);
+
 	/* need to save this, since old_namein might be folder->full_name, which could go away */
 	old_name = g_strdup(old_namein);
 	oldlen = strlen(old_name);
@@ -568,13 +601,13 @@ camel_store_rename_folder (CamelStore *store, const gchar *old_namein, const gch
 			} else {
 				g_ptr_array_remove_index_fast(folders, i);
 				i--;
-				camel_object_unref(folder);
+				g_object_unref (folder);
 			}
 		}
 	}
 
 	/* Now try the real rename (will emit renamed event) */
-	CS_CLASS (store)->rename_folder (store, old_name, new_name, ex);
+	class->rename_folder (store, old_name, new_name, ex);
 
 	/* If it worked, update all open folders/unlock them */
 	if (folders) {
@@ -593,7 +626,7 @@ camel_store_rename_folder (CamelStore *store, const gchar *old_namein, const gch
 				g_free(new);
 
 				CAMEL_FOLDER_REC_UNLOCK(folder, lock);
-				camel_object_unref(folder);
+				g_object_unref (folder);
 			}
 
 			/* Emit renamed signal */
@@ -601,17 +634,17 @@ camel_store_rename_folder (CamelStore *store, const gchar *old_namein, const gch
 				flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED;
 
 			reninfo.old_base = (gchar *)old_name;
-			reninfo.new = ((CamelStoreClass *)((CamelObject *)store)->klass)->get_folder_info(store, new_name, flags, ex);
+			reninfo.new = class->get_folder_info(store, new_name, flags, ex);
 			if (reninfo.new != NULL) {
 				camel_object_trigger_event (store, "folder_renamed", &reninfo);
-				((CamelStoreClass *)((CamelObject *)store)->klass)->free_folder_info(store, reninfo.new);
+				class->free_folder_info(store, reninfo.new);
 			}
 		} else {
 			/* Failed, just unlock our folders for re-use */
 			for (i=0;i<folders->len;i++) {
 				folder = folders->pdata[i];
 				CAMEL_FOLDER_REC_UNLOCK(folder, lock);
-				camel_object_unref(folder);
+				g_object_unref (folder);
 			}
 		}
 	}
@@ -622,15 +655,6 @@ camel_store_rename_folder (CamelStore *store, const gchar *old_namein, const gch
 	g_free(old_name);
 }
 
-static CamelFolder *
-get_inbox (CamelStore *store, CamelException *ex)
-{
-	/* Default: assume the inbox's name is "inbox"
-	 * and open with default flags.
-	 */
-	return CS_CLASS (store)->get_folder (store, "inbox", 0, ex);
-}
-
 /**
  * camel_store_get_inbox:
  * @store: a #CamelStore object
@@ -640,48 +664,24 @@ get_inbox (CamelStore *store, CamelException *ex)
  * or %NULL if no such folder exists.
  **/
 CamelFolder *
-camel_store_get_inbox (CamelStore *store, CamelException *ex)
+camel_store_get_inbox (CamelStore *store,
+                       CamelException *ex)
 {
+	CamelStoreClass *class;
 	CamelFolder *folder;
 
-	CAMEL_STORE_LOCK(store, folder_lock);
-	folder = CS_CLASS (store)->get_inbox (store, ex);
-	CAMEL_STORE_UNLOCK(store, folder_lock);
-
-	return folder;
-}
+	g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
 
-static CamelFolder *
-get_special(CamelStore *store, camel_vtrash_folder_t type)
-{
-	CamelFolder *folder;
-	GPtrArray *folders;
-	gint i;
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_val_if_fail (class->get_inbox != NULL, NULL);
 
-	folder = camel_vtrash_folder_new(store, type);
-	folders = camel_object_bag_list(store->folders);
-	for (i=0;i<folders->len;i++) {
-		if (!CAMEL_IS_VTRASH_FOLDER(folders->pdata[i]))
-			camel_vee_folder_add_folder((CamelVeeFolder *)folder, (CamelFolder *)folders->pdata[i]);
-		camel_object_unref(folders->pdata[i]);
-	}
-	g_ptr_array_free(folders, TRUE);
+	CAMEL_STORE_LOCK(store, folder_lock);
+	folder = class->get_inbox (store, ex);
+	CAMEL_STORE_UNLOCK(store, folder_lock);
 
 	return folder;
 }
 
-static CamelFolder *
-get_trash(CamelStore *store, CamelException *ex)
-{
-	return get_special(store, CAMEL_VTRASH_FOLDER_TRASH);
-}
-
-static CamelFolder *
-get_junk(CamelStore *store, CamelException *ex)
-{
-	return get_special(store, CAMEL_VTRASH_FOLDER_JUNK);
-}
-
 /**
  * camel_store_get_trash:
  * @store: a #CamelStore object
@@ -691,12 +691,21 @@ get_junk(CamelStore *store, CamelException *ex)
  * %NULL if no such folder exists.
  **/
 CamelFolder *
-camel_store_get_trash (CamelStore *store, CamelException *ex)
+camel_store_get_trash (CamelStore *store,
+                       CamelException *ex)
 {
-	if ((store->flags & CAMEL_STORE_VTRASH) == 0)
-		return CS_CLASS(store)->get_trash(store, ex);
-	else
-		return camel_store_get_folder(store, CAMEL_VTRASH_NAME, 0, ex);
+	g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
+
+	if ((store->flags & CAMEL_STORE_VTRASH) == 0) {
+		CamelStoreClass *class;
+
+		class = CAMEL_STORE_GET_CLASS (store);
+		g_return_val_if_fail (class->get_trash != NULL, NULL);
+
+		return class->get_trash (store, ex);
+	}
+
+	return camel_store_get_folder (store, CAMEL_VTRASH_NAME, 0, ex);
 }
 
 /**
@@ -710,49 +719,18 @@ camel_store_get_trash (CamelStore *store, CamelException *ex)
 CamelFolder *
 camel_store_get_junk (CamelStore *store, CamelException *ex)
 {
-	if ((store->flags & CAMEL_STORE_VJUNK) == 0)
-		return CS_CLASS(store)->get_junk(store, ex);
-	else
-		return camel_store_get_folder(store, CAMEL_VJUNK_NAME, 0, ex);
-}
+	g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
 
-/**
- * ignore_no_such_table_exception:
- * Clears the exception 'ex' when it's the 'no such table' exception.
- **/
-static void
-ignore_no_such_table_exception (CamelException *ex)
-{
-	if (ex && camel_exception_is_set (ex) && g_ascii_strncasecmp (camel_exception_get_description (ex), "no such table", 13) == 0)
-		camel_exception_clear (ex);
-}
+	if ((store->flags & CAMEL_STORE_VJUNK) == 0) {
+		CamelStoreClass *class;
 
-static void
-store_sync (CamelStore *store, gint expunge, CamelException *ex)
-{
-	if (store->folders) {
-		GPtrArray *folders;
-		CamelFolder *folder;
-		CamelException x;
-		gint i;
-
-		/* we don't sync any vFolders, that is used to update certain vfolder queries mainly,
-		   and we're really only interested in storing/expunging the physical mails */
-		camel_exception_init(&x);
-		folders = camel_object_bag_list(store->folders);
-		for (i=0;i<folders->len;i++) {
-			folder = folders->pdata[i];
-			if (!CAMEL_IS_VEE_FOLDER(folder)
-			    && !camel_exception_is_set(&x)) {
-				camel_folder_sync(folder, expunge, &x);
-				ignore_no_such_table_exception (&x);
-			} else if (CAMEL_IS_VEE_FOLDER(folder))
-				camel_vee_folder_sync_headers(folder, NULL); /* Literally don't care of vfolder exceptions */
-			camel_object_unref(folder);
-		}
-		camel_exception_xfer(ex, &x);
-		g_ptr_array_free(folders, TRUE);
+		class = CAMEL_STORE_GET_CLASS (store);
+		g_return_val_if_fail (class->get_junk != NULL, NULL);
+
+		return class->get_junk (store, ex);
 	}
+
+	return camel_store_get_folder (store, CAMEL_VJUNK_NAME, 0, ex);
 }
 
 /**
@@ -765,20 +743,18 @@ store_sync (CamelStore *store, gint expunge, CamelException *ex)
  * folders with the real store.
  **/
 void
-camel_store_sync(CamelStore *store, gint expunge, CamelException *ex)
+camel_store_sync (CamelStore *store,
+                  gint expunge,
+                  CamelException *ex)
 {
-	g_return_if_fail (CAMEL_IS_STORE (store));
+	CamelStoreClass *class;
 
-	CS_CLASS(store)->sync(store, expunge, ex);
-}
+	g_return_if_fail (CAMEL_IS_STORE (store));
 
-static CamelFolderInfo *
-get_folder_info (CamelStore *store, const gchar *top, guint32 flags, CamelException *ex)
-{
-	w(g_warning ("CamelStore::get_folder_info not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->sync != NULL);
 
-	return NULL;
+	class->sync (store, expunge, ex);
 }
 
 static void
@@ -886,13 +862,20 @@ dump_fi(CamelFolderInfo *fi, gint depth)
  * #camel_store_free_folder_info, or %NULL.
  **/
 CamelFolderInfo *
-camel_store_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelException *ex)
+camel_store_get_folder_info (CamelStore *store,
+                             const gchar *top,
+                             guint32 flags,
+                             CamelException *ex)
 {
+	CamelStoreClass *class;
 	CamelFolderInfo *info;
 
 	g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
 
-	info = CS_CLASS (store)->get_folder_info (store, top, flags, ex);
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_val_if_fail (class->get_folder_info != NULL, NULL);
+
+	info = class->get_folder_info (store, top, flags, ex);
 
 	if (info && (top == NULL || *top == '\0') && (flags & CAMEL_STORE_FOLDER_INFO_NO_VIRTUAL) == 0) {
 		if (info->uri && (store->flags & CAMEL_STORE_VTRASH))
@@ -914,13 +897,6 @@ camel_store_get_folder_info(CamelStore *store, const gchar *top, guint32 flags,
 	return info;
 }
 
-static void
-free_folder_info (CamelStore *store, CamelFolderInfo *fi)
-{
-	w(g_warning ("CamelStore::free_folder_info not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
-}
-
 /**
  * camel_store_free_folder_info:
  * @store: a #CamelStore object
@@ -930,14 +906,20 @@ free_folder_info (CamelStore *store, CamelFolderInfo *fi)
  * nothing is done, the routine simply returns.
  **/
 void
-camel_store_free_folder_info (CamelStore *store, CamelFolderInfo *fi)
+camel_store_free_folder_info (CamelStore *store,
+                              CamelFolderInfo *fi)
 {
+	CamelStoreClass *class;
+
 	g_return_if_fail (CAMEL_IS_STORE (store));
 
 	if (!fi)
 		return;
 
-	CS_CLASS (store)->free_folder_info (store, fi);
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->free_folder_info != NULL);
+
+	class->free_folder_info (store, fi);
 }
 
 /**
@@ -1187,15 +1169,6 @@ camel_store_supports_subscriptions (CamelStore *store)
 	return (store->flags & CAMEL_STORE_SUBSCRIPTIONS);
 }
 
-static gboolean
-folder_subscribed(CamelStore *store, const gchar *folder_name)
-{
-	w(g_warning ("CamelStore::folder_subscribed not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
-
-	return FALSE;
-}
-
 /**
  * camel_store_folder_subscribed:
  * @store: a #CamelStore object
@@ -1206,29 +1179,26 @@ folder_subscribed(CamelStore *store, const gchar *folder_name)
  * Returns: %TRUE if the folder has been subscribed to or %FALSE otherwise
  **/
 gboolean
-camel_store_folder_subscribed(CamelStore *store, const gchar *folder_name)
+camel_store_folder_subscribed (CamelStore *store,
+                               const gchar *folder_name)
 {
+	CamelStoreClass *class;
 	gboolean ret;
 
 	g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
+	g_return_val_if_fail (folder_name != NULL, FALSE);
 	g_return_val_if_fail (store->flags & CAMEL_STORE_SUBSCRIPTIONS, FALSE);
 
-	CAMEL_STORE_LOCK(store, folder_lock);
-
-	ret = CS_CLASS (store)->folder_subscribed (store, folder_name);
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_val_if_fail (class->folder_subscribed != NULL, FALSE);
 
-	CAMEL_STORE_UNLOCK(store, folder_lock);
+	CAMEL_STORE_LOCK (store, folder_lock);
+	ret = class->folder_subscribed (store, folder_name);
+	CAMEL_STORE_UNLOCK (store, folder_lock);
 
 	return ret;
 }
 
-static void
-subscribe_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
-{
-	w(g_warning ("CamelStore::subscribe_folder not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
-}
-
 /**
  * camel_store_subscribe_folder:
  * @store: a #CamelStore object
@@ -1238,23 +1208,22 @@ subscribe_folder(CamelStore *store, const gchar *folder_name, CamelException *ex
  * Subscribe to the folder described by @folder_name.
  **/
 void
-camel_store_subscribe_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
+camel_store_subscribe_folder (CamelStore *store,
+                              const gchar *folder_name,
+                              CamelException *ex)
 {
+	CamelStoreClass *class;
+
 	g_return_if_fail (CAMEL_IS_STORE (store));
+	g_return_if_fail (folder_name != NULL);
 	g_return_if_fail (store->flags & CAMEL_STORE_SUBSCRIPTIONS);
 
-	CAMEL_STORE_LOCK(store, folder_lock);
-
-	CS_CLASS (store)->subscribe_folder (store, folder_name, ex);
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->subscribe_folder != NULL);
 
-	CAMEL_STORE_UNLOCK(store, folder_lock);
-}
-
-static void
-unsubscribe_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
-{
-	w(g_warning ("CamelStore::unsubscribe_folder not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store))));
+	CAMEL_STORE_LOCK (store, folder_lock);
+	class->subscribe_folder (store, folder_name, ex);
+	CAMEL_STORE_UNLOCK (store, folder_lock);
 }
 
 /**
@@ -1266,32 +1235,32 @@ unsubscribe_folder(CamelStore *store, const gchar *folder_name, CamelException *
  * Unsubscribe from the folder described by @folder_name.
  **/
 void
-camel_store_unsubscribe_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
+camel_store_unsubscribe_folder (CamelStore *store,
+                                const gchar *folder_name,
+                                CamelException *ex)
 {
+	CamelStoreClass *class;
 	CamelException local;
 
 	g_return_if_fail (CAMEL_IS_STORE (store));
+	g_return_if_fail (folder_name != NULL);
 	g_return_if_fail (store->flags & CAMEL_STORE_SUBSCRIPTIONS);
 
-	camel_exception_init(&local);
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->unsubscribe_folder != NULL);
 
-	CAMEL_STORE_LOCK(store, folder_lock);
+	camel_exception_init (&local);
 
-	CS_CLASS (store)->unsubscribe_folder (store, folder_name, ex);
+	CAMEL_STORE_LOCK (store, folder_lock);
 
-	if (!camel_exception_is_set(&local))
-		cs_delete_cached_folder(store, folder_name);
-	else
-		camel_exception_xfer(ex, &local);
+	class->unsubscribe_folder (store, folder_name, ex);
 
-	CAMEL_STORE_UNLOCK(store, folder_lock);
-}
+	if (!camel_exception_is_set (&local))
+		cs_delete_cached_folder (store, folder_name);
+	else
+		camel_exception_xfer (ex, &local);
 
-static void
-noop (CamelStore *store, CamelException *ex)
-{
-	/* no-op */
-	;
+	CAMEL_STORE_UNLOCK (store, folder_lock);
 }
 
 /**
@@ -1302,9 +1271,17 @@ noop (CamelStore *store, CamelException *ex)
  * Pings @store so that its connection doesn't timeout.
  **/
 void
-camel_store_noop (CamelStore *store, CamelException *ex)
+camel_store_noop (CamelStore *store,
+                  CamelException *ex)
 {
-	CS_CLASS (store)->noop (store, ex);
+	CamelStoreClass *class;
+
+	g_return_if_fail (CAMEL_IS_STORE (store));
+
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_if_fail (class->noop != NULL);
+
+	class->noop (store, ex);
 }
 
 /**
@@ -1318,7 +1295,9 @@ camel_store_noop (CamelStore *store, CamelException *ex)
  * Returns: %TRUE if they are equal or %FALSE otherwise
  **/
 gint
-camel_store_folder_uri_equal (CamelStore *store, const gchar *uri0, const gchar *uri1)
+camel_store_folder_uri_equal (CamelStore *store,
+                              const gchar *uri0,
+                              const gchar *uri1)
 {
 	CamelProvider *provider;
 	CamelURL *url0, *url1;
@@ -1354,7 +1333,7 @@ camel_store_folder_uri_equal (CamelStore *store, const gchar *uri0, const gchar
 		if (name1 == NULL)
 			g_warning("URI is badly formed, missing folder name: %s", uri1);
 
-		equal = name0 && name1 && CS_CLASS (store)->compare_folder_name (name0, name1);
+		equal = name0 && name1 && CAMEL_STORE_GET_CLASS (store)->compare_folder_name (name0, name1);
 	}
 
 	camel_url_free (url0);
@@ -1363,12 +1342,6 @@ camel_store_folder_uri_equal (CamelStore *store, const gchar *uri0, const gchar
 	return equal;
 }
 
-static gboolean
-can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex)
-{
-	return ((info->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX);
-}
-
 /**
  * camel_store_can_refresh_folder
  * @store: a #CamelStore
@@ -1383,68 +1356,17 @@ can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex
  * Returns: whether folder should be checked for new mails
  **/
 gboolean
-camel_store_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex)
-{
-	g_return_val_if_fail (store != NULL, FALSE);
-	g_return_val_if_fail (info != NULL, FALSE);
-
-	return CS_CLASS (store)->can_refresh_folder (store, info, ex);
-}
-
-/* subscriptions interface */
-
-static void
-cis_interface_init (CamelISubscribe *cis)
-{
-	camel_object_class_add_event((CamelType)cis, "subscribed", NULL);
-	camel_object_class_add_event((CamelType)cis, "unsubscribed", NULL);
-}
-
-CamelType camel_isubscribe_get_type (void)
-{
-	static CamelType camel_isubscribe_type = CAMEL_INVALID_TYPE;
-
-	if (camel_isubscribe_type == CAMEL_INVALID_TYPE) {
-		camel_isubscribe_type = camel_interface_register (CAMEL_INTERFACE_TYPE, "CamelISubscribe",
-								  sizeof (CamelISubscribe),
-								  (CamelObjectClassInitFunc) cis_interface_init,
-								  NULL);
-	}
-
-	return camel_isubscribe_type;
-}
-
-gboolean camel_isubscribe_subscribed(CamelStore *store, const gchar *name)
+camel_store_can_refresh_folder (CamelStore *store,
+                                CamelFolderInfo *info,
+                                CamelException *ex)
 {
-	CamelISubscribe *iface = camel_object_get_interface(store, camel_isubscribe_get_type());
-
-	if (iface && iface->subscribed)
-		return iface->subscribed(store, name);
-
-	g_warning("Trying to invoke unimplemented subscribed method on a store");
-	return FALSE;
-}
-
-void camel_isubscribe_subscribe(CamelStore *store, const gchar *folder_name, CamelException *ex)
-{
-	CamelISubscribe *iface = camel_object_get_interface(store, camel_isubscribe_get_type());
-
-	if (iface && iface->subscribe) {
-		iface->subscribe(store, folder_name, ex);
-		return;
-	}
+	CamelStoreClass *class;
 
-	g_warning("Trying to invoke unimplemented subscribe method on a store");
-}
-
-void camel_isubscribe_unsubscribe(CamelStore *store, const gchar *folder_name, CamelException *ex)
-{
-	CamelISubscribe *iface = camel_object_get_interface(store, camel_isubscribe_get_type());
+	g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
+	g_return_val_if_fail (info != NULL, FALSE);
 
-	if (iface && iface->unsubscribe) {
-		iface->unsubscribe(store, folder_name, ex);
-		return;
-	}
+	class = CAMEL_STORE_GET_CLASS (store);
+	g_return_val_if_fail (class->can_refresh_folder != NULL, FALSE);
 
-	g_warning("Trying to invoke unimplemented unsubscribe method on a store");
+	return class->can_refresh_folder (store, info, ex);
 }
diff --git a/camel/camel-store.h b/camel/camel-store.h
index e4a19ee..3f8453f 100644
--- a/camel/camel-store.h
+++ b/camel/camel-store.h
@@ -24,15 +24,39 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_STORE_H
-#define CAMEL_STORE_H 1
+#define CAMEL_STORE_H
 
 /* for mode_t */
 #include <sys/types.h>
 
+#include <camel/camel-folder.h>
 #include <camel/camel-object.h>
 #include <camel/camel-service.h>
 
+/* Standard GObject macros */
+#define CAMEL_TYPE_STORE \
+	(camel_store_get_type ())
+#define CAMEL_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STORE, CamelStore))
+#define CAMEL_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STORE, CamelStoreClass))
+#define CAMEL_IS_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STORE))
+#define CAMEL_IS_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STORE))
+#define CAMEL_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STORE, CamelStoreClass))
+
 G_BEGIN_DECLS
 
 enum {
@@ -104,11 +128,6 @@ typedef struct _CamelRenameInfo {
 	struct _CamelFolderInfo *new;
 } CamelRenameInfo;
 
-#define CAMEL_STORE_TYPE     (camel_store_get_type ())
-#define CAMEL_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_STORE_TYPE, CamelStore))
-#define CAMEL_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_STORE_TYPE, CamelStoreClass))
-#define CAMEL_IS_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_STORE_TYPE))
-
 /* Flags for store flags */
 #define CAMEL_STORE_SUBSCRIPTIONS	(1 << 0)
 #define CAMEL_STORE_VTRASH		(1 << 1)
@@ -119,9 +138,13 @@ typedef struct _CamelRenameInfo {
 
 struct _CamelDB;
 
+typedef struct _CamelStore CamelStore;
+typedef struct _CamelStoreClass CamelStoreClass;
+typedef struct _CamelStorePrivate CamelStorePrivate;
+
 struct _CamelStore {
-	CamelService parent_object;
-	struct _CamelStorePrivate *priv;
+	CamelService parent;
+	CamelStorePrivate *priv;
 
 	CamelObjectBag *folders;
 	struct _CamelDB *cdb_r;
@@ -154,7 +177,7 @@ struct _CamelStore {
 /* folder fetching */
 #define CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST (1 << 4)
 
-typedef struct {
+struct _CamelStoreClass {
 	CamelServiceClass parent_class;
 
 	GHashFunc       hash_folder_name;
@@ -204,11 +227,9 @@ typedef struct {
 	gboolean        (*can_refresh_folder)       (CamelStore *store,
 						     CamelFolderInfo *info,
 						     CamelException *ex);
+};
 
-} CamelStoreClass;
-
-/* Standard Camel function */
-CamelType camel_store_get_type (void);
+GType camel_store_get_type (void);
 
 /* public methods */
 CamelFolder *    camel_store_get_folder         (CamelStore *store,
@@ -280,22 +301,6 @@ gboolean         camel_store_can_refresh_folder       (CamelStore *store,
 						       CamelFolderInfo *info,
 						       CamelException *ex);
 
-#ifndef CAMEL_DISABLE_DEPRECATED
-typedef struct _CamelISubscribe CamelISubscribe;
-struct _CamelISubscribe {
-	CamelInterface iface;
-
-	gboolean (*subscribed)(CamelStore *store, const gchar *folder_name);
-	void (*subscribe)(CamelStore *store, const gchar *folder_name, CamelException *ex);
-	void (*unsubscribe)(CamelStore *store, const gchar *folder_name, CamelException *ex);
-};
-
-CamelType camel_isubscribe_get_type (void);
-gboolean camel_isubscribe_subscribed(CamelStore *store, const gchar *name);
-void camel_isubscribe_subscribe(CamelStore *store, const gchar *folder_name, CamelException *ex);
-void camel_isubscribe_unsubscribe(CamelStore *store, const gchar *folder_name, CamelException *ex);
-#endif /* CAMEL_DISABLE_DEPRECATED */
-
 G_END_DECLS
 
 #endif /* CAMEL_STORE_H */
diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c
index 8175af7..1dca0ee 100644
--- a/camel/camel-stream-buffer.c
+++ b/camel/camel-stream-buffer.c
@@ -33,237 +33,160 @@
 
 #include "camel-stream-buffer.h"
 
-static CamelStreamClass *parent_class = NULL;
+#define CAMEL_STREAM_BUFFER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_STREAM_BUFFER, CamelStreamBufferPrivate))
 
-enum {
-	BUF_USER = 1<<0	/* user-supplied buffer, do not free */
-};
+struct _CamelStreamBufferPrivate {
 
-#define BUF_SIZE 1024
+	CamelStream *stream;
 
-static gssize stream_read (CamelStream *stream, gchar *buffer, gsize n);
-static gssize stream_write (CamelStream *stream, const gchar *buffer, gsize n);
-static gint stream_flush (CamelStream *stream);
-static gint stream_close (CamelStream *stream);
-static gboolean stream_eos (CamelStream *stream);
+	guchar *buf, *ptr, *end;
+	gint size;
 
-static void init_vbuf(CamelStreamBuffer *sbf, CamelStream *s, CamelStreamBufferMode mode, gchar *buf, guint32 size);
-static void init(CamelStreamBuffer *sbuf, CamelStream *s, CamelStreamBufferMode mode);
-
-static void
-camel_stream_buffer_class_init (CamelStreamBufferClass *camel_stream_buffer_class)
-{
-	CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_stream_buffer_class);
+	guchar *linebuf;	/* for reading lines at a time */
+	gint linesize;
 
-	parent_class = CAMEL_STREAM_CLASS (camel_type_get_global_classfuncs (camel_stream_get_type ()));
+	CamelStreamBufferMode mode;
+	guint flags;
+};
 
-	/* virtual method definition */
-	camel_stream_buffer_class->init = init;
-	camel_stream_buffer_class->init_vbuf = init_vbuf;
+static gpointer parent_class;
 
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->eos = stream_eos;
-}
+enum {
+	BUF_USER = 1<<0	/* user-supplied buffer, do not free */
+};
 
-static void
-camel_stream_buffer_init (gpointer object, gpointer klass)
-{
-	CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (object);
-
-	sbf->flags = 0;
-	sbf->size = BUF_SIZE;
-	sbf->buf = g_malloc(BUF_SIZE);
-	sbf->ptr = sbf->buf;
-	sbf->end = sbf->buf;
-	sbf->mode = CAMEL_STREAM_BUFFER_READ | CAMEL_STREAM_BUFFER_BUFFER;
-	sbf->stream = NULL;
-	sbf->linesize = 80;
-	sbf->linebuf = g_malloc(sbf->linesize);
-}
+#define BUF_SIZE 1024
 
-static void
-camel_stream_buffer_finalize (CamelObject *object)
+/* only returns the number passed in, or -1 on an error */
+static gssize
+stream_write_all (CamelStream *stream,
+                  const gchar *buffer,
+                  gsize n)
 {
-	CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (object);
+	gsize left = n, w;
 
-	if (!(sbf->flags & BUF_USER)) {
-		g_free(sbf->buf);
+	while (left > 0) {
+		w = camel_stream_write (stream, buffer, left);
+		if (w == -1)
+			return -1;
+		left -= w;
+		buffer += w;
 	}
-	if (sbf->stream)
-		camel_object_unref (sbf->stream);
 
-	g_free(sbf->linebuf);
+	return n;
 }
 
-CamelType
-camel_stream_buffer_get_type (void)
+static void
+set_vbuf (CamelStreamBuffer *stream,
+          gchar *buf,
+          CamelStreamBufferMode mode,
+          gint size)
 {
-	static CamelType camel_stream_buffer_type = CAMEL_INVALID_TYPE;
-
-	if (camel_stream_buffer_type == CAMEL_INVALID_TYPE)	{
-		camel_stream_buffer_type = camel_type_register (camel_stream_get_type (), "CamelStreamBuffer",
-								sizeof (CamelStreamBuffer),
-								sizeof (CamelStreamBufferClass),
-								(CamelObjectClassInitFunc) camel_stream_buffer_class_init,
-								NULL,
-								(CamelObjectInitFunc) camel_stream_buffer_init,
-								(CamelObjectFinalizeFunc) camel_stream_buffer_finalize);
-	}
+	CamelStreamBufferPrivate *priv;
 
-	return camel_stream_buffer_type;
-}
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
+
+	if (priv->buf && !(priv->flags & BUF_USER))
+		g_free (priv->buf);
 
-static void
-set_vbuf(CamelStreamBuffer *sbf, gchar *buf, CamelStreamBufferMode mode, gint size)
-{
-	if (sbf->buf && !(sbf->flags & BUF_USER)) {
-		g_free(sbf->buf);
-	}
 	if (buf) {
-		sbf->buf = (guchar *) buf;
-		sbf->flags |= BUF_USER;
+		priv->buf = (guchar *) buf;
+		priv->flags |= BUF_USER;
 	} else {
-		sbf->buf = g_malloc(size);
-		sbf->flags &= ~BUF_USER;
+		priv->buf = g_malloc (size);
+		priv->flags &= ~BUF_USER;
 	}
 
-	sbf->ptr = sbf->buf;
-	sbf->end = sbf->buf;
-	sbf->size = size;
-	sbf->mode = mode;
+	priv->ptr = priv->buf;
+	priv->end = priv->buf;
+	priv->size = size;
+	priv->mode = mode;
 }
 
 static void
-init_vbuf(CamelStreamBuffer *sbf, CamelStream *s, CamelStreamBufferMode mode, gchar *buf, guint32 size)
+stream_buffer_dispose (GObject *object)
 {
-	set_vbuf(sbf, buf, mode, size);
-	if (sbf->stream)
-		camel_object_unref (sbf->stream);
-	sbf->stream = s;
-	camel_object_ref (sbf->stream);
-}
+	CamelStreamBufferPrivate *priv;
 
-static void
-init(CamelStreamBuffer *sbuf, CamelStream *s, CamelStreamBufferMode mode)
-{
-	init_vbuf(sbuf, s, mode, NULL, BUF_SIZE);
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (object);
+
+	if (priv->stream != NULL) {
+		g_object_unref (priv->stream);
+		priv->stream = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
-/**
- * camel_stream_buffer_new:
- * @stream: a #CamelStream object to buffer
- * @mode: Operational mode of buffered stream.
- *
- * Create a new buffered stream of another stream.  A default
- * buffer size (1024 bytes), automatically managed will be used
- * for buffering.
- *
- * See #camel_stream_buffer_new_with_vbuf for details on the
- * @mode parameter.
- *
- * Returns: a newly created buffered stream.
- **/
-CamelStream *
-camel_stream_buffer_new (CamelStream *stream, CamelStreamBufferMode mode)
+static void
+stream_buffer_finalize (GObject *object)
 {
-	CamelStreamBuffer *sbf;
+	CamelStreamBufferPrivate *priv;
 
-	sbf = CAMEL_STREAM_BUFFER (camel_object_new (camel_stream_buffer_get_type ()));
-	CAMEL_STREAM_BUFFER_CLASS (CAMEL_OBJECT_GET_CLASS(sbf))->init (sbf, stream, mode);
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (object);
 
-	return CAMEL_STREAM (sbf);
-}
+	if (!(priv->flags & BUF_USER))
+		g_free (priv->buf);
 
-/**
- * camel_stream_buffer_new_with_vbuf:
- * @stream: An existing stream to buffer.
- * @mode: Mode to buffer in.
- * @buf: Memory to use for buffering.
- * @size: Size of buffer to use.
- *
- * Create a new stream which buffers another stream, @stream.
- *
- * The following values are available for @mode:
- *
- * #CAMEL_STREAM_BUFFER_BUFFER, Buffer the input/output in blocks.
- * #CAMEL_STREAM_BUFFER_NEWLINE, Buffer on newlines (for output).
- * #CAMEL_STREAM_BUFFER_NONE, Perform no buffering.
- *
- * Note that currently this is ignored and #CAMEL_STREAM_BUFFER_BUFFER
- * is always used.
- *
- * In addition, one of the following mode options should be or'd
- * together with the buffering mode:
- *
- * #CAMEL_STREAM_BUFFER_WRITE, Buffer in write mode.
- * #CAMEL_STREAM_BUFFER_READ, Buffer in read mode.
- *
- * Buffering can only be done in one direction for any
- * buffer instance.
- *
- * If @buf is non-NULL, then use the memory pointed to
- * (for upto @size bytes) as the buffer for all buffering
- * operations.  It is upto the application to free this buffer.
- * If @buf is NULL, then allocate and manage @size bytes
- * for all buffering.
- *
- * Return value: A new stream with buffering applied.
- **/
-CamelStream *
-camel_stream_buffer_new_with_vbuf (CamelStream *stream, CamelStreamBufferMode mode, gchar *buf, guint32 size)
-{
-	CamelStreamBuffer *sbf;
-	sbf = CAMEL_STREAM_BUFFER (camel_object_new (camel_stream_buffer_get_type ()));
-	CAMEL_STREAM_BUFFER_CLASS (CAMEL_OBJECT_GET_CLASS(sbf))->init_vbuf (sbf, stream, mode, buf, size);
+	g_free (priv->linebuf);
 
-	return CAMEL_STREAM (sbf);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gssize
-stream_read (CamelStream *stream, gchar *buffer, gsize n)
+stream_buffer_read (CamelStream *stream,
+                    gchar *buffer,
+                    gsize n)
 {
-	CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
+	CamelStreamBufferPrivate *priv;
 	gssize bytes_read = 1;
 	gssize bytes_left;
 	gchar *bptr = buffer;
 
-	g_return_val_if_fail( (sbf->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_READ, 0);
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
+
+	g_return_val_if_fail (
+		(priv->mode & CAMEL_STREAM_BUFFER_MODE) ==
+		CAMEL_STREAM_BUFFER_READ, 0);
 
 	while (n && bytes_read > 0) {
-		bytes_left = sbf->end - sbf->ptr;
+		bytes_left = priv->end - priv->ptr;
 		if (bytes_left < n) {
 			if (bytes_left > 0) {
-				memcpy(bptr, sbf->ptr, bytes_left);
+				memcpy(bptr, priv->ptr, bytes_left);
 				n -= bytes_left;
 				bptr += bytes_left;
-				sbf->ptr += bytes_left;
+				priv->ptr += bytes_left;
 			}
 			/* if we are reading a lot, then read directly to the destination buffer */
-			if (n >= sbf->size/3) {
-				bytes_read = camel_stream_read(sbf->stream, bptr, n);
+			if (n >= priv->size/3) {
+				bytes_read = camel_stream_read (
+					priv->stream, bptr, n);
 				if (bytes_read>0) {
 					n -= bytes_read;
 					bptr += bytes_read;
 				}
 			} else {
-				bytes_read = camel_stream_read(sbf->stream, (gchar *) sbf->buf, sbf->size);
+				bytes_read = camel_stream_read (
+					priv->stream, (gchar *)
+					priv->buf, priv->size);
 				if (bytes_read>0) {
 					gsize bytes_used = bytes_read > n ? n : bytes_read;
-					sbf->ptr = sbf->buf;
-					sbf->end = sbf->buf+bytes_read;
-					memcpy(bptr, sbf->ptr, bytes_used);
-					sbf->ptr += bytes_used;
+					priv->ptr = priv->buf;
+					priv->end = priv->buf+bytes_read;
+					memcpy(bptr, priv->ptr, bytes_used);
+					priv->ptr += bytes_used;
 					bptr += bytes_used;
 					n -= bytes_used;
 				}
 			}
 		} else {
-			memcpy(bptr, sbf->ptr, n);
-			sbf->ptr += n;
+			memcpy(bptr, priv->ptr, n);
+			priv->ptr += n;
 			bptr += n;
 			n = 0;
 		}
@@ -272,57 +195,48 @@ stream_read (CamelStream *stream, gchar *buffer, gsize n)
 	return (gssize)(bptr - buffer);
 }
 
-/* only returns the number passed in, or -1 on an error */
-static gssize
-stream_write_all(CamelStream *stream, const gchar *buffer, gsize n)
-{
-	gsize left = n, w;
-
-	while (left > 0) {
-		w = camel_stream_write(stream, buffer, left);
-		if (w == -1)
-			return -1;
-		left -= w;
-		buffer += w;
-	}
-
-	return n;
-}
-
 static gssize
-stream_write (CamelStream *stream, const gchar *buffer, gsize n)
+stream_buffer_write (CamelStream *stream,
+                     const gchar *buffer,
+                     gsize n)
 {
-	CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
+	CamelStreamBufferPrivate *priv;
 	gssize total = n;
 	gssize left, todo;
 
-	g_return_val_if_fail( (sbf->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_WRITE, 0);
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
+
+	g_return_val_if_fail (
+		(priv->mode & CAMEL_STREAM_BUFFER_MODE) ==
+		CAMEL_STREAM_BUFFER_WRITE, 0);
 
 	/* first, copy as much as we can */
-	left = sbf->size - (sbf->ptr-sbf->buf);
+	left = priv->size - (priv->ptr - priv->buf);
 	todo = MIN(left, n);
 
-	memcpy(sbf->ptr, buffer, todo);
+	memcpy(priv->ptr, buffer, todo);
 	n -= todo;
 	buffer += todo;
-	sbf->ptr += todo;
+	priv->ptr += todo;
 
 	/* if we've filled the buffer, write it out, reset buffer */
 	if (left == todo) {
-		if (stream_write_all(sbf->stream, (const gchar *) sbf->buf, sbf->size) == -1)
+		if (stream_write_all (
+			priv->stream, (gchar *)
+			priv->buf, priv->size) == -1)
 			return -1;
 
-		sbf->ptr = sbf->buf;
+		priv->ptr = priv->buf;
 	}
 
 	/* if we still have more, write directly, or copy to buffer */
 	if (n > 0) {
-		if (n >= sbf->size/3) {
-			if (stream_write_all(sbf->stream, buffer, n) == -1)
+		if (n >= priv->size/3) {
+			if (stream_write_all(priv->stream, buffer, n) == -1)
 				return -1;
 		} else {
-			memcpy(sbf->ptr, buffer, n);
-			sbf->ptr += n;
+			memcpy(priv->ptr, buffer, n);
+			priv->ptr += n;
 		}
 	}
 
@@ -330,40 +244,222 @@ stream_write (CamelStream *stream, const gchar *buffer, gsize n)
 }
 
 static gint
-stream_flush (CamelStream *stream)
+stream_buffer_flush (CamelStream *stream)
 {
-	CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
+	CamelStreamBufferPrivate *priv;
+
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
 
-	if ((sbf->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_WRITE) {
-		gsize len = sbf->ptr - sbf->buf;
+	if ((priv->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_WRITE) {
+		gsize len = priv->ptr - priv->buf;
 
-		if (camel_stream_write (sbf->stream, (const gchar *) sbf->buf, len) == -1)
+		if (camel_stream_write (
+			priv->stream, (gchar *) priv->buf, len) == -1)
 			return -1;
 
-		sbf->ptr = sbf->buf;
+		priv->ptr = priv->buf;
 	} else {
 		/* nothing to do for read mode 'flush' */
 	}
 
-	return camel_stream_flush(sbf->stream);
+	return camel_stream_flush (priv->stream);
 }
 
 static gint
-stream_close (CamelStream *stream)
+stream_buffer_close (CamelStream *stream)
 {
-	CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
+	CamelStreamBufferPrivate *priv;
 
-	if (stream_flush(stream) == -1)
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
+
+	if (stream_buffer_flush (stream) == -1)
 		return -1;
-	return camel_stream_close(sbf->stream);
+
+	return camel_stream_close (priv->stream);
 }
 
 static gboolean
-stream_eos (CamelStream *stream)
+stream_buffer_eos (CamelStream *stream)
+{
+	CamelStreamBufferPrivate *priv;
+
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
+
+	return camel_stream_eos(priv->stream) && priv->ptr == priv->end;
+}
+
+static void
+stream_buffer_init_vbuf (CamelStreamBuffer *stream,
+                         CamelStream *other_stream,
+                         CamelStreamBufferMode mode,
+                         gchar *buf,
+                         guint32 size)
+{
+	CamelStreamBufferPrivate *priv;
+
+	priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
+
+	set_vbuf (stream, buf, mode, size);
+
+	if (priv->stream != NULL)
+		g_object_unref (priv->stream);
+
+	priv->stream = g_object_ref (other_stream);
+}
+
+static void
+stream_buffer_init_method (CamelStreamBuffer *stream,
+                           CamelStream *other_stream,
+                           CamelStreamBufferMode mode)
+{
+	stream_buffer_init_vbuf (stream, other_stream, mode, NULL, BUF_SIZE);
+}
+
+static void
+stream_buffer_class_init (CamelStreamBufferClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelStreamBufferPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = stream_buffer_dispose;
+	object_class->finalize = stream_buffer_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_buffer_read;
+	stream_class->write = stream_buffer_write;
+	stream_class->flush = stream_buffer_flush;
+	stream_class->close = stream_buffer_close;
+	stream_class->eos = stream_buffer_eos;
+
+	class->init = stream_buffer_init_method;
+	class->init_vbuf = stream_buffer_init_vbuf;
+}
+
+static void
+stream_buffer_init (CamelStreamBuffer *stream)
+{
+	stream->priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
+
+	stream->priv->flags = 0;
+	stream->priv->size = BUF_SIZE;
+	stream->priv->buf = g_malloc(BUF_SIZE);
+	stream->priv->ptr = stream->priv->buf;
+	stream->priv->end = stream->priv->buf;
+	stream->priv->mode =
+		CAMEL_STREAM_BUFFER_READ |
+		CAMEL_STREAM_BUFFER_BUFFER;
+	stream->priv->stream = NULL;
+	stream->priv->linesize = 80;
+	stream->priv->linebuf = g_malloc (stream->priv->linesize);
+}
+
+GType
+camel_stream_buffer_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelStreamBuffer",
+			sizeof (CamelStreamBufferClass),
+			(GClassInitFunc) stream_buffer_class_init,
+			sizeof (CamelStreamBuffer),
+			(GInstanceInitFunc) stream_buffer_init,
+			0);
+
+	return type;
+}
+
+/**
+ * camel_stream_buffer_new:
+ * @stream: a #CamelStream object to buffer
+ * @mode: Operational mode of buffered stream.
+ *
+ * Create a new buffered stream of another stream.  A default
+ * buffer size (1024 bytes), automatically managed will be used
+ * for buffering.
+ *
+ * See #camel_stream_buffer_new_with_vbuf for details on the
+ * @mode parameter.
+ *
+ * Returns: a newly created buffered stream.
+ **/
+CamelStream *
+camel_stream_buffer_new (CamelStream *stream,
+                         CamelStreamBufferMode mode)
 {
-	CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
+	CamelStreamBuffer *sbf;
+	CamelStreamBufferClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_STREAM (stream), NULL);
+
+	sbf = g_object_new (CAMEL_TYPE_STREAM_BUFFER, NULL);
+
+	class = CAMEL_STREAM_BUFFER_GET_CLASS (sbf);
+	g_return_val_if_fail (class->init != NULL, NULL);
+
+	class->init (sbf, stream, mode);
 
-	return camel_stream_eos(sbf->stream) && sbf->ptr == sbf->end;
+	return CAMEL_STREAM (sbf);
+}
+
+/**
+ * camel_stream_buffer_new_with_vbuf:
+ * @stream: An existing stream to buffer.
+ * @mode: Mode to buffer in.
+ * @buf: Memory to use for buffering.
+ * @size: Size of buffer to use.
+ *
+ * Create a new stream which buffers another stream, @stream.
+ *
+ * The following values are available for @mode:
+ *
+ * #CAMEL_STREAM_BUFFER_BUFFER, Buffer the input/output in blocks.
+ * #CAMEL_STREAM_BUFFER_NEWLINE, Buffer on newlines (for output).
+ * #CAMEL_STREAM_BUFFER_NONE, Perform no buffering.
+ *
+ * Note that currently this is ignored and #CAMEL_STREAM_BUFFER_BUFFER
+ * is always used.
+ *
+ * In addition, one of the following mode options should be or'd
+ * together with the buffering mode:
+ *
+ * #CAMEL_STREAM_BUFFER_WRITE, Buffer in write mode.
+ * #CAMEL_STREAM_BUFFER_READ, Buffer in read mode.
+ *
+ * Buffering can only be done in one direction for any
+ * buffer instance.
+ *
+ * If @buf is non-NULL, then use the memory pointed to
+ * (for upto @size bytes) as the buffer for all buffering
+ * operations.  It is upto the application to free this buffer.
+ * If @buf is NULL, then allocate and manage @size bytes
+ * for all buffering.
+ *
+ * Return value: A new stream with buffering applied.
+ **/
+CamelStream *
+camel_stream_buffer_new_with_vbuf (CamelStream *stream, CamelStreamBufferMode mode, gchar *buf, guint32 size)
+{
+	CamelStreamBuffer *sbf;
+	CamelStreamBufferClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_STREAM (stream), NULL);
+	g_return_val_if_fail (buf != NULL, NULL);
+
+	sbf = g_object_new (CAMEL_TYPE_STREAM_BUFFER, NULL);
+
+	class = CAMEL_STREAM_BUFFER_GET_CLASS (sbf);
+	g_return_val_if_fail (class->init_vbuf != NULL, NULL);
+
+	class->init_vbuf (sbf, stream, mode, buf, size);
+
+	return CAMEL_STREAM (sbf);
 }
 
 /**
@@ -388,8 +484,8 @@ camel_stream_buffer_gets(CamelStreamBuffer *sbf, gchar *buf, guint max)
 	gint bytes_read;
 
 	outptr = buf;
-	inptr = (gchar *) sbf->ptr;
-	inend = (gchar *) sbf->end;
+	inptr = (gchar *) sbf->priv->ptr;
+	inend = (gchar *) sbf->priv->end;
 	outend = buf+max-1;	/* room for NUL */
 
 	do {
@@ -398,27 +494,29 @@ camel_stream_buffer_gets(CamelStreamBuffer *sbf, gchar *buf, guint max)
 			*outptr++ = c;
 			if (c == '\n') {
 				*outptr = 0;
-				sbf->ptr = (guchar *) inptr;
+				sbf->priv->ptr = (guchar *) inptr;
 				return outptr-buf;
 			}
 		}
 		if (outptr == outend)
 			break;
 
-		bytes_read = camel_stream_read (sbf->stream, (gchar *) sbf->buf, sbf->size);
+		bytes_read = camel_stream_read (
+			sbf->priv->stream, (gchar *)
+			sbf->priv->buf, sbf->priv->size);
 		if (bytes_read == -1) {
 			if (buf == outptr)
 				return -1;
 			else
 				bytes_read = 0;
 		}
-		sbf->ptr = sbf->buf;
-		sbf->end = sbf->buf + bytes_read;
-		inptr = (gchar *) sbf->ptr;
-		inend = (gchar *) sbf->end;
+		sbf->priv->ptr = sbf->priv->buf;
+		sbf->priv->end = sbf->priv->buf + bytes_read;
+		inptr = (gchar *) sbf->priv->ptr;
+		inend = (gchar *) sbf->priv->end;
 	} while (bytes_read>0);
 
-	sbf->ptr = (guchar *) inptr;
+	sbf->priv->ptr = (guchar *) inptr;
 	*outptr = 0;
 
 	return (gint)(outptr - buf);
@@ -441,12 +539,14 @@ camel_stream_buffer_read_line (CamelStreamBuffer *sbf)
 	guchar *p;
 	gint nread;
 
-	p = sbf->linebuf;
+	p = sbf->priv->linebuf;
 
 	while (1) {
-		nread = camel_stream_buffer_gets (sbf, (gchar *) p, sbf->linesize - (p - sbf->linebuf));
+		nread = camel_stream_buffer_gets (
+			sbf, (gchar *) p, sbf->priv->linesize -
+			(p - sbf->priv->linebuf));
 		if (nread <=0) {
-			if (p > sbf->linebuf)
+			if (p > sbf->priv->linebuf)
 				break;
 			return NULL;
 		}
@@ -455,16 +555,17 @@ camel_stream_buffer_read_line (CamelStreamBuffer *sbf)
 		if (p[-1] == '\n')
 			break;
 
-		nread = p - sbf->linebuf;
-		sbf->linesize *= 2;
-		sbf->linebuf = g_realloc (sbf->linebuf, sbf->linesize);
-		p = sbf->linebuf + nread;
+		nread = p - sbf->priv->linebuf;
+		sbf->priv->linesize *= 2;
+		sbf->priv->linebuf = g_realloc (
+			sbf->priv->linebuf, sbf->priv->linesize);
+		p = sbf->priv->linebuf + nread;
 	}
 
 	p--;
-	if (p > sbf->linebuf && p[-1] == '\r')
+	if (p > sbf->priv->linebuf && p[-1] == '\r')
 		p--;
 	p[0] = 0;
 
-	return g_strdup((gchar *) sbf->linebuf);
+	return g_strdup ((gchar *) sbf->priv->linebuf);
 }
diff --git a/camel/camel-stream-buffer.h b/camel/camel-stream-buffer.h
index 9f3e48d..2ccbe08 100644
--- a/camel/camel-stream-buffer.h
+++ b/camel/camel-stream-buffer.h
@@ -23,19 +23,41 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_STREAM_BUFFER_H
-#define CAMEL_STREAM_BUFFER_H 1
+#define CAMEL_STREAM_BUFFER_H
 
 #include <stdio.h>
 #include <camel/camel-seekable-stream.h>
 
-#define CAMEL_STREAM_BUFFER_TYPE     (camel_stream_buffer_get_type ())
-#define CAMEL_STREAM_BUFFER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_STREAM_BUFFER_TYPE, CamelStreamBuffer))
-#define CAMEL_STREAM_BUFFER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_STREAM_BUFFER_TYPE, CamelStreamBufferClass))
-#define CAMEL_IS_STREAM_BUFFER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_STREAM_BUFFER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_STREAM_BUFFER \
+	(camel_stream_buffer_get_type ())
+#define CAMEL_STREAM_BUFFER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM_BUFFER, CamelStreamBuffer))
+#define CAMEL_STREAM_BUFFER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM_BUFFER, CamelStreamBufferClass))
+#define CAMEL_IS_STREAM_BUFFER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM_BUFFER))
+#define CAMEL_IS_STREAM_BUFFER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM_BUFFER))
+#define CAMEL_STREAM_BUFFER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM_BUFFER, CamelStreamBufferClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelStreamBuffer CamelStreamBuffer;
+typedef struct _CamelStreamBufferClass CamelStreamBufferClass;
+typedef struct _CamelStreamBufferPrivate CamelStreamBufferPrivate;
+
 typedef enum {
 	CAMEL_STREAM_BUFFER_BUFFER = 0,
 	CAMEL_STREAM_BUFFER_NONE,
@@ -44,52 +66,38 @@ typedef enum {
 	CAMEL_STREAM_BUFFER_MODE = 0x80
 } CamelStreamBufferMode;
 
-struct _CamelStreamBuffer
-{
-	CamelStream parent_object;
-
-	/* these are all of course, private */
-	CamelStream *stream;
-
-	guchar *buf, *ptr, *end;
-	gint size;
-
-	guchar *linebuf;	/* for reading lines at a time */
-	gint linesize;
-
-	CamelStreamBufferMode mode;
-	guint flags;	/* internal flags */
+struct _CamelStreamBuffer {
+	CamelStream parent;
+	CamelStreamBufferPrivate *priv;
 };
 
-typedef struct {
+struct _CamelStreamBufferClass {
 	CamelStreamClass parent_class;
 
-	/* Virtual methods */
-	void (*init) (CamelStreamBuffer *stream_buffer, CamelStream *stream,
-		      CamelStreamBufferMode mode);
-	void (*init_vbuf) (CamelStreamBuffer *stream_buffer,
-			   CamelStream *stream, CamelStreamBufferMode mode,
-			   gchar *buf, guint32 size);
-
-} CamelStreamBufferClass;
-
-/* Standard Camel function */
-CamelType camel_stream_buffer_get_type (void);
-
-/* public methods */
-CamelStream *camel_stream_buffer_new (CamelStream *stream,
-				      CamelStreamBufferMode mode);
-CamelStream *camel_stream_buffer_new_with_vbuf (CamelStream *stream,
-						CamelStreamBufferMode mode,
-						gchar *buf, guint32 size);
+	void		(*init)		(CamelStreamBuffer *stream_buffer,
+					 CamelStream *stream,
+					 CamelStreamBufferMode mode);
+	void		(*init_vbuf)	(CamelStreamBuffer *stream_buffer,
+					 CamelStream *stream,
+					 CamelStreamBufferMode mode,
+					 gchar *buf,
+					 guint32 size);
+};
 
-/* unimplemented
-   CamelStream *camel_stream_buffer_set_vbuf (CamelStreamBuffer *b, CamelStreamBufferMode mode, gchar *buf, guint32 size); */
+GType		camel_stream_buffer_get_type	(void);
+CamelStream *	camel_stream_buffer_new		(CamelStream *stream,
+						 CamelStreamBufferMode mode);
+CamelStream *	camel_stream_buffer_new_with_vbuf
+						(CamelStream *stream,
+						 CamelStreamBufferMode mode,
+						 gchar *buf,
+						 guint32 size);
 
 /* read a line of characters */
-gint camel_stream_buffer_gets (CamelStreamBuffer *sbf, gchar *buf, guint max);
-
-gchar *camel_stream_buffer_read_line (CamelStreamBuffer *sbf);
+gint		camel_stream_buffer_gets	(CamelStreamBuffer *sbf,
+						 gchar *buf,
+						 guint max);
+gchar *		camel_stream_buffer_read_line	(CamelStreamBuffer *sbf);
 
 G_END_DECLS
 
diff --git a/camel/camel-stream-filter.c b/camel/camel-stream-filter.c
index 3879604..81acfb0 100644
--- a/camel/camel-stream-filter.c
+++ b/camel/camel-stream-filter.c
@@ -34,6 +34,10 @@
 /*extern void g_check(gpointer mp);*/
 #define g_check(x)
 
+#define CAMEL_STREAM_FILTER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_STREAM_FILTER, CamelStreamFilterPrivate))
+
 struct _filter {
 	struct _filter *next;
 	gint id;
@@ -41,6 +45,9 @@ struct _filter {
 };
 
 struct _CamelStreamFilterPrivate {
+
+	CamelStream *source;
+
 	struct _filter *filters;
 	gint filterid;		/* next filter id */
 
@@ -57,210 +64,81 @@ struct _CamelStreamFilterPrivate {
 #define READ_PAD (128)		/* bytes padded before buffer */
 #define READ_SIZE (4096)
 
-#define _PRIVATE(o) (((CamelStreamFilter *)(o))->priv)
-
-static void camel_stream_filter_class_init (CamelStreamFilterClass *klass);
-static void camel_stream_filter_init       (CamelStreamFilter *obj);
-
-static	gssize   do_read       (CamelStream *stream, gchar *buffer, gsize n);
-static	gssize   do_write      (CamelStream *stream, const gchar *buffer, gsize n);
-static	gint       do_flush      (CamelStream *stream);
-static	gint       do_close      (CamelStream *stream);
-static	gboolean  do_eos        (CamelStream *stream);
-static	gint       do_reset      (CamelStream *stream);
-
-static CamelStreamClass *camel_stream_filter_parent;
+static gpointer parent_class;
 
 static void
-camel_stream_filter_class_init (CamelStreamFilterClass *klass)
+stream_filter_finalize (GObject *object)
 {
-	CamelStreamClass *camel_stream_class = (CamelStreamClass *) klass;
-
-	camel_stream_filter_parent = CAMEL_STREAM_CLASS (camel_type_get_global_classfuncs (camel_stream_get_type ()));
-
-	camel_stream_class->read = do_read;
-	camel_stream_class->write = do_write;
-	camel_stream_class->flush = do_flush;
-	camel_stream_class->close = do_close;
-	camel_stream_class->eos = do_eos;
-	camel_stream_class->reset = do_reset;
-
-}
-
-static void
-camel_stream_filter_init (CamelStreamFilter *obj)
-{
-	struct _CamelStreamFilterPrivate *p;
-
-	_PRIVATE(obj) = p = g_malloc0(sizeof(*p));
-	p->realbuffer = g_malloc(READ_SIZE + READ_PAD);
-	p->buffer = p->realbuffer + READ_PAD;
-	p->last_was_read = TRUE;
-	p->flushed = FALSE;
-}
-
-static void
-camel_stream_filter_finalize(CamelObject *o)
-{
-	CamelStreamFilter *filter = (CamelStreamFilter *)o;
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+	CamelStreamFilter *stream = CAMEL_STREAM_FILTER (object);
 	struct _filter *fn, *f;
 
-	f = p->filters;
+	f = stream->priv->filters;
 	while (f) {
 		fn = f->next;
-		camel_object_unref((CamelObject *)f->filter);
-		g_free(f);
+		g_object_unref (f->filter);
+		g_free (f);
 		f = fn;
 	}
-	g_free(p->realbuffer);
-	g_free(p);
-	camel_object_unref((CamelObject *)filter->source);
-}
-
-CamelType
-camel_stream_filter_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_STREAM_TYPE, "CamelStreamFilter",
-					    sizeof (CamelStreamFilter),
-					    sizeof (CamelStreamFilterClass),
-					    (CamelObjectClassInitFunc) camel_stream_filter_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_stream_filter_init,
-					    (CamelObjectFinalizeFunc) camel_stream_filter_finalize);
-	}
 
-	return type;
-}
-
-/**
- * camel_stream_filter_new:
- *
- * Create a new #CamelStreamFilter object.
- *
- * Returns: a new #CamelStreamFilter object.
- **/
-CamelStreamFilter *
-camel_stream_filter_new_with_stream(CamelStream *stream)
-{
-	CamelStreamFilter *new = CAMEL_STREAM_FILTER ( camel_object_new (camel_stream_filter_get_type ()));
-
-	new->source = stream;
-	camel_object_ref ((CamelObject *)stream);
+	g_free (stream->priv->realbuffer);
+	g_object_unref (stream->priv->source);
 
-	return new;
-}
-
-/**
- * camel_stream_filter_add:
- * @stream: a #CamelStreamFilter object
- * @filter: a #CamelMimeFilter object
- *
- * Add a new #CamelMimeFilter to execute during the processing of this
- * stream.  Each filter added is processed after the previous one.
- *
- * Note that a filter should only be added to a single stream
- * at a time, otherwise unpredictable results may occur.
- *
- * Returns: a filter id for the added @filter.
- **/
-gint
-camel_stream_filter_add (CamelStreamFilter *stream, CamelMimeFilter *filter)
-{
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(stream);
-	struct _filter *fn, *f;
-
-	fn = g_malloc(sizeof(*fn));
-	fn->id = p->filterid++;
-	fn->filter = filter;
-	camel_object_ref (filter);
-
-	/* sure, we could use a GList, but we wouldn't save much */
-	f = (struct _filter *)&p->filters;
-	while (f->next)
-		f = f->next;
-	f->next = fn;
-	fn->next = NULL;
-	return fn->id;
-}
-
-/**
- * camel_stream_filter_remove:
- * @stream: a #CamelStreamFilter object
- * @id: Filter id, as returned from #camel_stream_filter_add
- *
- * Remove a processing filter from the stream by id.
- **/
-void
-camel_stream_filter_remove(CamelStreamFilter *stream, gint id)
-{
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(stream);
-	struct _filter *fn, *f;
-
-	f = (struct _filter *)&p->filters;
-	while (f && f->next) {
-		fn = f->next;
-		if (fn->id == id) {
-			f->next = fn->next;
-			camel_object_unref(fn->filter);
-			g_free(fn);
-		}
-		f = f->next;
-	}
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gssize
-do_read (CamelStream *stream, gchar *buffer, gsize n)
+stream_filter_read (CamelStream *stream,
+                    gchar *buffer,
+                    gsize n)
 {
-	CamelStreamFilter *filter = (CamelStreamFilter *)stream;
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+	CamelStreamFilterPrivate *priv;
 	gssize size;
 	struct _filter *f;
 
-	p->last_was_read = TRUE;
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	priv->last_was_read = TRUE;
 
-	g_check(p->realbuffer);
+	g_check(priv->realbuffer);
 
-	if (p->filteredlen<=0) {
+	if (priv->filteredlen<=0) {
 		gsize presize = READ_PAD;
 
-		size = camel_stream_read(filter->source, p->buffer, READ_SIZE);
+		size = camel_stream_read(priv->source, priv->buffer, READ_SIZE);
 		if (size <= 0) {
 			/* this is somewhat untested */
-			if (camel_stream_eos(filter->source)) {
-				f = p->filters;
-				p->filtered = p->buffer;
-				p->filteredlen = 0;
+			if (camel_stream_eos(priv->source)) {
+				f = priv->filters;
+				priv->filtered = priv->buffer;
+				priv->filteredlen = 0;
 				while (f) {
-					camel_mime_filter_complete(f->filter, p->filtered, p->filteredlen,
-								   presize, &p->filtered, &p->filteredlen, &presize);
-					g_check(p->realbuffer);
+					camel_mime_filter_complete(f->filter, priv->filtered, priv->filteredlen,
+								   presize, &priv->filtered, &priv->filteredlen, &presize);
+					g_check(priv->realbuffer);
 					f = f->next;
 				}
-				size = p->filteredlen;
-				p->flushed = TRUE;
+				size = priv->filteredlen;
+				priv->flushed = TRUE;
 			}
 			if (size <= 0)
 				return size;
 		} else {
-			f = p->filters;
-			p->filtered = p->buffer;
-			p->filteredlen = size;
+			f = priv->filters;
+			priv->filtered = priv->buffer;
+			priv->filteredlen = size;
 
-			d(printf ("\n\nOriginal content (%s): '", ((CamelObject *)filter->source)->klass->name));
-			d(fwrite(p->filtered, sizeof(gchar), p->filteredlen, stdout));
+			d(printf ("\n\nOriginal content (%s): '", ((CamelObject *)priv->source)->class->name));
+			d(fwrite(priv->filtered, sizeof(gchar), priv->filteredlen, stdout));
 			d(printf("'\n"));
 
 			while (f) {
-				camel_mime_filter_filter(f->filter, p->filtered, p->filteredlen, presize,
-							 &p->filtered, &p->filteredlen, &presize);
-				g_check(p->realbuffer);
+				camel_mime_filter_filter(f->filter, priv->filtered, priv->filteredlen, presize,
+							 &priv->filtered, &priv->filteredlen, &presize);
+				g_check(priv->realbuffer);
 
-				d(printf ("Filtered content (%s): '", ((CamelObject *)f->filter)->klass->name));
-				d(fwrite(p->filtered, sizeof(gchar), p->filteredlen, stdout));
+				d(printf ("Filtered content (%s): '", ((CamelObject *)f->filter)->class->name));
+				d(fwrite(priv->filtered, sizeof(gchar), priv->filteredlen, stdout));
 				d(printf("'\n"));
 
 				f = f->next;
@@ -268,12 +146,12 @@ do_read (CamelStream *stream, gchar *buffer, gsize n)
 		}
 	}
 
-	size = MIN(n, p->filteredlen);
-	memcpy(buffer, p->filtered, size);
-	p->filteredlen -= size;
-	p->filtered += size;
+	size = MIN(n, priv->filteredlen);
+	memcpy(buffer, priv->filtered, size);
+	priv->filteredlen -= size;
+	priv->filtered += size;
 
-	g_check(p->realbuffer);
+	g_check(priv->realbuffer);
 
 	return size;
 }
@@ -282,21 +160,24 @@ do_read (CamelStream *stream, gchar *buffer, gsize n)
    write (for 'success'), we return what they asked us to write (for 'success')
    rather than the true number of written bytes */
 static gssize
-do_write (CamelStream *stream, const gchar *buf, gsize n)
+stream_filter_write (CamelStream *stream,
+                     const gchar *buf,
+                     gsize n)
 {
-	CamelStreamFilter *filter = (CamelStreamFilter *)stream;
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+	CamelStreamFilterPrivate *priv;
 	struct _filter *f;
 	gsize presize, len, left = n;
 	gchar *buffer, realbuffer[READ_SIZE+READ_PAD];
 
-	p->last_was_read = FALSE;
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	priv->last_was_read = FALSE;
 
-	d(printf ("\n\nWriting: Original content (%s): '", ((CamelObject *)filter->source)->klass->name));
+	d(printf ("\n\nWriting: Original content (%s): '", ((CamelObject *)priv->source)->class->name));
 	d(fwrite(buf, sizeof(gchar), n, stdout));
 	d(printf("'\n"));
 
-	g_check(p->realbuffer);
+	g_check(priv->realbuffer);
 
 	while (left) {
 		/* Sigh, since filters expect non const args, copy the input first, we do this in handy sized chunks */
@@ -306,109 +187,262 @@ do_write (CamelStream *stream, const gchar *buf, gsize n)
 		buf += len;
 		left -= len;
 
-		f = p->filters;
+		f = priv->filters;
 		presize = READ_PAD;
 		while (f) {
 			camel_mime_filter_filter(f->filter, buffer, len, presize, &buffer, &len, &presize);
 
-			g_check(p->realbuffer);
+			g_check(priv->realbuffer);
 
-			d(printf ("Filtered content (%s): '", ((CamelObject *)f->filter)->klass->name));
+			d(printf ("Filtered content (%s): '", ((CamelObject *)f->filter)->class->name));
 			d(fwrite(buffer, sizeof(gchar), len, stdout));
 			d(printf("'\n"));
 
 			f = f->next;
 		}
 
-		if (camel_stream_write(filter->source, buffer, len) != len)
+		if (camel_stream_write(priv->source, buffer, len) != len)
 			return -1;
 	}
 
-	g_check(p->realbuffer);
+	g_check(priv->realbuffer);
 
 	return n;
 }
 
 static gint
-do_flush (CamelStream *stream)
+stream_filter_flush (CamelStream *stream)
 {
-	CamelStreamFilter *filter = (CamelStreamFilter *)stream;
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+	CamelStreamFilterPrivate *priv;
 	struct _filter *f;
 	gchar *buffer;
 	gsize presize;
 	gsize len;
 
-	if (p->last_was_read)
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	if (priv->last_was_read)
 		return 0;
 
 	buffer = (gchar *) "";
 	len = 0;
 	presize = 0;
-	f = p->filters;
+	f = priv->filters;
 
-	d(printf ("\n\nFlushing: Original content (%s): '", ((CamelObject *)filter->source)->klass->name));
+	d(printf ("\n\nFlushing: Original content (%s): '", ((CamelObject *)priv->source)->class->name));
 	d(fwrite(buffer, sizeof(gchar), len, stdout));
 	d(printf("'\n"));
 
 	while (f) {
 		camel_mime_filter_complete(f->filter, buffer, len, presize, &buffer, &len, &presize);
 
-		d(printf ("Filtered content (%s): '", ((CamelObject *)f->filter)->klass->name));
+		d(printf ("Filtered content (%s): '", ((CamelObject *)f->filter)->class->name));
 		d(fwrite(buffer, sizeof(gchar), len, stdout));
 		d(printf("'\n"));
 
 		f = f->next;
 	}
-	if (len > 0 && camel_stream_write(filter->source, buffer, len) == -1)
+	if (len > 0 && camel_stream_write(priv->source, buffer, len) == -1)
 		return -1;
-	return camel_stream_flush(filter->source);
+	return camel_stream_flush(priv->source);
 }
 
 static gint
-do_close (CamelStream *stream)
+stream_filter_close (CamelStream *stream)
 {
-	CamelStreamFilter *filter = (CamelStreamFilter *)stream;
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+	CamelStreamFilterPrivate *priv;
 
-	if (!p->last_was_read) {
-		do_flush(stream);
-	}
-	return camel_stream_close(filter->source);
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	if (!priv->last_was_read)
+		stream_filter_flush(stream);
+
+	return camel_stream_close(priv->source);
 }
 
 static gboolean
-do_eos (CamelStream *stream)
+stream_filter_eos (CamelStream *stream)
 {
-	CamelStreamFilter *filter = (CamelStreamFilter *)stream;
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+	CamelStreamFilterPrivate *priv;
+
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
 
-	if (p->filteredlen > 0)
+	if (priv->filteredlen > 0)
 		return FALSE;
 
-	if (!p->flushed)
+	if (!priv->flushed)
 		return FALSE;
 
-	return camel_stream_eos(filter->source);
+	return camel_stream_eos(priv->source);
 }
 
 static gint
-do_reset (CamelStream *stream)
+stream_filter_reset (CamelStream *stream)
 {
-	CamelStreamFilter *filter = (CamelStreamFilter *)stream;
-	struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+	CamelStreamFilterPrivate *priv;
 	struct _filter *f;
 
-	p->filteredlen = 0;
-	p->flushed = FALSE;
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	priv->filteredlen = 0;
+	priv->flushed = FALSE;
 
 	/* and reset filters */
-	f = p->filters;
+	f = priv->filters;
 	while (f) {
 		camel_mime_filter_reset(f->filter);
 		f = f->next;
 	}
 
-	return camel_stream_reset(filter->source);
+	return camel_stream_reset(priv->source);
+}
+
+static void
+stream_filter_class_init (CamelStreamFilterClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelStreamFilterPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = stream_filter_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_filter_read;
+	stream_class->write = stream_filter_write;
+	stream_class->flush = stream_filter_flush;
+	stream_class->close = stream_filter_close;
+	stream_class->eos = stream_filter_eos;
+	stream_class->reset = stream_filter_reset;
+
+}
+
+static void
+stream_filter_init (CamelStreamFilter *stream)
+{
+	stream->priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	stream->priv->realbuffer = g_malloc(READ_SIZE + READ_PAD);
+	stream->priv->buffer = stream->priv->realbuffer + READ_PAD;
+	stream->priv->last_was_read = TRUE;
+	stream->priv->flushed = FALSE;
+}
+
+GType
+camel_stream_filter_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelStreamFilter",
+			sizeof (CamelStreamFilterClass),
+			(GClassInitFunc) stream_filter_class_init,
+			sizeof (CamelStreamFilter),
+			(GInstanceInitFunc) stream_filter_init,
+			0);
+
+	return type;
+}
+
+/**
+ * camel_stream_filter_new:
+ *
+ * Create a new #CamelStreamFilter object.
+ *
+ * Returns: a new #CamelStreamFilter object.
+ **/
+CamelStream *
+camel_stream_filter_new (CamelStream *source)
+{
+	CamelStream *stream;
+	CamelStreamFilterPrivate *priv;
+
+	g_return_val_if_fail (CAMEL_IS_STREAM (source), NULL);
+
+	stream = g_object_new (CAMEL_TYPE_STREAM_FILTER, NULL);
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	priv->source = g_object_ref (source);
+
+	return source;
+}
+
+CamelStream *
+camel_stream_filter_get_source (CamelStreamFilter *stream)
+{
+	g_return_val_if_fail (CAMEL_IS_STREAM_FILTER (stream), NULL);
+
+	return stream->priv->source;
+}
+
+/**
+ * camel_stream_filter_add:
+ * @stream: a #CamelStreamFilter object
+ * @filter: a #CamelMimeFilter object
+ *
+ * Add a new #CamelMimeFilter to execute during the processing of this
+ * stream.  Each filter added is processed after the previous one.
+ *
+ * Note that a filter should only be added to a single stream
+ * at a time, otherwise unpredictable results may occur.
+ *
+ * Returns: a filter id for the added @filter.
+ **/
+gint
+camel_stream_filter_add (CamelStreamFilter *stream,
+                         CamelMimeFilter *filter)
+{
+	CamelStreamFilterPrivate *priv;
+	struct _filter *fn, *f;
+
+	g_return_val_if_fail (CAMEL_IS_STREAM_FILTER (stream), -1);
+	g_return_val_if_fail (CAMEL_IS_MIME_FILTER (filter), -1);
+
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	fn = g_malloc(sizeof(*fn));
+	fn->id = priv->filterid++;
+	fn->filter = filter;
+	g_object_ref (filter);
+
+	/* sure, we could use a GList, but we wouldn't save much */
+	f = (struct _filter *)&priv->filters;
+	while (f->next)
+		f = f->next;
+	f->next = fn;
+	fn->next = NULL;
+	return fn->id;
 }
 
+/**
+ * camel_stream_filter_remove:
+ * @stream: a #CamelStreamFilter object
+ * @id: Filter id, as returned from #camel_stream_filter_add
+ *
+ * Remove a processing filter from the stream by id.
+ **/
+void
+camel_stream_filter_remove (CamelStreamFilter *stream, gint id)
+{
+	CamelStreamFilterPrivate *priv;
+	struct _filter *fn, *f;
+
+	g_return_if_fail (CAMEL_IS_STREAM_FILTER (stream));
+
+	priv = CAMEL_STREAM_FILTER_GET_PRIVATE (stream);
+
+	f = (struct _filter *)&priv->filters;
+	while (f && f->next) {
+		fn = f->next;
+		if (fn->id == id) {
+			f->next = fn->next;
+			g_object_unref (fn->filter);
+			g_free(fn);
+		}
+		f = f->next;
+	}
+}
diff --git a/camel/camel-stream-filter.h b/camel/camel-stream-filter.h
index e8b1701..76ce880 100644
--- a/camel/camel-stream-filter.h
+++ b/camel/camel-stream-filter.h
@@ -19,39 +19,58 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_STREAM_FILTER_H
-#define _CAMEL_STREAM_FILTER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_STREAM_FILTER_H
+#define CAMEL_STREAM_FILTER_H
 
 #include <camel/camel-stream.h>
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_STREAM_FILTER(obj)         CAMEL_CHECK_CAST (obj, camel_stream_filter_get_type (), CamelStreamFilter)
-#define CAMEL_STREAM_FILTER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_stream_filter_get_type (), CamelStreamFilterClass)
-#define CAMEL_IS_STREAM_FILTER(obj)      CAMEL_CHECK_TYPE (obj, camel_stream_filter_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_STREAM_FILTER \
+	(camel_stream_filter_get_type ())
+#define CAMEL_STREAM_FILTER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM_FILTER, CamelStreamFilter))
+#define CAMEL_STREAM_FILTER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM_FILTER, CamelStreamFilterClass))
+#define CAMEL_IS_STREAM_FILTER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM_FILTER))
+#define CAMEL_IS_STREAM_FILTER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM_FILTER))
+#define CAMEL_STREAM_FILTER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM_FILTER, CamelStreamFilterClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelStreamFilter CamelStreamFilter;
 typedef struct _CamelStreamFilterClass CamelStreamFilterClass;
+typedef struct _CamelStreamFilterPrivate CamelStreamFilterPrivate;
 
 struct _CamelStreamFilter {
 	CamelStream parent;
-
-	CamelStream *source;
-
-	struct _CamelStreamFilterPrivate *priv;
+	CamelStreamFilterPrivate *priv;
 };
 
 struct _CamelStreamFilterClass {
 	CamelStreamClass parent_class;
 };
 
-CamelType			camel_stream_filter_get_type	(void);
-
-CamelStreamFilter      *camel_stream_filter_new_with_stream	(CamelStream *stream);
-
-gint camel_stream_filter_add	(CamelStreamFilter *stream, CamelMimeFilter *filter);
-void camel_stream_filter_remove	(CamelStreamFilter *stream, gint id);
+GType		camel_stream_filter_get_type	(void);
+CamelStream *	camel_stream_filter_new		(CamelStream *source);
+CamelStream *	camel_stream_filter_get_source	(CamelStreamFilter *stream);
+gint		camel_stream_filter_add		(CamelStreamFilter *stream,
+						 CamelMimeFilter *filter);
+void		camel_stream_filter_remove	(CamelStreamFilter *stream,
+						 gint id);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_STREAM_FILTER_H */
+#endif /* CAMEL_STREAM_FILTER_H */
diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c
index 87f1820..ebc3bfc 100644
--- a/camel/camel-stream-fs.c
+++ b/camel/camel-stream-fs.c
@@ -32,7 +32,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
 #include "camel-file-utils.h"
@@ -40,71 +39,194 @@
 #include "camel-private.h"
 #include "camel-stream-fs.h"
 
-static CamelSeekableStreamClass *parent_class = NULL;
+#define CAMEL_STREAM_FS_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_STREAM_FS, CamelStreamFsPrivate))
 
-/* Returns the class for a CamelStreamFS */
-#define CSFS_CLASS(so) CAMEL_STREAM_FS_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+struct _CamelStreamFsPrivate {
+	gint fd;	/* file descriptor on the underlying file */
+};
 
-static gssize stream_read   (CamelStream *stream, gchar *buffer, gsize n);
-static gssize stream_write  (CamelStream *stream, const gchar *buffer, gsize n);
-static gint stream_flush  (CamelStream *stream);
-static gint stream_close  (CamelStream *stream);
-static off_t stream_seek (CamelSeekableStream *stream, off_t offset,
-			  CamelStreamSeekPolicy policy);
+static gpointer parent_class;
 
 static void
-camel_stream_fs_class_init (CamelStreamFsClass *camel_stream_fs_class)
+stream_fs_finalize (GObject *object)
 {
-	CamelSeekableStreamClass *camel_seekable_stream_class =
-		CAMEL_SEEKABLE_STREAM_CLASS (camel_stream_fs_class);
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_stream_fs_class);
+	CamelStreamFsPrivate *priv;
 
-	parent_class = CAMEL_SEEKABLE_STREAM_CLASS (camel_type_get_global_classfuncs (camel_seekable_stream_get_type ()));
+	priv = CAMEL_STREAM_FS_GET_PRIVATE (object);
 
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->close = stream_close;
+	if (priv->fd != -1)
+		close (priv->fd);
 
-	camel_seekable_stream_class->seek = stream_seek;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static gssize
+stream_fs_read (CamelStream *stream,
+                gchar *buffer,
+                gsize n)
+{
+	CamelStreamFsPrivate *priv;
+	CamelSeekableStream *seekable;
+	gssize nread;
+
+	priv = CAMEL_STREAM_FS_GET_PRIVATE (stream);
+	seekable = CAMEL_SEEKABLE_STREAM (stream);
+
+	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
+		n = MIN (seekable->bound_end - seekable->position, n);
+
+	if ((nread = camel_read (priv->fd, buffer, n)) > 0)
+		seekable->position += nread;
+	else if (nread == 0)
+		stream->eos = TRUE;
+
+	return nread;
+}
+
+static gssize
+stream_fs_write (CamelStream *stream,
+                 const gchar *buffer,
+                 gsize n)
+{
+	CamelStreamFsPrivate *priv;
+	CamelSeekableStream *seekable;
+	gssize nwritten;
+
+	priv = CAMEL_STREAM_FS_GET_PRIVATE (stream);
+	seekable = CAMEL_SEEKABLE_STREAM (stream);
+
+	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
+		n = MIN (seekable->bound_end - seekable->position, n);
+
+	if ((nwritten = camel_write (priv->fd, buffer, n)) > 0)
+		seekable->position += nwritten;
+
+	return nwritten;
+}
+
+static gint
+stream_fs_flush (CamelStream *stream)
+{
+	CamelStreamFsPrivate *priv;
+
+	priv = CAMEL_STREAM_FS_GET_PRIVATE (stream);
+
+	return fsync (priv->fd);
+}
+
+static gint
+stream_fs_close (CamelStream *stream)
+{
+	CamelStreamFsPrivate *priv;
+
+	priv = CAMEL_STREAM_FS_GET_PRIVATE (stream);
+
+	if (close (priv->fd) == -1)
+		return -1;
+
+	priv->fd = -1;
+
+	return 0;
+}
+
+static off_t
+stream_fs_seek (CamelSeekableStream *stream,
+                off_t offset,
+                CamelStreamSeekPolicy policy)
+{
+	CamelStreamFsPrivate *priv;
+	off_t real = 0;
+
+	priv = CAMEL_STREAM_FS_GET_PRIVATE (stream);
+
+	switch (policy) {
+	case CAMEL_STREAM_SET:
+		real = offset;
+		break;
+	case CAMEL_STREAM_CUR:
+		real = stream->position + offset;
+		break;
+	case CAMEL_STREAM_END:
+		if (stream->bound_end == CAMEL_STREAM_UNBOUND) {
+			real = lseek(priv->fd, offset, SEEK_END);
+			if (real != -1) {
+				if (real<stream->bound_start)
+					real = stream->bound_start;
+				stream->position = real;
+			}
+			return real;
+		}
+		real = stream->bound_end + offset;
+		break;
+	}
+
+	if (stream->bound_end != CAMEL_STREAM_UNBOUND)
+		real = MIN (real, stream->bound_end);
+	real = MAX (real, stream->bound_start);
+
+	real = lseek(priv->fd, real, SEEK_SET);
+	if (real == -1)
+		return -1;
+
+	if (real != stream->position && ((CamelStream *)stream)->eos)
+		((CamelStream *)stream)->eos = FALSE;
+
+	stream->position = real;
+
+	return real;
 }
 
 static void
-camel_stream_fs_init (gpointer object, gpointer klass)
+stream_fs_class_init (CamelStreamFsClass *class)
 {
-	CamelStreamFs *stream = CAMEL_STREAM_FS (object);
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+	CamelSeekableStreamClass *seekable_stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelStreamFsPrivate));
 
-	stream->fd = -1;
-	((CamelSeekableStream *)stream)->bound_end = CAMEL_STREAM_UNBOUND;
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = stream_fs_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_fs_read;
+	stream_class->write = stream_fs_write;
+	stream_class->flush = stream_fs_flush;
+	stream_class->close = stream_fs_close;
+
+	seekable_stream_class = CAMEL_SEEKABLE_STREAM_CLASS (class);
+	seekable_stream_class->seek = stream_fs_seek;
 }
 
 static void
-camel_stream_fs_finalize (CamelObject *object)
+stream_fs_init (CamelStreamFs *stream)
 {
-	CamelStreamFs *stream_fs = CAMEL_STREAM_FS (object);
+	stream->priv = CAMEL_STREAM_FS_GET_PRIVATE (stream);
+	stream->priv->fd = -1;
 
-	if (stream_fs->fd != -1)
-		close (stream_fs->fd);
+	CAMEL_SEEKABLE_STREAM (stream)->bound_end = CAMEL_STREAM_UNBOUND;
 }
 
-CamelType
+GType
 camel_stream_fs_get_type (void)
 {
-	static CamelType camel_stream_fs_type = CAMEL_INVALID_TYPE;
-
-	if (camel_stream_fs_type == CAMEL_INVALID_TYPE) {
-		camel_stream_fs_type = camel_type_register (camel_seekable_stream_get_type (), "CamelStreamFs",
-							    sizeof (CamelStreamFs),
-							    sizeof (CamelStreamFsClass),
-							    (CamelObjectClassInitFunc) camel_stream_fs_class_init,
-							    NULL,
-							    (CamelObjectInitFunc) camel_stream_fs_init,
-							    (CamelObjectFinalizeFunc) camel_stream_fs_finalize);
-	}
-
-	return camel_stream_fs_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SEEKABLE_STREAM,
+			"CamelStreamFs",
+			sizeof (CamelStreamFsClass),
+			(GClassInitFunc) stream_fs_class_init,
+			sizeof (CamelStreamFs),
+			(GInstanceInitFunc) stream_fs_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -120,20 +242,23 @@ camel_stream_fs_get_type (void)
 CamelStream *
 camel_stream_fs_new_with_fd (gint fd)
 {
-	CamelStreamFs *stream_fs;
+	CamelStreamFsPrivate *priv;
+	CamelStream *stream;
 	off_t offset;
 
 	if (fd == -1)
 		return NULL;
 
-	stream_fs = CAMEL_STREAM_FS (camel_object_new (camel_stream_fs_get_type ()));
-	stream_fs->fd = fd;
+	stream = g_object_new (CAMEL_TYPE_STREAM_FS, NULL);
+	priv = CAMEL_STREAM_FS_GET_PRIVATE (stream);
+
+	priv->fd = fd;
 	offset = lseek (fd, 0, SEEK_CUR);
 	if (offset == -1)
 		offset = 0;
-	CAMEL_SEEKABLE_STREAM (stream_fs)->position = offset;
+	CAMEL_SEEKABLE_STREAM (stream)->position = offset;
 
-	return CAMEL_STREAM (stream_fs);
+	return stream;
 }
 
 /**
@@ -153,7 +278,8 @@ camel_stream_fs_new_with_fd_and_bounds (gint fd, off_t start, off_t end)
 	CamelStream *stream;
 
 	stream = camel_stream_fs_new_with_fd (fd);
-	camel_seekable_stream_set_bounds (CAMEL_SEEKABLE_STREAM (stream), start, end);
+	camel_seekable_stream_set_bounds (
+		CAMEL_SEEKABLE_STREAM (stream), start, end);
 
 	return stream;
 }
@@ -210,95 +336,10 @@ camel_stream_fs_new_with_name_and_bounds (const gchar *name, gint flags,
 	return stream;
 }
 
-static gssize
-stream_read (CamelStream *stream, gchar *buffer, gsize n)
-{
-	CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
-	CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
-	gssize nread;
-
-	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
-		n = MIN (seekable->bound_end - seekable->position, n);
-
-	if ((nread = camel_read (stream_fs->fd, buffer, n)) > 0)
-		seekable->position += nread;
-	else if (nread == 0)
-		stream->eos = TRUE;
-
-	return nread;
-}
-
-static gssize
-stream_write (CamelStream *stream, const gchar *buffer, gsize n)
-{
-	CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
-	CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
-	gssize nwritten;
-
-	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
-		n = MIN (seekable->bound_end - seekable->position, n);
-
-	if ((nwritten = camel_write (stream_fs->fd, buffer, n)) > 0)
-		seekable->position += nwritten;
-
-	return nwritten;
-}
-
-static gint
-stream_flush (CamelStream *stream)
-{
-	return fsync(((CamelStreamFs *)stream)->fd);
-}
-
-static gint
-stream_close (CamelStream *stream)
-{
-	if (close (((CamelStreamFs *)stream)->fd) == -1)
-		return -1;
-
-	((CamelStreamFs *)stream)->fd = -1;
-	return 0;
-}
-
-static off_t
-stream_seek (CamelSeekableStream *stream, off_t offset, CamelStreamSeekPolicy policy)
+gint
+camel_stream_fs_get_fd (CamelStreamFs *stream)
 {
-	CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
-	off_t real = 0;
+	g_return_val_if_fail (CAMEL_IS_STREAM_FS (stream), -1);
 
-	switch (policy) {
-	case CAMEL_STREAM_SET:
-		real = offset;
-		break;
-	case CAMEL_STREAM_CUR:
-		real = stream->position + offset;
-		break;
-	case CAMEL_STREAM_END:
-		if (stream->bound_end == CAMEL_STREAM_UNBOUND) {
-			real = lseek(stream_fs->fd, offset, SEEK_END);
-			if (real != -1) {
-				if (real<stream->bound_start)
-					real = stream->bound_start;
-				stream->position = real;
-			}
-			return real;
-		}
-		real = stream->bound_end + offset;
-		break;
-	}
-
-	if (stream->bound_end != CAMEL_STREAM_UNBOUND)
-		real = MIN (real, stream->bound_end);
-	real = MAX (real, stream->bound_start);
-
-	real = lseek(stream_fs->fd, real, SEEK_SET);
-	if (real == -1)
-		return -1;
-
-	if (real != stream->position && ((CamelStream *)stream)->eos)
-		((CamelStream *)stream)->eos = FALSE;
-
-	stream->position = real;
-
-	return real;
+	return stream->priv->fd;
 }
diff --git a/camel/camel-stream-fs.h b/camel/camel-stream-fs.h
index 6811936..4223318 100644
--- a/camel/camel-stream-fs.h
+++ b/camel/camel-stream-fs.h
@@ -22,8 +22,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_STREAM_FS_H
-#define CAMEL_STREAM_FS_H 1
+#define CAMEL_STREAM_FS_H
 
 /* for open flags */
 #include <sys/types.h>
@@ -32,34 +36,55 @@
 
 #include <camel/camel-seekable-stream.h>
 
-#define CAMEL_STREAM_FS_TYPE     (camel_stream_fs_get_type ())
-#define CAMEL_STREAM_FS(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_STREAM_FS_TYPE, CamelStreamFs))
-#define CAMEL_STREAM_FS_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_STREAM_FS_TYPE, CamelStreamFsClass))
-#define CAMEL_IS_STREAM_FS(o)    (CAMEL_CHECK_TYPE((o), CAMEL_STREAM_FS_TYPE))
+#define CAMEL_TYPE_STREAM_FS \
+	(camel_stream_fs_get_type ())
+#define CAMEL_STREAM_FS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM_FS, CamelStreamFs))
+#define CAMEL_STREAM_FS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM_FS, CamelStreamFsClass))
+#define CAMEL_IS_STREAM_FS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM_FS))
+#define CAMEL_IS_STREAM_FS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM_FS))
+#define CAMEL_STREAM_FS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM_FS, CamelStreamFsClass))
 
 G_BEGIN_DECLS
 
-struct _CamelStreamFs {
-	CamelSeekableStream parent_object;
+typedef struct _CamelStreamFs CamelStreamFs;
+typedef struct _CamelStreamFsClass CamelStreamFsClass;
+typedef struct _CamelStreamFsPrivate CamelStreamFsPrivate;
 
-	gint fd;             /* file descriptor on the underlying file */
+struct _CamelStreamFs {
+	CamelSeekableStream parent;
+	CamelStreamFsPrivate *priv;
 };
 
-typedef struct {
+struct _CamelStreamFsClass {
 	CamelSeekableStreamClass parent_class;
+};
 
-} CamelStreamFsClass;
-
-/* Standard Camel function */
-CamelType camel_stream_fs_get_type (void);
-
-/* public methods */
-CamelStream * camel_stream_fs_new_with_name            (const gchar *name, gint flags, mode_t mode);
-CamelStream * camel_stream_fs_new_with_name_and_bounds (const gchar *name, gint flags, mode_t mode,
-							off_t start, off_t end);
-
-CamelStream * camel_stream_fs_new_with_fd              (gint fd);
-CamelStream * camel_stream_fs_new_with_fd_and_bounds   (gint fd, off_t start, off_t end);
+GType		camel_stream_fs_get_type	(void);
+CamelStream *	camel_stream_fs_new_with_name	(const gchar *name,
+						 gint flags,
+						 mode_t mode);
+CamelStream *	camel_stream_fs_new_with_name_and_bounds
+						(const gchar *name,
+						 gint flags,
+						 mode_t mode,
+						 off_t start,
+						 off_t end);
+CamelStream *	camel_stream_fs_new_with_fd	(gint fd);
+CamelStream *	camel_stream_fs_new_with_fd_and_bounds
+						(gint fd,
+						 off_t start,
+						 off_t end);
+gint		camel_stream_fs_get_fd		(CamelStreamFs *stream);
 
 G_END_DECLS
 
diff --git a/camel/camel-stream-mem.c b/camel/camel-stream-mem.c
index 2c55a86..8b770a4 100644
--- a/camel/camel-stream-mem.c
+++ b/camel/camel-stream-mem.c
@@ -34,80 +34,206 @@
 
 #include "camel-stream-mem.h"
 
-static CamelSeekableStreamClass *parent_class = NULL;
+#define CAMEL_STREAM_MEM_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_STREAM_MEM, CamelStreamMemPrivate))
 
-/* Returns the class for a CamelStreamMem */
-#define CSM_CLASS(so) CAMEL_STREAM_MEM_CLASS(CAMEL_OBJECT_GET_CLASS(so))
+struct _CamelStreamMemPrivate {
+	guint owner  : 1;	/* do we own the buffer? */
+	guint secure : 1;	/* do we clear the buffer on finalize?
+				   (only if we own it) */
 
-static gssize stream_read (CamelStream *stream, gchar *buffer, gsize n);
-static gssize stream_write (CamelStream *stream, const gchar *buffer, gsize n);
-static gboolean stream_eos (CamelStream *stream);
-static off_t stream_seek (CamelSeekableStream *stream, off_t offset,
-			  CamelStreamSeekPolicy policy);
+	GByteArray *buffer;
+};
 
-static void camel_stream_mem_finalize (CamelObject *object);
+static gpointer parent_class;
 
+/* could probably be a util method */
 static void
-camel_stream_mem_class_init (CamelStreamMemClass *camel_stream_mem_class)
+clear_mem (gpointer p, gsize len)
 {
-	CamelSeekableStreamClass *camel_seekable_stream_class =
-		CAMEL_SEEKABLE_STREAM_CLASS (camel_stream_mem_class);
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_stream_mem_class);
-
-	parent_class = CAMEL_SEEKABLE_STREAM_CLASS( camel_type_get_global_classfuncs( CAMEL_SEEKABLE_STREAM_TYPE ) );
+	gchar *s = p;
 
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->eos = stream_eos;
+	/* This also helps debug bad access memory errors */
+	while (len > 4) {
+		*s++ = 0xAB;
+		*s++ = 0xAD;
+		*s++ = 0xF0;
+		*s++ = 0x0D;
+		len -= 4;
+	}
 
-	camel_seekable_stream_class->seek = stream_seek;
+	memset(s, 0xbf, len);
 }
 
 static void
-camel_stream_mem_init (CamelObject *object)
+stream_mem_finalize (GObject *object)
 {
-	CamelStreamMem *stream_mem = CAMEL_STREAM_MEM (object);
+	CamelStreamMemPrivate *priv;
+
+	priv = CAMEL_STREAM_MEM_GET_PRIVATE (object);
 
-	stream_mem->owner = FALSE;
-	stream_mem->buffer = NULL;
+	if (priv->buffer && priv->owner) {
+		/* TODO: we need our own bytearray type since we don't know
+		   the real size of the underlying buffer :-/ */
+		if (priv->secure && priv->buffer->len)
+			clear_mem (priv->buffer->data, priv->buffer->len);
+		g_byte_array_free (priv->buffer, TRUE);
+	}
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
-/* could probably be a util method */
-static void clear_mem(gpointer p, gsize len)
+static gssize
+stream_mem_read (CamelStream *stream,
+                 gchar *buffer,
+                 gsize n)
 {
-	gchar *s = p;
+	CamelStreamMemPrivate *priv;
+	CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
+	gssize nread;
 
-	/* This also helps debug bad access memory errors */
-	while (len > 4) {
-		*s++ = 0xAB;
-		*s++ = 0xAD;
-		*s++ = 0xF0;
-		*s++ = 0x0D;
-		len -= 4;
+	priv = CAMEL_STREAM_MEM_GET_PRIVATE (stream);
+
+	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
+		n = MIN(seekable->bound_end - seekable->position, n);
+
+	nread = MIN (n, priv->buffer->len - seekable->position);
+	if (nread > 0) {
+		memcpy (buffer, priv->buffer->data + seekable->position, nread);
+		seekable->position += nread;
+	} else
+		nread = 0;
+
+	return nread;
+}
+
+static gssize
+stream_mem_write (CamelStream *stream,
+                  const gchar *buffer,
+                  gsize n)
+{
+	CamelStreamMemPrivate *priv;
+	CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
+	gssize nwrite = n;
+
+	priv = CAMEL_STREAM_MEM_GET_PRIVATE (stream);
+
+	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
+		nwrite = MIN(seekable->bound_end - seekable->position, n);
+
+	/* FIXME: we shouldn't use g_byte_arrays or g_malloc perhaps? */
+	if (seekable->position == priv->buffer->len) {
+		g_byte_array_append(priv->buffer, (const guint8 *)buffer, nwrite);
+	} else {
+		g_byte_array_set_size(priv->buffer, nwrite + priv->buffer->len);
+		memcpy(priv->buffer->data + seekable->position, buffer, nwrite);
 	}
+	seekable->position += nwrite;
 
-	memset(s, 0xbf, len);
+	return nwrite;
 }
 
-CamelType
-camel_stream_mem_get_type (void)
+static gboolean
+stream_mem_eos (CamelStream *stream)
 {
-	static CamelType camel_stream_mem_type = CAMEL_INVALID_TYPE;
-
-	if (camel_stream_mem_type == CAMEL_INVALID_TYPE) {
-		camel_stream_mem_type = camel_type_register( CAMEL_SEEKABLE_STREAM_TYPE,
-							     "CamelStreamMem",
-							     sizeof( CamelStreamMem ),
-							     sizeof( CamelStreamMemClass ),
-							     (CamelObjectClassInitFunc) camel_stream_mem_class_init,
-							     NULL,
-							     (CamelObjectInitFunc) camel_stream_mem_init,
-							     (CamelObjectFinalizeFunc) camel_stream_mem_finalize );
+	CamelStreamMemPrivate *priv;
+	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
+
+	priv = CAMEL_STREAM_MEM_GET_PRIVATE (stream);
+
+	return priv->buffer->len <= seekable_stream->position;
+}
+
+static off_t
+stream_mem_seek (CamelSeekableStream *stream,
+                 off_t offset,
+                 CamelStreamSeekPolicy policy)
+{
+	CamelStreamMemPrivate *priv;
+	off_t position;
+
+	priv = CAMEL_STREAM_MEM_GET_PRIVATE (stream);
+
+	switch  (policy) {
+	case CAMEL_STREAM_SET:
+		position = offset;
+		break;
+	case CAMEL_STREAM_CUR:
+		position = stream->position + offset;
+		break;
+	case CAMEL_STREAM_END:
+		position = (priv->buffer)->len + offset;
+		break;
+	default:
+		position = offset;
+		break;
+	}
+
+	if (stream->bound_end != CAMEL_STREAM_UNBOUND)
+		position = MIN (position, stream->bound_end);
+	if (stream->bound_start != CAMEL_STREAM_UNBOUND)
+		position = MAX (position, 0);
+	else
+		position = MAX (position, stream->bound_start);
+
+	if (position > priv->buffer->len) {
+		gint oldlen = priv->buffer->len;
+		g_byte_array_set_size (priv->buffer, position);
+		memset (priv->buffer->data + oldlen, 0,
+			position - oldlen);
 	}
 
-	return camel_stream_mem_type;
+	stream->position = position;
+
+	return position;
+}
+
+static void
+stream_mem_class_init (CamelStreamMemClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+	CamelSeekableStreamClass *seekable_stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelStreamMemPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = stream_mem_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_mem_read;
+	stream_class->write = stream_mem_write;
+	stream_class->eos = stream_mem_eos;
+
+	seekable_stream_class = CAMEL_SEEKABLE_STREAM_CLASS (class);
+	seekable_stream_class->seek = stream_mem_seek;
+}
+
+static void
+stream_mem_init (CamelStreamMem *stream)
+{
+	stream->priv = CAMEL_STREAM_MEM_GET_PRIVATE (stream);
+}
+
+GType
+camel_stream_mem_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SEEKABLE_STREAM,
+			"CamelStreamMem",
+			sizeof (CamelStreamMemClass),
+			(GClassInitFunc) stream_mem_class_init,
+			sizeof (CamelStreamMem),
+			(GInstanceInitFunc) stream_mem_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -137,12 +263,16 @@ camel_stream_mem_new (void)
  * Returns: a new #CamelStreamMem
  **/
 CamelStream *
-camel_stream_mem_new_with_buffer (const gchar *buffer, gsize len)
+camel_stream_mem_new_with_buffer (const gchar *buffer,
+                                  gsize len)
 {
 	GByteArray *ba;
 
+	g_return_val_if_fail (buffer != NULL, NULL);
+
 	ba = g_byte_array_new ();
 	g_byte_array_append (ba, (const guint8 *)buffer, len);
+
 	return camel_stream_mem_new_with_byte_array (ba);
 }
 
@@ -160,13 +290,18 @@ camel_stream_mem_new_with_buffer (const gchar *buffer, gsize len)
 CamelStream *
 camel_stream_mem_new_with_byte_array (GByteArray *buffer)
 {
-	CamelStreamMem *stream_mem;
+	CamelStream *stream;
+	CamelStreamMemPrivate *priv;
+
+	g_return_val_if_fail (buffer != NULL, NULL);
+
+	stream = g_object_new (CAMEL_TYPE_STREAM_MEM, NULL);
+	priv = CAMEL_STREAM_MEM_GET_PRIVATE (stream);
 
-	stream_mem = CAMEL_STREAM_MEM (camel_object_new (CAMEL_STREAM_MEM_TYPE));
-	stream_mem->buffer = buffer;
-	stream_mem->owner = TRUE;
+	priv->buffer = buffer;
+	priv->owner = TRUE;
 
-	return CAMEL_STREAM (stream_mem);
+	return stream;
 }
 
 /**
@@ -174,18 +309,27 @@ 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
 camel_stream_mem_set_secure(CamelStreamMem *mem)
 {
-	mem->secure = 1;
-	/* setup a mem-locked buffer etc?  blah blah, well not yet anyway */
+	g_return_if_fail (CAMEL_IS_STREAM_MEM (mem));
+
+	mem->priv->secure = 1;
 }
 
 /* note: with these functions the caller is the 'owner' of the buffer */
 
+GByteArray *
+camel_stream_mem_get_byte_array (CamelStreamMem *mem)
+{
+	g_return_val_if_fail (CAMEL_IS_STREAM_MEM (mem), NULL);
+
+	return mem->priv->buffer;
+}
+
 /**
  * camel_stream_mem_set_byte_array:
  * @mem: a #CamelStreamMem object
@@ -197,15 +341,21 @@ camel_stream_mem_set_secure(CamelStreamMem *mem)
  * be freed separately from @mem.
  **/
 void
-camel_stream_mem_set_byte_array (CamelStreamMem *mem, GByteArray *buffer)
+camel_stream_mem_set_byte_array (CamelStreamMem *mem,
+                                 GByteArray *buffer)
 {
-	if (mem->buffer && mem->owner) {
-		if (mem->secure && mem->buffer->len)
-			clear_mem (mem->buffer->data, mem->buffer->len);
-		g_byte_array_free (mem->buffer, TRUE);
+	g_return_if_fail (CAMEL_IS_STREAM_MEM (mem));
+	g_return_if_fail (buffer != NULL);
+
+	if (mem->priv->buffer && mem->priv->owner) {
+		if (mem->priv->secure && mem->priv->buffer->len)
+			clear_mem (
+				mem->priv->buffer->data,
+				mem->priv->buffer->len);
+		g_byte_array_free (mem->priv->buffer, TRUE);
 	}
-	mem->owner = FALSE;
-	mem->buffer = buffer;
+	mem->priv->owner = FALSE;
+	mem->priv->buffer = buffer;
 }
 
 /**
@@ -220,118 +370,17 @@ camel_stream_mem_set_byte_array (CamelStreamMem *mem, GByteArray *buffer)
  * and so may have resource implications to consider.
  **/
 void
-camel_stream_mem_set_buffer (CamelStreamMem *mem, const gchar *buffer, gsize len)
+camel_stream_mem_set_buffer (CamelStreamMem *mem,
+                             const gchar *buffer,
+                             gsize len)
 {
 	GByteArray *ba;
 
+	g_return_if_fail (CAMEL_IS_STREAM_MEM (mem));
+	g_return_if_fail (buffer != NULL);
+
 	ba = g_byte_array_new ();
 	g_byte_array_append(ba, (const guint8 *)buffer, len);
 	camel_stream_mem_set_byte_array(mem, ba);
-	mem->owner = TRUE;
-}
-
-static void
-camel_stream_mem_finalize (CamelObject *object)
-{
-	CamelStreamMem *s = CAMEL_STREAM_MEM (object);
-
-	if (s->buffer && s->owner) {
-		/* TODO: we need our own bytearray type since we don't know
-		   the real size of the underlying buffer :-/ */
-		if (s->secure && s->buffer->len)
-			clear_mem(s->buffer->data, s->buffer->len);
-		g_byte_array_free(s->buffer, TRUE);
-	}
-}
-
-static gssize
-stream_read (CamelStream *stream, gchar *buffer, gsize n)
-{
-	CamelStreamMem *camel_stream_mem = CAMEL_STREAM_MEM (stream);
-	CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
-	gssize nread;
-
-	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
-		n = MIN(seekable->bound_end - seekable->position, n);
-
-	nread = MIN (n, camel_stream_mem->buffer->len - seekable->position);
-	if (nread > 0) {
-		memcpy (buffer, camel_stream_mem->buffer->data + seekable->position, nread);
-		seekable->position += nread;
-	} else
-		nread = 0;
-
-	return nread;
-}
-
-static gssize
-stream_write (CamelStream *stream, const gchar *buffer, gsize n)
-{
-	CamelStreamMem *stream_mem = CAMEL_STREAM_MEM (stream);
-	CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
-	gssize nwrite = n;
-
-	if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
-		nwrite = MIN(seekable->bound_end - seekable->position, n);
-
-	/* FIXME: we shouldn't use g_byte_arrays or g_malloc perhaps? */
-	if (seekable->position == stream_mem->buffer->len) {
-		g_byte_array_append(stream_mem->buffer, (const guint8 *)buffer, nwrite);
-	} else {
-		g_byte_array_set_size(stream_mem->buffer, nwrite + stream_mem->buffer->len);
-		memcpy(stream_mem->buffer->data + seekable->position, buffer, nwrite);
-	}
-	seekable->position += nwrite;
-
-	return nwrite;
-}
-
-static gboolean
-stream_eos (CamelStream *stream)
-{
-	CamelStreamMem *stream_mem = CAMEL_STREAM_MEM (stream);
-	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
-
-	return stream_mem->buffer->len <= seekable_stream->position;
-}
-
-static off_t
-stream_seek (CamelSeekableStream *stream, off_t offset,
-	     CamelStreamSeekPolicy policy)
-{
-	off_t position;
-	CamelStreamMem *stream_mem = CAMEL_STREAM_MEM (stream);
-
-	switch  (policy) {
-	case CAMEL_STREAM_SET:
-		position = offset;
-		break;
-	case CAMEL_STREAM_CUR:
-		position = stream->position + offset;
-		break;
-	case CAMEL_STREAM_END:
-		position = (stream_mem->buffer)->len + offset;
-		break;
-	default:
-		position = offset;
-		break;
-	}
-
-	if (stream->bound_end != CAMEL_STREAM_UNBOUND)
-		position = MIN (position, stream->bound_end);
-	if (stream->bound_start != CAMEL_STREAM_UNBOUND)
-		position = MAX (position, 0);
-	else
-		position = MAX (position, stream->bound_start);
-
-	if (position > stream_mem->buffer->len) {
-		gint oldlen = stream_mem->buffer->len;
-		g_byte_array_set_size (stream_mem->buffer, position);
-		memset (stream_mem->buffer->data + oldlen, 0,
-			position - oldlen);
-	}
-
-	stream->position = position;
-
-	return position;
+	mem->priv->owner = TRUE;
 }
diff --git a/camel/camel-stream-mem.h b/camel/camel-stream-mem.h
index 2a5060b..7e85c01 100644
--- a/camel/camel-stream-mem.h
+++ b/camel/camel-stream-mem.h
@@ -22,49 +22,63 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_STREAM_MEM_H
-#define CAMEL_STREAM_MEM_H 1
+#define CAMEL_STREAM_MEM_H
 
 #include <sys/types.h>
 #include <camel/camel-seekable-stream.h>
 
-#define CAMEL_STREAM_MEM_TYPE     (camel_stream_mem_get_type ())
-#define CAMEL_STREAM_MEM(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_STREAM_MEM_TYPE, CamelStreamMem))
-#define CAMEL_STREAM_MEM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_STREAM_MEM_TYPE, CamelStreamMemClass))
-#define CAMEL_IS_STREAM_MEM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_STREAM_MEM_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_STREAM_MEM \
+	(camel_stream_mem_get_type ())
+#define CAMEL_STREAM_MEM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM_MEM, CamelStreamMem))
+#define CAMEL_STREAM_MEM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM_MEM, CamelStreamMemClass))
+#define CAMEL_IS_STREAM_MEM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM_MEM))
+#define CAMEL_IS_STREAM_MEM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM_MEM))
+#define CAMEL_STREAM_MEM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM_MEM, CamelStreamMemClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelStreamMem CamelStreamMem;
 typedef struct _CamelStreamMemClass CamelStreamMemClass;
+typedef struct _CamelStreamMemPrivate CamelStreamMemPrivate;
 
 struct _CamelStreamMem {
-	CamelSeekableStream parent_object;
-
-	guint owner:1;	/* do we own the buffer? */
-	guint secure:1;	/* do we clear the buffer on finalise (if we own it) */
-	GByteArray *buffer;
+	CamelSeekableStream parent;
+	CamelStreamMemPrivate *priv;
 };
 
 struct _CamelStreamMemClass {
 	CamelSeekableStreamClass parent_class;
-
-	/* Virtual methods */
 };
 
-/* Standard Camel function */
-CamelType camel_stream_mem_get_type (void);
-
-/* public methods */
-CamelStream *camel_stream_mem_new(void);
-CamelStream *camel_stream_mem_new_with_byte_array(GByteArray *buffer);
-CamelStream *camel_stream_mem_new_with_buffer(const gchar *buffer, gsize len);
-
-/* 'secure' data, currently just clears memory on finalise */
-void camel_stream_mem_set_secure(CamelStreamMem *mem);
-
-/* these are really only here for implementing classes */
-void camel_stream_mem_set_byte_array(CamelStreamMem *mem, GByteArray *buffer);
-void camel_stream_mem_set_buffer(CamelStreamMem *mem, const gchar *buffer, gsize len);
+GType		camel_stream_mem_get_type	(void);
+CamelStream *	camel_stream_mem_new		(void);
+CamelStream *	camel_stream_mem_new_with_byte_array
+						(GByteArray *buffer);
+CamelStream *	camel_stream_mem_new_with_buffer(const gchar *buffer,
+						 gsize len);
+void		camel_stream_mem_set_secure	(CamelStreamMem *mem);
+GByteArray *	camel_stream_mem_get_byte_array (CamelStreamMem *mem);
+void		camel_stream_mem_set_byte_array	(CamelStreamMem *mem,
+						 GByteArray *buffer);
+void		camel_stream_mem_set_buffer	(CamelStreamMem *mem,
+						 const gchar *buffer,
+						 gsize len);
 
 G_END_DECLS
 
diff --git a/camel/camel-stream-null.c b/camel/camel-stream-null.c
index a93393a..fd6d249 100644
--- a/camel/camel-stream-null.c
+++ b/camel/camel-stream-null.c
@@ -28,52 +28,61 @@
 
 #include "camel-stream-null.h"
 
-static CamelObjectClass *parent_class = NULL;
+static gpointer parent_class;
 
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_STREAM_NULL_CLASS(CAMEL_OBJECT_GET_CLASS(so))
+static gssize
+stream_null_write (CamelStream *stream,
+                   const gchar *buffer,
+                   gsize n)
+{
+	CAMEL_STREAM_NULL (stream)->written += n;
+
+	return n;
+}
 
-/* dummy implementations, for a NULL stream */
-static gssize   stream_read       (CamelStream *stream, gchar *buffer, gsize n) { return 0; }
-static gssize   stream_write      (CamelStream *stream, const gchar *buffer, gsize n) { ((CamelStreamNull *)stream)->written += n; return n; }
-static gint       stream_close      (CamelStream *stream) { return 0; }
-static gint       stream_flush      (CamelStream *stream) { return 0; }
-static gboolean  stream_eos        (CamelStream *stream) { return TRUE; }
-static gint       stream_reset      (CamelStream *stream) { ((CamelStreamNull *)stream)->written = 0; return 0; }
+static gboolean
+stream_null_eos (CamelStream *stream)
+{
+	return TRUE;
+}
+
+static gint
+stream_null_reset (CamelStream *stream)
+{
+	CAMEL_STREAM_NULL (stream)->written = 0;
+
+	return 0;
+}
 
 static void
-camel_stream_null_class_init (CamelStreamClass *camel_stream_null_class)
+stream_null_class_init (CamelStreamClass *class)
 {
-	CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_stream_null_class;
+	CamelStreamClass *stream_class;
 
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	parent_class = g_type_class_peek_parent (class);
 
-	/* virtual method definition */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->eos = stream_eos;
-	camel_stream_class->reset = stream_reset;
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->write = stream_null_write;
+	stream_class->eos = stream_null_eos;
+	stream_class->reset = stream_null_reset;
 }
 
-CamelType
+GType
 camel_stream_null_get_type (void)
 {
-	static CamelType camel_stream_null_type = CAMEL_INVALID_TYPE;
-
-	if (camel_stream_null_type == CAMEL_INVALID_TYPE) {
-		camel_stream_null_type = camel_type_register( camel_stream_get_type(),
-							      "CamelStreamNull",
-							      sizeof( CamelStreamNull ),
-							      sizeof( CamelStreamNullClass ),
-							      (CamelObjectClassInitFunc) camel_stream_null_class_init,
-							      NULL,
-							      NULL,
-							      NULL );
-	}
-
-	return camel_stream_null_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelStreamNull",
+			sizeof (CamelStreamNullClass),
+			(GClassInitFunc) stream_null_class_init,
+			sizeof (CamelStreamNull),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 /**
@@ -87,5 +96,5 @@ camel_stream_null_get_type (void)
 CamelStream *
 camel_stream_null_new(void)
 {
-	return (CamelStream *)camel_object_new(camel_stream_null_get_type ());
+	return g_object_new (CAMEL_TYPE_STREAM_NULL, NULL);
 }
diff --git a/camel/camel-stream-null.h b/camel/camel-stream-null.h
index 46e3d3b..94e96ab 100644
--- a/camel/camel-stream-null.h
+++ b/camel/camel-stream-null.h
@@ -19,17 +19,37 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_STREAM_NULL_H
-#define _CAMEL_STREAM_NULL_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_STREAM_NULL_H
+#define CAMEL_STREAM_NULL_H
 
 #include <camel/camel-stream.h>
 
-#define CAMEL_STREAM_NULL(obj)         CAMEL_CHECK_CAST (obj, camel_stream_null_get_type (), CamelStreamNull)
-#define CAMEL_STREAM_NULL_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_stream_null_get_type (), CamelStreamNullClass)
-#define CAMEL_IS_STREAM_NULL(obj)      CAMEL_CHECK_TYPE (obj, camel_stream_null_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_STREAM_NULL \
+	(camel_stream_null_get_type ())
+#define CAMEL_STREAM_NULL(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM_NULL, CamelStreamNull))
+#define CAMEL_STREAM_NULL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM_NULL, CamelStreamNullClass))
+#define CAMEL_IS_STREAM_NULL(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM_NULL))
+#define CAMEL_IS_STREAM_NULL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM_NULL))
+#define CAMEL_STREAM_NULL_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM_NULL, CamelStreamNullClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelStreamNull CamelStreamNull;
 typedef struct _CamelStreamNullClass CamelStreamNullClass;
 
 struct _CamelStreamNull {
@@ -42,10 +62,10 @@ struct _CamelStreamNullClass {
 	CamelStreamClass parent_class;
 };
 
-CamelType camel_stream_null_get_type (void);
+GType camel_stream_null_get_type (void);
 
 CamelStream *camel_stream_null_new (void);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_STREAM_NULL_H */
+#endif /* CAMEL_STREAM_NULL_H */
diff --git a/camel/camel-stream-process.c b/camel/camel-stream-process.c
index 91053f3..a469f02 100644
--- a/camel/camel-stream-process.c
+++ b/camel/camel-stream-process.c
@@ -44,82 +44,23 @@
 
 extern gint camel_verbose_debug;
 
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_STREAM_PROCESS_CLASS(CAMEL_OBJECT_GET_CLASS(so))
-
-/* dummy implementations, for a PROCESS stream */
-static gssize   stream_read       (CamelStream *stream, gchar *buffer, gsize n);
-static gssize   stream_write      (CamelStream *stream, const gchar *buffer, gsize n);
-static gint       stream_close      (CamelStream *stream);
-static gint       stream_flush      (CamelStream *stream);
+static gpointer parent_class;
 
 static void
-camel_stream_process_finalise (CamelObject *object)
+stream_process_finalize (GObject *object)
 {
 	/* Ensure we clean up after ourselves -- kill
 	   the child process and reap it. */
-	stream_close (CAMEL_STREAM (object));
-}
-
-static void
-camel_stream_process_class_init (CamelStreamProcessClass *camel_stream_process_class)
-{
-	CamelStreamClass *camel_stream_class = (CamelStreamClass *) camel_stream_process_class;
-
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
-
-	/* virtual method definition */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->flush = stream_flush;
-}
-
-static void
-camel_stream_process_init (gpointer object, gpointer klass)
-{
-        CamelStreamProcess *stream = CAMEL_STREAM_PROCESS (object);
-
-        stream->sockfd = -1;
-	stream->childpid = 0;
-}
-
-CamelType
-camel_stream_process_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type =  camel_type_register (camel_stream_get_type (),
-					     "CamelStreamProcess",
-					     sizeof (CamelStreamProcess),
-					     sizeof (CamelStreamProcessClass),
-					     (CamelObjectClassInitFunc) camel_stream_process_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) camel_stream_process_init,
-					     (CamelObjectFinalizeFunc) camel_stream_process_finalise);
-	}
+	camel_stream_close (CAMEL_STREAM (object));
 
-	return type;
-}
-
-/**
- * camel_stream_process_new:
- *
- * Returns a PROCESS stream.
- *
- * Return value: the stream
- **/
-CamelStream *
-camel_stream_process_new (void)
-{
-	return (CamelStream *) camel_object_new (camel_stream_process_get_type ());
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gssize
-stream_read (CamelStream *stream, gchar *buffer, gsize n)
+stream_process_read (CamelStream *stream,
+                     gchar *buffer,
+                     gsize n)
 {
 	CamelStreamProcess *stream_process = CAMEL_STREAM_PROCESS (stream);
 
@@ -127,7 +68,9 @@ stream_read (CamelStream *stream, gchar *buffer, gsize n)
 }
 
 static gssize
-stream_write (CamelStream *stream, const gchar *buffer, gsize n)
+stream_process_write (CamelStream *stream,
+                      const gchar *buffer,
+                      gsize n)
 {
 	CamelStreamProcess *stream_process = CAMEL_STREAM_PROCESS (stream);
 
@@ -135,13 +78,7 @@ stream_write (CamelStream *stream, const gchar *buffer, gsize n)
 }
 
 static gint
-stream_flush (CamelStream *stream)
-{
-	return 0;
-}
-
-static gint
-stream_close (CamelStream *object)
+stream_process_close (CamelStream *object)
 {
 	CamelStreamProcess *stream = CAMEL_STREAM_PROCESS (object);
 
@@ -189,6 +126,68 @@ stream_close (CamelStream *object)
 	return 0;
 }
 
+static gint
+stream_process_flush (CamelStream *stream)
+{
+	return 0;
+}
+
+static void
+stream_process_class_init (CamelStreamProcessClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = stream_process_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_process_read;
+	stream_class->write = stream_process_write;
+	stream_class->close = stream_process_close;
+	stream_class->flush = stream_process_flush;
+}
+
+static void
+stream_process_init (CamelStreamProcess *stream)
+{
+	stream->sockfd = -1;
+	stream->childpid = 0;
+}
+
+GType
+camel_stream_process_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelStreamProcess",
+			sizeof (CamelStreamProcessClass),
+			(GClassInitFunc) stream_process_class_init,
+			sizeof (CamelStreamProcess),
+			(GInstanceInitFunc) stream_process_init,
+			0);
+
+	return type;
+}
+
+/**
+ * camel_stream_process_new:
+ *
+ * Returns a PROCESS stream.
+ *
+ * Return value: the stream
+ **/
+CamelStream *
+camel_stream_process_new (void)
+{
+	return g_object_new (CAMEL_TYPE_STREAM_PROCESS, NULL);
+}
+
 G_GNUC_NORETURN static void
 do_exec_command (gint fd, const gchar *command, gchar **env)
 {
@@ -240,7 +239,7 @@ camel_stream_process_connect (CamelStreamProcess *stream, const gchar *command,
 	gint sockfds[2];
 
 	if (stream->sockfd != -1 || stream->childpid)
-		stream_close (CAMEL_STREAM (stream));
+		camel_stream_close (CAMEL_STREAM (stream));
 
 	if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockfds))
 		return -1;
diff --git a/camel/camel-stream-process.h b/camel/camel-stream-process.h
index 4c435cd..84496d6 100644
--- a/camel/camel-stream-process.h
+++ b/camel/camel-stream-process.h
@@ -19,19 +19,38 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_STREAM_NULL_H
-#define _CAMEL_STREAM_NULL_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_STREAM_PROCESS_H
+#define CAMEL_STREAM_PROCESS_H
 
 #include <camel/camel-stream.h>
 
-#define CAMEL_STREAM_PROCESS(obj)         CAMEL_CHECK_CAST (obj, camel_stream_process_get_type (), CamelStreamProcess)
-#define CAMEL_STREAM_PROCESS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_stream_process_get_type (), CamelStreamProcessClass)
-#define CAMEL_IS_STREAM_PROCESS(obj)      CAMEL_CHECK_TYPE (obj, camel_stream_process_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_STREAM_PROCESS \
+	(camel_stream_process_get_type ())
+#define CAMEL_STREAM_PROCESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM_PROCESS, CamelStreamProcess))
+#define CAMEL_STREAM_PROCESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM_PROCESS, CamelStreamProcessClass))
+#define CAMEL_IS_STREAM_PROCESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM_PROCESS))
+#define CAMEL_IS_STREAM_PROCESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM_PROCESS))
+#define CAMEL_STREAM_PROCESS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM_PROCSS, CamelStreamProcessClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelStreamProcessClass CamelStreamProcessClass;
 typedef struct _CamelStreamProcess CamelStreamProcess;
+typedef struct _CamelStreamProcessClass CamelStreamProcessClass;
 
 struct _CamelStreamProcess {
 	CamelStream parent;
@@ -44,10 +63,10 @@ struct _CamelStreamProcessClass {
 	CamelStreamClass parent_class;
 };
 
-CamelType		camel_stream_process_get_type	(void);
+GType		camel_stream_process_get_type	(void);
 CamelStream            *camel_stream_process_new		(void);
 gint camel_stream_process_connect(CamelStreamProcess *, const gchar *, const gchar **);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_STREAM_PROCESS_H */
+#endif /* CAMEL_STREAM_PROCESS_H */
diff --git a/camel/camel-stream-vfs.c b/camel/camel-stream-vfs.c
index b735638..c526e27 100644
--- a/camel/camel-stream-vfs.c
+++ b/camel/camel-stream-vfs.c
@@ -28,7 +28,6 @@
 #include <errno.h>
 #include <string.h>
 
-#include <glib.h>
 #include <gio/gio.h>
 
 #include "camel-file-utils.h"
@@ -36,64 +35,155 @@
 #include "camel-private.h"
 #include "camel-stream-vfs.h"
 
-static CamelStreamClass *parent_class = NULL;
+static gpointer parent_class;
 
-/* Returns the class for a CamelStreamVFS */
-#define CSVFS_CLASS(so) CAMEL_STREAM_VFS_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static void
+stream_vfs_dispose (GObject *object)
+{
+	CamelStreamVFS *stream = CAMEL_STREAM_VFS (object);
 
-static gssize stream_read   (CamelStream *stream, gchar *buffer, gsize n);
-static gssize stream_write  (CamelStream *stream, const gchar *buffer, gsize n);
-static gint stream_flush  (CamelStream *stream);
-static gint stream_close  (CamelStream *stream);
+	if (stream->stream != NULL) {
+		g_object_unref (stream->stream);
+		stream->stream = NULL;
+	}
 
-static void
-camel_stream_vfs_class_init (CamelStreamVFSClass *camel_stream_vfs_class)
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static gssize
+stream_vfs_read (CamelStream *stream,
+                 gchar *buffer,
+                 gsize n)
 {
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_stream_vfs_class);
+	gssize nread;
+	GError *error = NULL;
+	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
 
-	parent_class = CAMEL_STREAM_CLASS (camel_type_get_global_classfuncs (camel_stream_get_type ()));
+	g_return_val_if_fail (G_IS_INPUT_STREAM (stream_vfs->stream), 0);
 
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->close = stream_close;
+	nread = g_input_stream_read (G_INPUT_STREAM (stream_vfs->stream), buffer, n, NULL, &error);
+
+	if (nread == 0 || error)
+		stream->eos = TRUE;
+
+	if (error) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+	}
+
+	return nread;
 }
 
-static void
-camel_stream_vfs_init (gpointer object, gpointer klass)
+static gssize
+stream_vfs_write (CamelStream *stream,
+                  const gchar *buffer,
+                  gsize n)
 {
-	CamelStreamVFS *stream = CAMEL_STREAM_VFS (object);
+	gboolean success;
+	gsize bytes_written;
+	GError *error = NULL;
+	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
 
-	stream->stream = NULL;
+	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), 0);
+
+	success = g_output_stream_write_all (G_OUTPUT_STREAM (stream_vfs->stream), buffer, n, &bytes_written, NULL, &error);
+
+	if (error) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+	}
+	return success ? bytes_written : -1;
 }
 
-static void
-camel_stream_vfs_finalize (CamelObject *object)
+static gint
+stream_vfs_flush (CamelStream *stream)
 {
-	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (object);
+	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
+	GError *error = NULL;
+
+	g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1);
+	g_return_val_if_fail (stream_vfs->stream != NULL, -1);
+	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), -1);
+
+	g_output_stream_flush (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error);
+
+	if (error) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+		return -1;
+	}
 
-	if (stream_vfs->stream)
-		g_object_unref (stream_vfs->stream);
+	return 0;
 }
 
-CamelType
-camel_stream_vfs_get_type (void)
+static gint
+stream_vfs_close (CamelStream *stream)
 {
-	static CamelType camel_stream_vfs_type = CAMEL_INVALID_TYPE;
-
-	if (camel_stream_vfs_type == CAMEL_INVALID_TYPE) {
-		camel_stream_vfs_type = camel_type_register (camel_stream_get_type (), "CamelStreamVFS",
-							    sizeof (CamelStreamVFS),
-							    sizeof (CamelStreamVFSClass),
-							    (CamelObjectClassInitFunc) camel_stream_vfs_class_init,
-							    NULL,
-							    (CamelObjectInitFunc) camel_stream_vfs_init,
-							    (CamelObjectFinalizeFunc) camel_stream_vfs_finalize);
+	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
+	GError *error = NULL;
+
+	g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1);
+	g_return_val_if_fail (stream_vfs->stream != NULL, -1);
+	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream) || G_IS_INPUT_STREAM (stream_vfs->stream), -1);
+
+	if (G_IS_OUTPUT_STREAM (stream_vfs->stream))
+		g_output_stream_close (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error);
+	else
+		g_input_stream_close (G_INPUT_STREAM (stream_vfs->stream), NULL, &error);
+
+	if (error) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+		return -1;
 	}
 
-	return camel_stream_vfs_type;
+	g_object_unref (stream_vfs->stream);
+	stream_vfs->stream = NULL;
+
+	return 0;
+}
+
+static void
+stream_vfs_class_init (CamelStreamVFSClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = stream_vfs_dispose;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_vfs_read;
+	stream_class->write = stream_vfs_write;
+	stream_class->flush = stream_vfs_flush;
+	stream_class->close = stream_vfs_close;
+}
+
+static void
+stream_vfs_init (CamelStreamVFS *stream)
+{
+	stream->stream = NULL;
+}
+
+GType
+camel_stream_vfs_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelStreamVFS",
+			sizeof (CamelStreamVFSClass),
+			(GClassInitFunc) stream_vfs_class_init,
+			sizeof (CamelStreamVFS),
+			(GInstanceInitFunc) stream_vfs_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -119,7 +209,7 @@ camel_stream_vfs_new_with_stream (GObject *stream)
 	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream) || G_IS_INPUT_STREAM (stream), NULL);
 
 	errno = 0;
-	stream_vfs = CAMEL_STREAM_VFS (camel_object_new (camel_stream_vfs_get_type ()));
+	stream_vfs = g_object_new (CAMEL_TYPE_STREAM_VFS, NULL);
 	stream_vfs->stream = stream;
 
 	return CAMEL_STREAM (stream_vfs);
@@ -184,92 +274,3 @@ camel_stream_vfs_is_writable (CamelStreamVFS *stream_vfs)
 
 	return G_IS_OUTPUT_STREAM (stream_vfs->stream);
 }
-
-static gssize
-stream_read (CamelStream *stream, gchar *buffer, gsize n)
-{
-	gssize nread;
-	GError *error = NULL;
-	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
-
-	g_return_val_if_fail (G_IS_INPUT_STREAM (stream_vfs->stream), 0);
-
-	nread = g_input_stream_read (G_INPUT_STREAM (stream_vfs->stream), buffer, n, NULL, &error);
-
-	if (nread == 0 || error)
-		stream->eos = TRUE;
-
-	if (error) {
-		g_warning ("%s", error->message);
-		g_error_free (error);
-	}
-
-	return nread;
-}
-
-static gssize
-stream_write (CamelStream *stream, const gchar *buffer, gsize n)
-{
-	gboolean success;
-	gsize bytes_written;
-	GError *error = NULL;
-	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
-
-	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), 0);
-
-	success = g_output_stream_write_all (G_OUTPUT_STREAM (stream_vfs->stream), buffer, n, &bytes_written, NULL, &error);
-
-	if (error) {
-		g_warning ("%s", error->message);
-		g_error_free (error);
-	}
-	return success ? bytes_written : -1;
-}
-
-static gint
-stream_flush (CamelStream *stream)
-{
-	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
-	GError *error = NULL;
-
-	g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1);
-	g_return_val_if_fail (stream_vfs->stream != NULL, -1);
-	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), -1);
-
-	g_output_stream_flush (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error);
-
-	if (error) {
-		g_warning ("%s", error->message);
-		g_error_free (error);
-		return -1;
-	}
-
-	return 0;
-}
-
-static gint
-stream_close (CamelStream *stream)
-{
-	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
-	GError *error = NULL;
-
-	g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1);
-	g_return_val_if_fail (stream_vfs->stream != NULL, -1);
-	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream) || G_IS_INPUT_STREAM (stream_vfs->stream), -1);
-
-	if (G_IS_OUTPUT_STREAM (stream_vfs->stream))
-		g_output_stream_close (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error);
-	else
-		g_input_stream_close (G_INPUT_STREAM (stream_vfs->stream), NULL, &error);
-
-	if (error) {
-		g_warning ("%s", error->message);
-		g_error_free (error);
-		return -1;
-	}
-
-	g_object_unref (stream_vfs->stream);
-	stream_vfs->stream = NULL;
-
-	return 0;
-}
diff --git a/camel/camel-stream-vfs.h b/camel/camel-stream-vfs.h
index 816129a..ac5a634 100644
--- a/camel/camel-stream-vfs.h
+++ b/camel/camel-stream-vfs.h
@@ -22,25 +22,40 @@
  * USA
  */
 
-#ifndef CAMEL_STREAM_VFS_H
-#define CAMEL_STREAM_VFS_H 1
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
 
-#include <glib.h>
-#include <glib-object.h>
+#ifndef CAMEL_STREAM_VFS_H
+#define CAMEL_STREAM_VFS_H
 
 #include <camel/camel-stream.h>
 
-#define CAMEL_STREAM_VFS_TYPE     (camel_stream_vfs_get_type ())
-#define CAMEL_STREAM_VFS(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_STREAM_VFS_TYPE, CamelStreamVFS))
-#define CAMEL_STREAM_VFS_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_STREAM_VFS_TYPE, CamelStreamVFSClass))
-#define CAMEL_IS_STREAM_VFS(o)    (CAMEL_CHECK_TYPE((o), CAMEL_STREAM_VFS_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_STREAM_VFS \
+	(camel_stream_vfs_get_type ())
+#define CAMEL_STREAM_VFS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM_VFS, CamelStreamVFS))
+#define CAMEL_STREAM_VFS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM_VFS, CamelStreamVFSClass))
+#define CAMEL_IS_STREAM_VFS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM_VFS))
+#define CAMEL_IS_STREAM_VFS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM_VFS))
+#define CAMEL_STREAM_VFS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM_VFS, CamelStreamVFSClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelStreamVFS CamelStreamVFS;
 
 struct _CamelStreamVFS {
-	CamelStream parent_object;
+	CamelStream parent;
 
 	GObject *stream;
 };
@@ -50,8 +65,7 @@ typedef struct {
 
 } CamelStreamVFSClass;
 
-/* Standard Camel function */
-CamelType camel_stream_vfs_get_type (void);
+GType camel_stream_vfs_get_type (void);
 
 typedef enum {
 	CAMEL_STREAM_VFS_CREATE,	/* writable, creates new file or replaces old file */
diff --git a/camel/camel-stream.c b/camel/camel-stream.c
index b8b8da0..f05df4a 100644
--- a/camel/camel-stream.c
+++ b/camel/camel-stream.c
@@ -30,50 +30,77 @@
 
 #include "camel-stream.h"
 
-static CamelObjectClass *parent_class = NULL;
+static gpointer parent_class;
 
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_STREAM_CLASS(CAMEL_OBJECT_GET_CLASS(so))
+static gssize
+stream_read (CamelStream *stream,
+             gchar *buffer,
+             gsize n)
+{
+	return 0;
+}
+
+static gssize
+stream_write (CamelStream *stream,
+              const gchar *buffer,
+              gsize n)
+{
+	return n;
+}
+
+static gint
+stream_close (CamelStream *stream)
+{
+	return 0;
+}
 
-/* default implementations, do very little */
-static gssize   stream_read       (CamelStream *stream, gchar *buffer, gsize n) { return 0; }
-static gssize   stream_write      (CamelStream *stream, const gchar *buffer, gsize n) { return n; }
-static gint       stream_close      (CamelStream *stream) { return 0; }
-static gint       stream_flush      (CamelStream *stream) { return 0; }
-static gboolean  stream_eos        (CamelStream *stream) { return stream->eos; }
-static gint       stream_reset      (CamelStream *stream) { return 0; }
+static gint
+stream_flush (CamelStream *stream)
+{
+	return 0;
+}
+
+static gboolean
+stream_eos (CamelStream *stream)
+{
+	return stream->eos;
+}
+
+static gint
+stream_reset (CamelStream *stream)
+{
+	return 0;
+}
 
 static void
-camel_stream_class_init (CamelStreamClass *camel_stream_class)
+stream_class_init (CamelStreamClass *class)
 {
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
-
-	/* virtual method definition */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->eos = stream_eos;
-	camel_stream_class->reset = stream_reset;
+	parent_class = g_type_class_peek_parent (class);
+
+	class->read = stream_read;
+	class->write = stream_write;
+	class->close = stream_close;
+	class->flush = stream_flush;
+	class->eos = stream_eos;
+	class->reset = stream_reset;
 }
 
-CamelType
+GType
 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,
-							 "CamelStream",
-							 sizeof( CamelStream ),
-							 sizeof( CamelStreamClass ),
-							 (CamelObjectClassInitFunc) camel_stream_class_init,
-							 NULL,
-							 NULL,
-							 NULL );
-	}
-
-	return camel_stream_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelStream",
+			sizeof (CamelStreamClass),
+			(GClassInitFunc) stream_class_init,
+			sizeof (CamelStream),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 /**
@@ -88,12 +115,19 @@ camel_stream_get_type (void)
  * errno.
  **/
 gssize
-camel_stream_read (CamelStream *stream, gchar *buffer, gsize n)
+camel_stream_read (CamelStream *stream,
+                   gchar *buffer,
+                   gsize n)
 {
+	CamelStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 	g_return_val_if_fail (n == 0 || buffer, -1);
 
-	return (CS_CLASS (stream)->read) (stream, buffer, n);
+	class = CAMEL_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->read != NULL, -1);
+
+	return class->read (stream, buffer, n);
 }
 
 /**
@@ -108,12 +142,19 @@ camel_stream_read (CamelStream *stream, gchar *buffer, gsize n)
  * along with setting errno.
  **/
 gssize
-camel_stream_write (CamelStream *stream, const gchar *buffer, gsize n)
+camel_stream_write (CamelStream *stream,
+                    const gchar *buffer,
+                    gsize n)
 {
+	CamelStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 	g_return_val_if_fail (n == 0 || buffer, -1);
 
-	return CS_CLASS (stream)->write (stream, buffer, n);
+	class = CAMEL_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->write != NULL, -1);
+
+	return class->write (stream, buffer, n);
 }
 
 /**
@@ -128,9 +169,14 @@ camel_stream_write (CamelStream *stream, const gchar *buffer, gsize n)
 gint
 camel_stream_flush (CamelStream *stream)
 {
+	CamelStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 
-	return CS_CLASS (stream)->flush (stream);
+	class = CAMEL_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->flush != NULL, -1);
+
+	return class->flush (stream);
 }
 
 /**
@@ -144,9 +190,14 @@ camel_stream_flush (CamelStream *stream)
 gint
 camel_stream_close (CamelStream *stream)
 {
+	CamelStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 
-	return CS_CLASS (stream)->close (stream);
+	class = CAMEL_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->close != NULL, -1);
+
+	return class->close (stream);
 }
 
 /**
@@ -160,9 +211,14 @@ camel_stream_close (CamelStream *stream)
 gboolean
 camel_stream_eos (CamelStream *stream)
 {
+	CamelStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), TRUE);
 
-	return CS_CLASS (stream)->eos (stream);
+	class = CAMEL_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->eos != NULL, TRUE);
+
+	return class->eos (stream);
 }
 
 /**
@@ -178,9 +234,14 @@ camel_stream_eos (CamelStream *stream)
 gint
 camel_stream_reset (CamelStream *stream)
 {
+	CamelStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 
-	return CS_CLASS (stream)->reset (stream);
+	class = CAMEL_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->reset != NULL, -1);
+
+	return class->reset (stream);
 }
 
 /***************** Utility functions ********************/
diff --git a/camel/camel-stream.h b/camel/camel-stream.h
index b44f181..51d450c 100644
--- a/camel/camel-stream.h
+++ b/camel/camel-stream.h
@@ -22,28 +22,48 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_STREAM_H
-#define CAMEL_STREAM_H 1
+#define CAMEL_STREAM_H
 
 #include <stdarg.h>
 #include <unistd.h>
 #include <camel/camel-object.h>
 
-#define CAMEL_STREAM_TYPE     (camel_stream_get_type ())
-#define CAMEL_STREAM(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_STREAM_TYPE, CamelStream))
-#define CAMEL_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_STREAM_TYPE, CamelStreamClass))
-#define CAMEL_IS_STREAM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_STREAM_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_STREAM \
+	(camel_stream_get_type ())
+#define CAMEL_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_STREAM, CamelStream))
+#define CAMEL_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_STREAM, CamelStreamClass))
+#define CAMEL_IS_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_STREAM))
+#define CAMEL_IS_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_STREAM))
+#define CAMEL_STREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_STREAM, CamelStreamClass))
 
 G_BEGIN_DECLS
 
-struct _CamelStream
-{
-	CamelObject parent_object;
+typedef struct _CamelStream CamelStream;
+typedef struct _CamelStreamClass CamelStreamClass;
+
+struct _CamelStream {
+	CamelObject parent;
 
 	gboolean eos;
 };
 
-typedef struct {
+struct _CamelStreamClass {
 	CamelObjectClass parent_class;
 
 	/* Virtual methods */
@@ -54,11 +74,9 @@ typedef struct {
 	gint       (*flush)      (CamelStream *stream);
 	gboolean  (*eos)        (CamelStream *stream);
 	gint       (*reset)      (CamelStream *stream);
+};
 
-} CamelStreamClass;
-
-/* Standard Camel function */
-CamelType camel_stream_get_type (void);
+GType camel_stream_get_type (void);
 
 /* public methods */
 gssize    camel_stream_read       (CamelStream *stream, gchar *buffer, gsize n);
diff --git a/camel/camel-string-utils.h b/camel/camel-string-utils.h
index 10274ea..c32c4bd 100644
--- a/camel/camel-string-utils.h
+++ b/camel/camel-string-utils.h
@@ -20,8 +20,12 @@
  *
  */
 
-#ifndef __CAMEL_STRING_UTILS_H__
-#define __CAMEL_STRING_UTILS_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_STRING_UTILS_H
+#define CAMEL_STRING_UTILS_H
 
 #include <glib.h>
 
@@ -45,4 +49,4 @@ const gchar * camel_pstring_peek (const gchar *str);
 
 G_END_DECLS
 
-#endif /* __CAMEL_STRING_UTILS_H__ */
+#endif /* CAMEL_STRING_UTILS_H */
diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c
index 72979e7..e0f649e 100644
--- a/camel/camel-tcp-stream-raw.c
+++ b/camel/camel-tcp-stream-raw.c
@@ -50,80 +50,7 @@
 #define ETIMEDOUT EAGAIN
 #endif
 
-static CamelTcpStreamClass *parent_class = NULL;
-
-/* Returns the class for a CamelTcpStreamRaw */
-#define CTSR_CLASS(so) CAMEL_TCP_STREAM_RAW_CLASS (CAMEL_OBJECT_GET_CLASS (so))
-
-static gssize stream_read (CamelStream *stream, gchar *buffer, gsize n);
-static gssize stream_write (CamelStream *stream, const gchar *buffer, gsize n);
-static gint stream_flush  (CamelStream *stream);
-static gint stream_close  (CamelStream *stream);
-
-static gint stream_connect (CamelTcpStream *stream, struct addrinfo *host);
-static gint stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data);
-static gint stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data);
-static struct sockaddr *stream_get_local_address (CamelTcpStream *stream, socklen_t *len);
-static struct sockaddr *stream_get_remote_address (CamelTcpStream *stream, socklen_t *len);
-
-static void
-camel_tcp_stream_raw_class_init (CamelTcpStreamRawClass *camel_tcp_stream_raw_class)
-{
-	CamelTcpStreamClass *camel_tcp_stream_class =
-		CAMEL_TCP_STREAM_CLASS (camel_tcp_stream_raw_class);
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_tcp_stream_raw_class);
-
-	parent_class = CAMEL_TCP_STREAM_CLASS (camel_type_get_global_classfuncs (camel_tcp_stream_get_type ()));
-
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->close = stream_close;
-
-	camel_tcp_stream_class->connect = stream_connect;
-	camel_tcp_stream_class->getsockopt = stream_getsockopt;
-	camel_tcp_stream_class->setsockopt  = stream_setsockopt;
-	camel_tcp_stream_class->get_local_address  = stream_get_local_address;
-	camel_tcp_stream_class->get_remote_address = stream_get_remote_address;
-}
-
-static void
-camel_tcp_stream_raw_init (gpointer object, gpointer klass)
-{
-	CamelTcpStreamRaw *stream = CAMEL_TCP_STREAM_RAW (object);
-
-	stream->sockfd = -1;
-}
-
-static void
-camel_tcp_stream_raw_finalize (CamelObject *object)
-{
-	CamelTcpStreamRaw *stream = CAMEL_TCP_STREAM_RAW (object);
-
-	if (stream->sockfd != -1)
-		SOCKET_CLOSE (stream->sockfd);
-}
-
-CamelType
-camel_tcp_stream_raw_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_tcp_stream_get_type (),
-					    "CamelTcpStreamRaw",
-					    sizeof (CamelTcpStreamRaw),
-					    sizeof (CamelTcpStreamRawClass),
-					    (CamelObjectClassInitFunc) camel_tcp_stream_raw_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_tcp_stream_raw_init,
-					    (CamelObjectFinalizeFunc) camel_tcp_stream_raw_finalize);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 #ifdef SIMULATE_FLAKY_NETWORK
 static gssize
@@ -226,53 +153,45 @@ flaky_tcp_read (gint fd, gchar *buffer, gsize buflen)
 
 #endif /* SIMULATE_FLAKY_NETWORK */
 
-/**
- * camel_tcp_stream_raw_new:
- *
- * Create a new #CamelTcpStreamRaw object.
- *
- * Returns: a new #CamelTcpStream object
- **/
-CamelStream *
-camel_tcp_stream_raw_new (void)
-{
-	CamelTcpStreamRaw *stream;
-
-	stream = CAMEL_TCP_STREAM_RAW (camel_object_new (camel_tcp_stream_raw_get_type ()));
-
-	return CAMEL_STREAM (stream);
-}
-
-static gssize
-stream_read (CamelStream *stream, gchar *buffer, gsize n)
-{
-	CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
-
-	return camel_read_socket (raw->sockfd, buffer, n);
-}
-
-static gssize
-stream_write (CamelStream *stream, const gchar *buffer, gsize n)
-{
-	CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
-
-	return camel_write_socket (raw->sockfd, buffer, n);
-}
-
 static gint
-stream_flush (CamelStream *stream)
+get_sockopt_level (const CamelSockOptData *data)
 {
-	return 0;
+	switch (data->option) {
+	case CAMEL_SOCKOPT_MAXSEGMENT:
+	case CAMEL_SOCKOPT_NODELAY:
+		return IPPROTO_TCP;
+	default:
+		return SOL_SOCKET;
+	}
 }
 
 static gint
-stream_close (CamelStream *stream)
+get_sockopt_optname (const CamelSockOptData *data)
 {
-	if (SOCKET_CLOSE (((CamelTcpStreamRaw *)stream)->sockfd) == -1)
+	switch (data->option) {
+#ifdef TCP_MAXSEG
+	case CAMEL_SOCKOPT_MAXSEGMENT:
+		return TCP_MAXSEG;
+#endif
+	case CAMEL_SOCKOPT_NODELAY:
+		return TCP_NODELAY;
+	case CAMEL_SOCKOPT_BROADCAST:
+		return SO_BROADCAST;
+	case CAMEL_SOCKOPT_KEEPALIVE:
+		return SO_KEEPALIVE;
+	case CAMEL_SOCKOPT_LINGER:
+		return SO_LINGER;
+	case CAMEL_SOCKOPT_RECVBUFFERSIZE:
+		return SO_RCVBUF;
+	case CAMEL_SOCKOPT_SENDBUFFERSIZE:
+		return SO_SNDBUF;
+	case CAMEL_SOCKOPT_REUSEADDR:
+		return SO_REUSEADDR;
+	case CAMEL_SOCKOPT_IPTYPEOFSERVICE:
+		return SO_TYPE;
+	default:
 		return -1;
-
-	((CamelTcpStreamRaw *)stream)->sockfd = -1;
-	return 0;
+	}
 }
 
 /* this is a 'cancellable' connect, cancellable from camel_operation_cancel etc */
@@ -400,67 +319,76 @@ socket_connect(struct addrinfo *h)
 	return fd;
 }
 
-static gint
-stream_connect (CamelTcpStream *stream, struct addrinfo *host)
+static void
+tcp_stream_raw_finalize (GObject *object)
 {
-	CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+	CamelTcpStreamRaw *stream = CAMEL_TCP_STREAM_RAW (object);
 
-	g_return_val_if_fail (host != NULL, -1);
+	if (stream->sockfd != -1)
+		SOCKET_CLOSE (stream->sockfd);
 
-	while (host) {
-		raw->sockfd = socket_connect(host);
-		if (raw->sockfd != -1)
-			return 0;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
 
-		host = host->ai_next;
-	}
+static gssize
+tcp_stream_raw_read (CamelStream *stream,
+                     gchar *buffer,
+                     gsize n)
+{
+	CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
 
-	return -1;
+	return camel_read_socket (raw->sockfd, buffer, n);
+}
+
+static gssize
+tcp_stream_raw_write (CamelStream *stream,
+                      const gchar *buffer,
+                      gsize n)
+{
+	CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+
+	return camel_write_socket (raw->sockfd, buffer, n);
 }
 
 static gint
-get_sockopt_level (const CamelSockOptData *data)
+tcp_stream_raw_flush (CamelStream *stream)
 {
-	switch (data->option) {
-	case CAMEL_SOCKOPT_MAXSEGMENT:
-	case CAMEL_SOCKOPT_NODELAY:
-		return IPPROTO_TCP;
-	default:
-		return SOL_SOCKET;
-	}
+	return 0;
 }
 
 static gint
-get_sockopt_optname (const CamelSockOptData *data)
+tcp_stream_raw_close (CamelStream *stream)
 {
-	switch (data->option) {
-#ifdef TCP_MAXSEG
-	case CAMEL_SOCKOPT_MAXSEGMENT:
-		return TCP_MAXSEG;
-#endif
-	case CAMEL_SOCKOPT_NODELAY:
-		return TCP_NODELAY;
-	case CAMEL_SOCKOPT_BROADCAST:
-		return SO_BROADCAST;
-	case CAMEL_SOCKOPT_KEEPALIVE:
-		return SO_KEEPALIVE;
-	case CAMEL_SOCKOPT_LINGER:
-		return SO_LINGER;
-	case CAMEL_SOCKOPT_RECVBUFFERSIZE:
-		return SO_RCVBUF;
-	case CAMEL_SOCKOPT_SENDBUFFERSIZE:
-		return SO_SNDBUF;
-	case CAMEL_SOCKOPT_REUSEADDR:
-		return SO_REUSEADDR;
-	case CAMEL_SOCKOPT_IPTYPEOFSERVICE:
-		return SO_TYPE;
-	default:
+	if (SOCKET_CLOSE (((CamelTcpStreamRaw *)stream)->sockfd) == -1)
 		return -1;
+
+	((CamelTcpStreamRaw *)stream)->sockfd = -1;
+	return 0;
+}
+
+static gint
+tcp_stream_raw_connect (CamelTcpStream *stream,
+                        struct addrinfo *host)
+{
+	CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+
+	g_return_val_if_fail (host != NULL, -1);
+
+	while (host) {
+		raw->sockfd = socket_connect(host);
+		if (raw->sockfd != -1)
+			return 0;
+
+		host = host->ai_next;
 	}
+
+	return -1;
 }
 
 static gint
-stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
+tcp_stream_raw_getsockopt (CamelTcpStream *stream,
+                           CamelSockOptData *data)
 {
 	gint optname, optlen;
 
@@ -490,7 +418,8 @@ stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
 }
 
 static gint
-stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
+tcp_stream_raw_setsockopt (CamelTcpStream *stream,
+                           const CamelSockOptData *data)
 {
 	gint optname;
 
@@ -527,7 +456,8 @@ stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
 }
 
 static struct sockaddr *
-stream_get_local_address (CamelTcpStream *stream, socklen_t *len)
+tcp_stream_raw_get_local_address (CamelTcpStream *stream,
+                                  socklen_t *len)
 {
 #ifdef ENABLE_IPv6
 	struct sockaddr_in6 sin;
@@ -547,7 +477,7 @@ stream_get_local_address (CamelTcpStream *stream, socklen_t *len)
 }
 
 static struct sockaddr *
-stream_get_remote_address (CamelTcpStream *stream, socklen_t *len)
+tcp_stream_raw_get_remote_address (CamelTcpStream *stream, socklen_t *len)
 {
 #ifdef ENABLE_IPv6
 	struct sockaddr_in6 sin;
@@ -565,3 +495,66 @@ stream_get_remote_address (CamelTcpStream *stream, socklen_t *len)
 
 	return saddr;
 }
+
+static void
+tcp_stream_raw_class_init (CamelTcpStreamRawClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+	CamelTcpStreamClass *tcp_stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = tcp_stream_raw_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = tcp_stream_raw_read;
+	stream_class->write = tcp_stream_raw_write;
+	stream_class->flush = tcp_stream_raw_flush;
+	stream_class->close = tcp_stream_raw_close;
+
+	tcp_stream_class = CAMEL_TCP_STREAM_CLASS (class);
+	tcp_stream_class->connect = tcp_stream_raw_connect;
+	tcp_stream_class->getsockopt = tcp_stream_raw_getsockopt;
+	tcp_stream_class->setsockopt = tcp_stream_raw_setsockopt;
+	tcp_stream_class->get_local_address = tcp_stream_raw_get_local_address;
+	tcp_stream_class->get_remote_address = tcp_stream_raw_get_remote_address;
+}
+
+static void
+tcp_stream_raw_init (CamelTcpStreamRaw *stream)
+{
+	stream->sockfd = -1;
+}
+
+GType
+camel_tcp_stream_raw_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_TCP_STREAM,
+			"CamelTcpStreamRaw",
+			sizeof (CamelTcpStreamRawClass),
+			(GClassInitFunc) tcp_stream_raw_class_init,
+			sizeof (CamelTcpStreamRaw),
+			(GInstanceInitFunc) tcp_stream_raw_init,
+			0);
+
+	return type;
+}
+
+/**
+ * camel_tcp_stream_raw_new:
+ *
+ * Create a new #CamelTcpStreamRaw object.
+ *
+ * Returns: a new #CamelTcpStream object
+ **/
+CamelStream *
+camel_tcp_stream_raw_new (void)
+{
+	return g_object_new (CAMEL_TYPE_TCP_STREAM_RAW, NULL);
+}
diff --git a/camel/camel-tcp-stream-raw.h b/camel/camel-tcp-stream-raw.h
index ebf13fb..435d5fe 100644
--- a/camel/camel-tcp-stream-raw.h
+++ b/camel/camel-tcp-stream-raw.h
@@ -20,21 +20,41 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_TCP_STREAM_RAW_H
 #define CAMEL_TCP_STREAM_RAW_H
 
 #include <camel/camel-tcp-stream.h>
 
-#define CAMEL_TCP_STREAM_RAW_TYPE     (camel_tcp_stream_raw_get_type ())
-#define CAMEL_TCP_STREAM_RAW(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_TCP_STREAM_RAW_TYPE, CamelTcpStreamRaw))
-#define CAMEL_TCP_STREAM_RAW_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TCP_STREAM_RAW_TYPE, CamelTcpStreamRawClass))
-#define CAMEL_IS_TCP_STREAM_RAW(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TCP_STREAM_RAW_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_TCP_STREAM_RAW \
+	(camel_tcp_stream_raw_get_type ())
+#define CAMEL_TCP_STREAM_RAW(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TCP_STREAM_RAW, CamelTcpStreamRaw))
+#define CAMEL_TCP_STREAM_RAW_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TCP_STREAM_RAW, CamelTcpStreamRawClass))
+#define CAMEL_IS_TCP_STREAM_RAW(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TCP_STREAM_RAW))
+#define CAMEL_IS_TCP_STREAM_RAW_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TCP_STREAM_RAW))
+#define CAMEL_TCP_STREAM_RAW_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TCP_STREAM_RAW, CAmelTcpStreamRawClass))
 
 G_BEGIN_DECLS
 
-struct _CamelTcpStreamRaw
-{
-	CamelTcpStream parent_object;
+typedef struct _CamelTcpStreamRaw CamelTcpStreamRaw;
+typedef struct _CamelTcpStreamRawClass CamelTcpStreamRawClass;
+
+struct _CamelTcpStreamRaw {
+	CamelTcpStream parent;
 
 	gint sockfd;
 #ifdef G_OS_WIN32
@@ -42,15 +62,11 @@ struct _CamelTcpStreamRaw
 #endif
 };
 
-typedef struct {
+struct _CamelTcpStreamRawClass {
 	CamelTcpStreamClass parent_class;
+};
 
-	/* virtual functions */
-
-} CamelTcpStreamRawClass;
-
-/* Standard Camel function */
-CamelType camel_tcp_stream_raw_get_type (void);
+GType camel_tcp_stream_raw_get_type (void);
 
 /* public methods */
 CamelStream *camel_tcp_stream_raw_new (void);
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c
index e2af703..8155cbe 100644
--- a/camel/camel-tcp-stream-ssl.c
+++ b/camel/camel-tcp-stream-ssl.c
@@ -49,7 +49,6 @@
 #include <certdb.h>
 #include <pk11func.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -64,10 +63,11 @@
 #define IO_TIMEOUT (PR_TicksPerSecond() * 4 * 60)
 #define CONNECT_TIMEOUT (PR_TicksPerSecond () * 4 * 60)
 
-static CamelTcpStreamClass *parent_class = NULL;
+#define CAMEL_TCP_STREAM_SSL_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_TCP_STREAM_SSL, CamelTcpStreamSSLPrivate))
 
-/* Returns the class for a CamelTcpStreamSSL */
-#define CTSS_CLASS(so) CAMEL_TCP_STREAM_SSL_CLASS (CAMEL_OBJECT_GET_CLASS (so))
+static gpointer parent_class;
 
 static gssize stream_read (CamelStream *stream, gchar *buffer, gsize n);
 static gssize stream_write (CamelStream *stream, const gchar *buffer, gsize n);
@@ -92,69 +92,87 @@ struct _CamelTcpStreamSSLPrivate {
 };
 
 static void
-camel_tcp_stream_ssl_class_init (CamelTcpStreamSSLClass *camel_tcp_stream_ssl_class)
+tcp_stream_ssl_dispose (GObject *object)
 {
-	CamelTcpStreamClass *camel_tcp_stream_class =
-		CAMEL_TCP_STREAM_CLASS (camel_tcp_stream_ssl_class);
-	CamelStreamClass *camel_stream_class =
-		CAMEL_STREAM_CLASS (camel_tcp_stream_ssl_class);
-
-	parent_class = CAMEL_TCP_STREAM_CLASS (camel_type_get_global_classfuncs (camel_tcp_stream_get_type ()));
-
-	/* virtual method overload */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->close = stream_close;
-
-	camel_tcp_stream_class->connect = stream_connect;
-	camel_tcp_stream_class->getsockopt = stream_getsockopt;
-	camel_tcp_stream_class->setsockopt = stream_setsockopt;
-	camel_tcp_stream_class->get_local_address  = stream_get_local_address;
-	camel_tcp_stream_class->get_remote_address = stream_get_remote_address;
-}
+	CamelTcpStreamSSLPrivate *priv;
 
-static void
-camel_tcp_stream_ssl_init (gpointer object, gpointer klass)
-{
-	CamelTcpStreamSSL *stream = CAMEL_TCP_STREAM_SSL (object);
+	priv = CAMEL_TCP_STREAM_SSL_GET_PRIVATE (object);
 
-	stream->priv = g_new0 (struct _CamelTcpStreamSSLPrivate, 1);
+	if (priv->session != NULL) {
+		g_object_unref (priv->session);
+		priv->session = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_tcp_stream_ssl_finalize (CamelObject *object)
+tcp_stream_ssl_finalize (GObject *object)
 {
-	CamelTcpStreamSSL *stream = CAMEL_TCP_STREAM_SSL (object);
+	CamelTcpStreamSSLPrivate *priv;
+
+	priv = CAMEL_TCP_STREAM_SSL_GET_PRIVATE (object);
 
-	if (stream->priv->sockfd != NULL) {
-		PR_Shutdown (stream->priv->sockfd, PR_SHUTDOWN_BOTH);
-		PR_Close (stream->priv->sockfd);
+	if (priv->sockfd != NULL) {
+		PR_Shutdown (priv->sockfd, PR_SHUTDOWN_BOTH);
+		PR_Close (priv->sockfd);
 	}
 
-	if (stream->priv->session)
-		camel_object_unref(stream->priv->session);
+	g_free (priv->expected_host);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
 
-	g_free (stream->priv->expected_host);
+static void
+tcp_stream_ssl_class_init (CamelTcpStreamSSLClass *class)
+{
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+	CamelTcpStreamClass *tcp_stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelTcpStreamSSLPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = tcp_stream_ssl_dispose;
+	object_class->finalize = tcp_stream_ssl_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_read;
+	stream_class->write = stream_write;
+	stream_class->flush = stream_flush;
+	stream_class->close = stream_close;
+
+	tcp_stream_class = CAMEL_TCP_STREAM_CLASS (class);
+	tcp_stream_class->connect = stream_connect;
+	tcp_stream_class->getsockopt = stream_getsockopt;
+	tcp_stream_class->setsockopt = stream_setsockopt;
+	tcp_stream_class->get_local_address  = stream_get_local_address;
+	tcp_stream_class->get_remote_address = stream_get_remote_address;
+}
 
-	g_free (stream->priv);
+static void
+tcp_stream_ssl_init (CamelTcpStreamSSL *stream)
+{
+	stream->priv = CAMEL_TCP_STREAM_SSL_GET_PRIVATE (stream);
 }
 
-CamelType
+GType
 camel_tcp_stream_ssl_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_tcp_stream_get_type (),
-					    "CamelTcpStreamSSL",
-					    sizeof (CamelTcpStreamSSL),
-					    sizeof (CamelTcpStreamSSLClass),
-					    (CamelObjectClassInitFunc) camel_tcp_stream_ssl_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_tcp_stream_ssl_init,
-					    (CamelObjectFinalizeFunc) camel_tcp_stream_ssl_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_TCP_STREAM,
+			"CamelTcpStreamSSL",
+			sizeof (CamelTcpStreamSSLClass),
+			(GClassInitFunc) tcp_stream_ssl_class_init,
+			sizeof (CamelTcpStreamSSL),
+			(GInstanceInitFunc) tcp_stream_ssl_init,
+			0);
 
 	return type;
 }
@@ -181,10 +199,9 @@ camel_tcp_stream_ssl_new (CamelSession *session, const gchar *expected_host, gui
 
 	g_assert(CAMEL_IS_SESSION(session));
 
-	stream = CAMEL_TCP_STREAM_SSL (camel_object_new (camel_tcp_stream_ssl_get_type ()));
+	stream = g_object_new (CAMEL_TYPE_TCP_STREAM_SSL, NULL);
 
-	stream->priv->session = session;
-	camel_object_ref(session);
+	stream->priv->session = g_object_ref (session);
 	stream->priv->expected_host = g_strdup (expected_host);
 	stream->priv->ssl_mode = TRUE;
 	stream->priv->flags = flags;
@@ -214,10 +231,9 @@ camel_tcp_stream_ssl_new_raw (CamelSession *session, const gchar *expected_host,
 
 	g_assert(CAMEL_IS_SESSION(session));
 
-	stream = CAMEL_TCP_STREAM_SSL (camel_object_new (camel_tcp_stream_ssl_get_type ()));
+	stream = g_object_new (CAMEL_TYPE_TCP_STREAM_SSL, NULL);
 
-	stream->priv->session = session;
-	camel_object_ref(session);
+	stream->priv->session = g_object_ref (session);
 	stream->priv->expected_host = g_strdup (expected_host);
 	stream->priv->ssl_mode = FALSE;
 	stream->priv->flags = flags;
@@ -802,7 +818,7 @@ camel_certdb_nss_cert_set(CamelCertDB *certdb, CamelCert *ccert, CERTCertificate
 			g_unlink (path);
 		}
 		camel_stream_close (stream);
-		camel_object_unref (stream);
+		g_object_unref (stream);
 	} else {
 		g_warning ("Could not save cert: %s: %s", path, g_strerror (errno));
 	}
@@ -894,7 +910,7 @@ ssl_bad_cert (gpointer data, PRFileDesc *sockfd)
 	}
 
 	camel_certdb_cert_unref(certdb, ccert);
-	camel_object_unref(certdb);
+	g_object_unref (certdb);
 
 	return accept ? SECSuccess : SECFailure;
 
diff --git a/camel/camel-tcp-stream-ssl.h b/camel/camel-tcp-stream-ssl.h
index d8f5861..88b3a1e 100644
--- a/camel/camel-tcp-stream-ssl.h
+++ b/camel/camel-tcp-stream-ssl.h
@@ -20,15 +20,33 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_TCP_STREAM_SSL_H
 #define CAMEL_TCP_STREAM_SSL_H
 
 #include <camel/camel-tcp-stream.h>
 
-#define CAMEL_TCP_STREAM_SSL_TYPE     (camel_tcp_stream_ssl_get_type ())
-#define CAMEL_TCP_STREAM_SSL(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_TCP_STREAM_SSL_TYPE, CamelTcpStreamSSL))
-#define CAMEL_TCP_STREAM_SSL_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TCP_STREAM_SSL_TYPE, CamelTcpStreamSSLClass))
-#define CAMEL_IS_TCP_STREAM_SSL(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TCP_STREAM_SSL_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_TCP_STREAM_SSL \
+	(camel_tcp_stream_ssl_get_type ())
+#define CAMEL_TCP_STREAM_SSL(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TCP_STREAM_SSL, CamelTcpStreamSSL))
+#define CAMEL_TCP_STREAM_SSL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TCP_STREAM_SSL, CamelTcpStreamSSLClass))
+#define CAMEL_IS_TCP_STREAM_SSL(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TCP_STREAM_SSL))
+#define CAMEL_IS_TCP_STREAM_SSL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TCP_STREAM_SSL))
+#define CAMEL_TCP_STREAM_SSL_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TCP_STREAM_SSL, CamelTcpStreamSSLClass))
 
 #define CAMEL_TCP_STREAM_SSL_ENABLE_SSL2   (1 << 0)
 #define CAMEL_TCP_STREAM_SSL_ENABLE_SSL3   (1 << 1)
@@ -38,21 +56,20 @@ G_BEGIN_DECLS
 
 struct _CamelSession;
 
-struct _CamelTcpStreamSSL {
-	CamelTcpStream parent_object;
+typedef struct _CamelTcpStreamSSL CamelTcpStreamSSL;
+typedef struct _CamelTcpStreamSSLClass CamelTcpStreamSSLClass;
+typedef struct _CamelTcpStreamSSLPrivate CamelTcpStreamSSLPrivate;
 
-	struct _CamelTcpStreamSSLPrivate *priv;
+struct _CamelTcpStreamSSL {
+	CamelTcpStream parent;
+	CamelTcpStreamSSLPrivate *priv;
 };
 
-typedef struct {
+struct _CamelTcpStreamSSLClass {
 	CamelTcpStreamClass parent_class;
+};
 
-	/* virtual functions */
-
-} CamelTcpStreamSSLClass;
-
-/* Standard Camel function */
-CamelType camel_tcp_stream_ssl_get_type (void);
+GType camel_tcp_stream_ssl_get_type (void);
 
 /* public methods */
 CamelStream *camel_tcp_stream_ssl_new (struct _CamelSession *session, const gchar *expected_host, guint32 flags);
diff --git a/camel/camel-tcp-stream.c b/camel/camel-tcp-stream.c
index acc817b..a6c726d 100644
--- a/camel/camel-tcp-stream.c
+++ b/camel/camel-tcp-stream.c
@@ -30,64 +30,32 @@
 
 #define w(x)
 
-static CamelStreamClass *parent_class = NULL;
-
-/* Returns the class for a CamelTcpStream */
-#define CTS_CLASS(so) CAMEL_TCP_STREAM_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-static gint tcp_connect    (CamelTcpStream *stream, struct addrinfo *host);
-static gint tcp_getsockopt (CamelTcpStream *stream, CamelSockOptData *data);
-static gint tcp_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data);
-static struct sockaddr *tcp_get_local_address (CamelTcpStream *stream, socklen_t *len);
-static struct sockaddr *tcp_get_remote_address (CamelTcpStream *stream, socklen_t *len);
+static gpointer parent_class;
 
 static void
-camel_tcp_stream_class_init (CamelTcpStreamClass *camel_tcp_stream_class)
+tcp_stream_class_init (CamelTcpStreamClass *class)
 {
-	/*CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_tcp_stream_class);*/
-
-	parent_class = CAMEL_STREAM_CLASS (camel_type_get_global_classfuncs (CAMEL_STREAM_TYPE));
-
-	/* tcp stream methods */
-	camel_tcp_stream_class->connect            = tcp_connect;
-	camel_tcp_stream_class->getsockopt         = tcp_getsockopt;
-	camel_tcp_stream_class->setsockopt         = tcp_setsockopt;
-	camel_tcp_stream_class->get_local_address  = tcp_get_local_address;
-	camel_tcp_stream_class->get_remote_address = tcp_get_remote_address;
+	parent_class = g_type_class_peek_parent (class);
 }
 
-static void
-camel_tcp_stream_init (gpointer o)
-{
-	;
-}
-
-CamelType
+GType
 camel_tcp_stream_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_STREAM_TYPE,
-					    "CamelTcpStream",
-					    sizeof (CamelTcpStream),
-					    sizeof (CamelTcpStreamClass),
-					    (CamelObjectClassInitFunc) camel_tcp_stream_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_tcp_stream_init,
-					    NULL);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelTcpStream",
+			sizeof (CamelTcpStreamClass),
+			(GClassInitFunc) tcp_stream_class_init,
+			sizeof (CamelTcpStream),
+			(GInstanceInitFunc) NULL,
+			0);
 
 	return type;
 }
 
-static gint
-tcp_connect (CamelTcpStream *stream, struct addrinfo *host)
-{
-	w(g_warning ("CamelTcpStream::connect called on default implementation"));
-	return -1;
-}
-
 /**
  * camel_tcp_stream_connect:
  * @stream: a #CamelTcpStream object
@@ -99,18 +67,17 @@ tcp_connect (CamelTcpStream *stream, struct addrinfo *host)
  * Returns: %0 on success or %-1 on fail
  **/
 gint
-camel_tcp_stream_connect (CamelTcpStream *stream, struct addrinfo *host)
+camel_tcp_stream_connect (CamelTcpStream *stream,
+                          struct addrinfo *host)
 {
+	CamelTcpStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), -1);
 
-	return CTS_CLASS (stream)->connect (stream, host);
-}
+	class = CAMEL_TCP_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->connect != NULL, -1);
 
-static gint
-tcp_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
-{
-	w(g_warning ("CamelTcpStream::getsockopt called on default implementation"));
-	return -1;
+	return class->connect (stream, host);
 }
 
 /**
@@ -123,18 +90,17 @@ tcp_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
  * Returns: %0 on success or %-1 on fail
  **/
 gint
-camel_tcp_stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
+camel_tcp_stream_getsockopt (CamelTcpStream *stream,
+                             CamelSockOptData *data)
 {
+	CamelTcpStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), -1);
 
-	return CTS_CLASS (stream)->getsockopt (stream, data);
-}
+	class = CAMEL_TCP_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->getsockopt != NULL, -1);
 
-static gint
-tcp_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
-{
-	w(g_warning ("CamelTcpStream::setsockopt called on default implementation"));
-	return -1;
+	return class->getsockopt (stream, data);
 }
 
 /**
@@ -147,18 +113,17 @@ tcp_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
  * Returns: %0 on success or %-1 on fail
  **/
 gint
-camel_tcp_stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
+camel_tcp_stream_setsockopt (CamelTcpStream *stream,
+                             const CamelSockOptData *data)
 {
+	CamelTcpStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), -1);
 
-	return CTS_CLASS (stream)->setsockopt (stream, data);
-}
+	class = CAMEL_TCP_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->setsockopt != NULL, -1);
 
-static struct sockaddr *
-tcp_get_local_address (CamelTcpStream *stream, socklen_t *len)
-{
-	w(g_warning ("CamelTcpStream::get_local_address called on default implementation"));
-	return NULL;
+	return class->setsockopt (stream, data);
 }
 
 /**
@@ -172,19 +137,18 @@ tcp_get_local_address (CamelTcpStream *stream, socklen_t *len)
  * #g_free) if the stream is connected, or %NULL if not
  **/
 struct sockaddr *
-camel_tcp_stream_get_local_address (CamelTcpStream *stream, socklen_t *len)
+camel_tcp_stream_get_local_address (CamelTcpStream *stream,
+                                    socklen_t *len)
 {
+	CamelTcpStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), NULL);
-	g_return_val_if_fail(len != NULL, NULL);
+	g_return_val_if_fail (len != NULL, NULL);
 
-	return CTS_CLASS (stream)->get_local_address (stream, len);
-}
+	class = CAMEL_TCP_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->get_local_address != NULL, NULL);
 
-static struct sockaddr *
-tcp_get_remote_address (CamelTcpStream *stream, socklen_t *len)
-{
-	w(g_warning ("CamelTcpStream::get_remote_address called on default implementation"));
-	return NULL;
+	return class->get_local_address (stream, len);
 }
 
 /**
@@ -198,10 +162,16 @@ tcp_get_remote_address (CamelTcpStream *stream, socklen_t *len)
  * #g_free) if the stream is connected, or %NULL if not.
  **/
 struct sockaddr *
-camel_tcp_stream_get_remote_address (CamelTcpStream *stream, socklen_t *len)
+camel_tcp_stream_get_remote_address (CamelTcpStream *stream,
+                                     socklen_t *len)
 {
+	CamelTcpStreamClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), NULL);
-	g_return_val_if_fail(len != NULL, NULL);
+	g_return_val_if_fail (len != NULL, NULL);
+
+	class = CAMEL_TCP_STREAM_GET_CLASS (stream);
+	g_return_val_if_fail (class->get_remote_address != NULL, NULL);
 
-	return CTS_CLASS (stream)->get_remote_address (stream, len);
+	return class->get_remote_address (stream, len);
 }
diff --git a/camel/camel-tcp-stream.h b/camel/camel-tcp-stream.h
index 238c0fa..778c61d 100644
--- a/camel/camel-tcp-stream.h
+++ b/camel/camel-tcp-stream.h
@@ -20,11 +20,13 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_TCP_STREAM_H
 #define CAMEL_TCP_STREAM_H
 
-#include <glib.h>
-
 #ifndef G_OS_WIN32
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -39,13 +41,30 @@
 
 #include <camel/camel-stream.h>
 
-#define CAMEL_TCP_STREAM_TYPE     (camel_tcp_stream_get_type ())
-#define CAMEL_TCP_STREAM(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_TCP_STREAM_TYPE, CamelTcpStream))
-#define CAMEL_TCP_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TCP_STREAM_TYPE, CamelTcpStreamClass))
-#define CAMEL_IS_TCP_STREAM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TCP_STREAM_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_TCP_STREAM \
+	(camel_tcp_stream_get_type ())
+#define CAMEL_TCP_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TCP_STREAM, CamelTcpStream))
+#define CAMEL_TCP_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TCP_STREAM, CamelTcpStreamClass))
+#define CAMEL_IS_TCP_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TCP_STREAM))
+#define CAMEL_IS_TCP_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TCP_STREAM))
+#define CAMEL_TCP_STREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TCP_STREAM, CamelTcpStreamClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelTcpStream CamelTcpStream;
+typedef struct _CamelTcpStreamClass CamelTcpStreamClass;
+
 typedef enum {
 	CAMEL_SOCKOPT_NONBLOCKING,     /* nonblocking io */
 	CAMEL_SOCKOPT_LINGER,          /* linger on close if data present */
@@ -91,11 +110,10 @@ typedef struct _CamelSockOptData {
 } CamelSockOptData;
 
 struct _CamelTcpStream {
-	CamelStream parent_object;
-
+	CamelStream parent;
 };
 
-typedef struct {
+struct _CamelTcpStreamClass {
 	CamelStreamClass parent_class;
 
 	/* Virtual methods */
@@ -105,10 +123,9 @@ typedef struct {
 
 	struct sockaddr * (*get_local_address)  (CamelTcpStream *stream, socklen_t *len);
 	struct sockaddr * (*get_remote_address) (CamelTcpStream *stream, socklen_t *len);
-} CamelTcpStreamClass;
+};
 
-/* Standard Camel function */
-CamelType camel_tcp_stream_get_type (void);
+GType camel_tcp_stream_get_type (void);
 
 /* public methods */
 gint         camel_tcp_stream_connect    (CamelTcpStream *stream, struct addrinfo *host);
diff --git a/camel/camel-text-index.c b/camel/camel-text-index.c
index 8b9bb42..8b3ae22 100644
--- a/camel/camel-text-index.c
+++ b/camel/camel-text-index.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>
@@ -47,7 +46,7 @@
 
 #define w(x)
 #define io(x)
-#define d(x) /*(printf("%s(%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
+#define d(x) /*(printf ("%s (%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
 
 /* cursor debug */
 #define c(x)
@@ -55,16 +54,17 @@
 #define CAMEL_TEXT_INDEX_MAX_WORDLEN  (36)
 
 #define CAMEL_TEXT_INDEX_LOCK(kf, lock) \
-	(g_static_rec_mutex_lock(&((CamelTextIndex *)kf)->priv->lock))
+	(g_static_rec_mutex_lock (&((CamelTextIndex *)kf)->priv->lock))
 #define CAMEL_TEXT_INDEX_UNLOCK(kf, lock) \
-	(g_static_rec_mutex_unlock(&((CamelTextIndex *)kf)->priv->lock))
+	(g_static_rec_mutex_unlock (&((CamelTextIndex *)kf)->priv->lock))
 
-static gint text_index_compress_nosync(CamelIndex *idx);
+static gint text_index_compress_nosync (CamelIndex *idx);
 
 /* ********************************************************************** */
 
-/* "private" data, shared between index/cursor/name classes */
-typedef struct _CamelTextIndexNamePrivate CamelTextIndexNamePrivate;
+#define CAMEL_TEXT_INDEX_NAME_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_TEXT_INDEX_NAME, CamelTextIndexNamePrivate))
 
 struct _CamelTextIndexNamePrivate {
 	GString *buffer;
@@ -72,11 +72,13 @@ struct _CamelTextIndexNamePrivate {
 	EMemPool *pool;
 };
 
-CamelTextIndexName *camel_text_index_name_new(CamelTextIndex *idx, const gchar *name, camel_key_t nameid);
+CamelTextIndexName *camel_text_index_name_new (CamelTextIndex *idx, const gchar *name, camel_key_t nameid);
 
 /* ****************************** */
 
-typedef struct _CamelTextIndexCursorPrivate CamelTextIndexCursorPrivate;
+#define CAMEL_TEXT_INDEX_CURSOR_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_TEXT_INDEX_CURSOR, CamelTextIndexCursorPrivate))
 
 struct _CamelTextIndexCursorPrivate {
 	camel_block_t first;
@@ -90,10 +92,13 @@ struct _CamelTextIndexCursorPrivate {
 	gchar *current;
 };
 
-CamelTextIndexCursor *camel_text_index_cursor_new(CamelTextIndex *idx, camel_block_t data);
+CamelTextIndexCursor *camel_text_index_cursor_new (CamelTextIndex *idx, camel_block_t data);
 
 /* ****************************** */
-typedef struct _CamelTextIndexKeyCursorPrivate CamelTextIndexKeyCursorPrivate;
+
+#define CAMEL_TEXT_INDEX_KEY_CURSOR_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR, CamelTextIndexKeyCursorPrivate))
 
 struct _CamelTextIndexKeyCursorPrivate {
 	CamelKeyTable *table;
@@ -104,13 +109,17 @@ struct _CamelTextIndexKeyCursorPrivate {
 	gchar *current;
 };
 
-CamelTextIndexKeyCursor *camel_text_index_key_cursor_new(CamelTextIndex *idx, CamelKeyTable *table);
+CamelTextIndexKeyCursor *camel_text_index_key_cursor_new (CamelTextIndex *idx, CamelKeyTable *table);
 
 /* ********************************************************************** */
 
 #define CAMEL_TEXT_INDEX_VERSION "TEXT.000"
 #define CAMEL_TEXT_INDEX_KEY_VERSION "KEYS.000"
 
+#define CAMEL_TEXT_INDEX_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_TEXT_INDEX, CamelTextIndexPrivate))
+
 struct _CamelTextIndexPrivate {
 	CamelBlockFile *blocks;
 	CamelKeyFile *links;
@@ -157,46 +166,105 @@ struct _CamelTextIndexWord {
 	camel_key_t names[32];
 };
 
-#define CTI_PRIVATE(o) (((CamelTextIndex *)(o))->priv)
-
-#define CI_CLASS(o) ((CamelTextIndexClass *)(((CamelObject *)o)->classfuncs))
-
 /* ********************************************************************** */
 /* CamelTextIndex */
 /* ********************************************************************** */
 
-static CamelObjectClass *camel_text_index_parent;
+static gpointer text_index_parent_class;
+
+static void
+text_index_dispose (GObject *object)
+{
+	CamelTextIndexPrivate *priv;
+
+	priv = CAMEL_TEXT_INDEX_GET_PRIVATE (object);
+
+	/* Only run this the first time. */
+	if (priv->word_index != NULL)
+		camel_index_sync (CAMEL_INDEX (object));
+
+	if (priv->word_index != NULL) {
+		g_object_unref (priv->word_index);
+		priv->word_index = NULL;
+	}
+
+	if (priv->word_hash != NULL) {
+		g_object_unref (priv->word_hash);
+		priv->word_hash = NULL;
+	}
+
+	if (priv->name_index != NULL) {
+		g_object_unref (priv->name_index);
+		priv->name_index = NULL;
+	}
+
+	if (priv->name_hash != NULL) {
+		g_object_unref (priv->name_hash);
+		priv->name_hash = NULL;
+	}
+
+	if (priv->blocks != NULL) {
+		g_object_unref (priv->blocks);
+		priv->blocks = NULL;
+	}
+
+	if (priv->links != NULL) {
+		g_object_unref (priv->links);
+		priv->links = NULL;
+	}
+
+	/* Chain up to parent's dispose () method. */
+	G_OBJECT_CLASS (text_index_parent_class)->dispose (object);
+}
+
+static void
+text_index_finalize (GObject *object)
+{
+	CamelTextIndexPrivate *priv;
+
+	priv = CAMEL_TEXT_INDEX_GET_PRIVATE (object);
+
+	g_assert (camel_dlist_empty (&priv->word_cache));
+	g_assert (g_hash_table_size (priv->words) == 0);
+
+	g_hash_table_destroy (priv->words);
+
+	g_static_rec_mutex_free (&priv->lock);
+
+	/* Chain up to parent's finalize () method. */
+	G_OBJECT_CLASS (text_index_parent_class)->finalize (object);
+}
 
 /* call locked */
 static void
-text_index_add_name_to_word(CamelIndex *idx, const gchar *word, camel_key_t nameid)
+text_index_add_name_to_word (CamelIndex *idx, const gchar *word, camel_key_t nameid)
 {
 	struct _CamelTextIndexWord *w, *wp, *ww;
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	camel_key_t wordid;
 	camel_block_t data;
 	struct _CamelTextIndexRoot *rb = (struct _CamelTextIndexRoot *)p->blocks->root;
 
-	w = g_hash_table_lookup(p->words, word);
+	w = g_hash_table_lookup (p->words, word);
 	if (w == NULL) {
-		wordid = camel_partition_table_lookup(p->word_hash, word);
+		wordid = camel_partition_table_lookup (p->word_hash, word);
 		if (wordid == 0) {
 			data = 0;
-			wordid = camel_key_table_add(p->word_index, word, 0, 0);
+			wordid = camel_key_table_add (p->word_index, word, 0, 0);
 			if (wordid == 0) {
 				g_warning ("Could not create key entry for word '%s': %s\n",
 					   word, g_strerror (errno));
 				return;
 			}
-			if (camel_partition_table_add(p->word_hash, word, wordid) == -1) {
+			if (camel_partition_table_add (p->word_hash, word, wordid) == -1) {
 				g_warning ("Could not create hash entry for word '%s': %s\n",
 					   word, g_strerror (errno));
 				return;
 			}
 			rb->words++;
-			camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+			camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 		} else {
-			data = camel_key_table_lookup(p->word_index, wordid, NULL, NULL);
+			data = camel_key_table_lookup (p->word_index, wordid, NULL, NULL);
 			if (data == 0) {
 				g_warning ("Could not find key entry for word '%s': %s\n",
 					   word, g_strerror (errno));
@@ -204,47 +272,47 @@ text_index_add_name_to_word(CamelIndex *idx, const gchar *word, camel_key_t name
 			}
 		}
 
-		w = g_malloc0(sizeof(*w));
-		w->word = g_strdup(word);
+		w = g_malloc0 (sizeof (*w));
+		w->word = g_strdup (word);
 		w->wordid = wordid;
 		w->used = 1;
 		w->data = data;
 
 		w->names[0] = nameid;
-		g_hash_table_insert(p->words, w->word, w);
-		camel_dlist_addhead(&p->word_cache, (CamelDListNode *)w);
+		g_hash_table_insert (p->words, w->word, w);
+		camel_dlist_addhead (&p->word_cache, (CamelDListNode *)w);
 		p->word_cache_count++;
 		ww = (struct _CamelTextIndexWord *)p->word_cache.tailpred;
 		wp = ww->prev;
 		while (wp && p->word_cache_count > p->word_cache_limit) {
-			io(printf("writing key file entry '%s' [%x]\n", ww->word, ww->data));
-			if (camel_key_file_write(p->links, &ww->data, ww->used, ww->names) != -1) {
-				io(printf("  new data [%x]\n", ww->data));
+			io (printf ("writing key file entry '%s' [%x]\n", ww->word, ww->data));
+			if (camel_key_file_write (p->links, &ww->data, ww->used, ww->names) != -1) {
+				io (printf ("  new data [%x]\n", ww->data));
 				rb->keys++;
-				camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+				camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 				/* if this call fails - we still point to the old data - not fatal */
-				camel_key_table_set_data(p->word_index, ww->wordid, ww->data);
-				camel_dlist_remove((CamelDListNode *)ww);
-				g_hash_table_remove(p->words, ww->word);
-				g_free(ww->word);
-				g_free(ww);
+				camel_key_table_set_data (p->word_index, ww->wordid, ww->data);
+				camel_dlist_remove ((CamelDListNode *)ww);
+				g_hash_table_remove (p->words, ww->word);
+				g_free (ww->word);
+				g_free (ww);
 				p->word_cache_count--;
 			}
 			ww = wp;
 			wp = wp->prev;
 		}
 	} else {
-		camel_dlist_remove((CamelDListNode *)w);
-		camel_dlist_addhead(&p->word_cache, (CamelDListNode *)w);
+		camel_dlist_remove ((CamelDListNode *)w);
+		camel_dlist_addhead (&p->word_cache, (CamelDListNode *)w);
 		w->names[w->used] = nameid;
 		w->used++;
 		if (w->used == G_N_ELEMENTS (w->names)) {
-			io(printf("writing key file entry '%s' [%x]\n", w->word, w->data));
-			if (camel_key_file_write(p->links, &w->data, w->used, w->names) != -1) {
+			io (printf ("writing key file entry '%s' [%x]\n", w->word, w->data));
+			if (camel_key_file_write (p->links, &w->data, w->used, w->names) != -1) {
 				rb->keys++;
-				camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+				camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 				/* if this call fails - we still point to the old data - not fatal */
-				camel_key_table_set_data(p->word_index, w->wordid, w->data);
+				camel_key_table_set_data (p->word_index, w->wordid, w->data);
 			}
 			/* FIXME: what to on error?  lost data? */
 			w->used = 0;
@@ -253,14 +321,14 @@ text_index_add_name_to_word(CamelIndex *idx, const gchar *word, camel_key_t name
 }
 
 static gint
-text_index_sync(CamelIndex *idx)
+text_index_sync (CamelIndex *idx)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	struct _CamelTextIndexWord *ww;
 	struct _CamelTextIndexRoot *rb;
 	gint ret = 0, wfrag, nfrag, work = FALSE;
 
-	d(printf("sync: blocks = %p\n", p->blocks));
+	d (printf ("sync: blocks = %p\n", p->blocks));
 
 	if (p->blocks == NULL || p->links == NULL
 	    || p->word_index == NULL || p->word_hash == NULL
@@ -271,93 +339,93 @@ text_index_sync(CamelIndex *idx)
 
 	/* sync/flush word cache */
 
-	CAMEL_TEXT_INDEX_LOCK(idx, lock);
+	CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
 	/* we sync, bump down the cache limits since we dont need them for reading */
 	p->blocks->block_cache_limit = 128;
 	/* this doesn't really need to be dropped, its only used in updates anyway */
 	p->word_cache_limit = 1024;
 
-	work = !camel_dlist_empty(&p->word_cache);
+	work = !camel_dlist_empty (&p->word_cache);
 
-	while ( (ww = (struct _CamelTextIndexWord *)camel_dlist_remhead(&p->word_cache)) ) {
+	while ( (ww = (struct _CamelTextIndexWord *)camel_dlist_remhead (&p->word_cache)) ) {
 		if (ww->used > 0) {
-			io(printf("writing key file entry '%s' [%x]\n", ww->word, ww->data));
-			if (camel_key_file_write(p->links, &ww->data, ww->used, ww->names) != -1) {
-				io(printf("  new data [%x]\n", ww->data));
+			io (printf ("writing key file entry '%s' [%x]\n", ww->word, ww->data));
+			if (camel_key_file_write (p->links, &ww->data, ww->used, ww->names) != -1) {
+				io (printf ("  new data [%x]\n", ww->data));
 				rb->keys++;
-				camel_block_file_touch_block(p->blocks, p->blocks->root_block);
-				camel_key_table_set_data(p->word_index, ww->wordid, ww->data);
+				camel_block_file_touch_block (p->blocks, p->blocks->root_block);
+				camel_key_table_set_data (p->word_index, ww->wordid, ww->data);
 			} else {
 				ret = -1;
 			}
 			ww->used = 0;
 		}
-		g_hash_table_remove(p->words, ww->word);
-		g_free(ww->word);
-		g_free(ww);
+		g_hash_table_remove (p->words, ww->word);
+		g_free (ww->word);
+		g_free (ww);
 	}
 
-	if (camel_key_table_sync(p->word_index) == -1
-	    || camel_key_table_sync(p->name_index) == -1
-	    || camel_partition_table_sync(p->word_hash) == -1
-	    || camel_partition_table_sync(p->name_hash) == -1)
+	if (camel_key_table_sync (p->word_index) == -1
+	    || camel_key_table_sync (p->name_index) == -1
+	    || camel_partition_table_sync (p->word_hash) == -1
+	    || camel_partition_table_sync (p->name_hash) == -1)
 		ret = -1;
 
 	/* only do the frag/compress check if we did some new writes on this index */
 	wfrag = rb->words ? (((rb->keys - rb->words) * 100)/ rb->words) : 0;
 	nfrag = rb->names ? ((rb->deleted * 100) / rb->names) : 0;
-	d(printf("wfrag = %d, nfrag = %d, work = %s, ret = %d\n", wfrag, nfrag, work?"true":"false", ret));
-	d(printf("  words = %d, keys = %d\n", rb->words, rb->keys));
+	d (printf ("wfrag = %d, nfrag = %d, work = %s, ret = %d\n", wfrag, nfrag, work?"true":"false", ret));
+	d (printf ("  words = %d, keys = %d\n", rb->words, rb->keys));
 
 	if (ret == 0) {
 		if (wfrag > 30 || nfrag > 20)
-			ret = text_index_compress_nosync(idx);
+			ret = text_index_compress_nosync (idx);
 	}
 
-	ret = camel_block_file_sync(p->blocks);
+	ret = camel_block_file_sync (p->blocks);
 
-	CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+	CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 
 	return ret;
 }
 
-static void tmp_name(const gchar *in, gchar *o)
+static void tmp_name (const gchar *in, gchar *o)
 {
 	gchar *s;
 
-	s = strrchr(in, '/');
+	s = strrchr (in, '/');
 	if (s) {
-		memcpy(o, in, s-in+1);
-		memcpy(o+(s-in+1), ".#", 2);
-		strcpy(o+(s-in+3), s+1);
+		memcpy (o, in, s-in+1);
+		memcpy (o+(s-in+1), ".#", 2);
+		strcpy (o+(s-in+3), s+1);
 	} else {
-		sprintf(o, ".#%s", in);
+		sprintf (o, ".#%s", in);
 	}
 }
 
 static gint
-text_index_compress(CamelIndex *idx)
+text_index_compress (CamelIndex *idx)
 {
 	gint ret;
 
-	CAMEL_TEXT_INDEX_LOCK(idx, lock);
+	CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
-	ret = camel_index_sync(idx);
+	ret = camel_index_sync (idx);
 	if (ret != -1)
-		ret = text_index_compress_nosync(idx);
+		ret = text_index_compress_nosync (idx);
 
-	CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+	CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 
 	return ret;
 }
 
 /* Attempt to recover index space by compressing the indices */
 static gint
-text_index_compress_nosync(CamelIndex *idx)
+text_index_compress_nosync (CamelIndex *idx)
 {
 	CamelTextIndex *newidx;
-	struct _CamelTextIndexPrivate *newp, *oldp;
+	CamelTextIndexPrivate *newp, *oldp;
 	camel_key_t oldkeyid, newkeyid;
 	GHashTable *remap;
 	guint deleted;
@@ -370,30 +438,30 @@ text_index_compress_nosync(CamelIndex *idx)
 	camel_key_t *records, newrecords[256];
 	struct _CamelTextIndexRoot *rb;
 
-	i = strlen(idx->path)+16;
-	oldpath = alloca(i);
-	newpath = alloca(i);
-	savepath = alloca(i);
+	i = strlen (idx->path)+16;
+	oldpath = alloca (i);
+	newpath = alloca (i);
+	savepath = alloca (i);
 
-	strcpy(oldpath, idx->path);
-	oldpath[strlen(oldpath)-strlen(".index")] = 0;
+	strcpy (oldpath, idx->path);
+	oldpath[strlen (oldpath)-strlen (".index")] = 0;
 
-	tmp_name(oldpath, newpath);
-	sprintf(savepath, "%s~", oldpath);
+	tmp_name (oldpath, newpath);
+	sprintf (savepath, "%s~", oldpath);
 
-	d(printf("Old index: %s\n", idx->path));
-	d(printf("Old path: %s\n", oldpath));
-	d(printf("New: %s\n", newpath));
-	d(printf("Save: %s\n", savepath));
+	d (printf ("Old index: %s\n", idx->path));
+	d (printf ("Old path: %s\n", oldpath));
+	d (printf ("New: %s\n", newpath));
+	d (printf ("Save: %s\n", savepath));
 
-	newidx = camel_text_index_new(newpath, O_RDWR|O_CREAT);
+	newidx = camel_text_index_new (newpath, O_RDWR|O_CREAT);
 	if (newidx == NULL)
 		return -1;
 
-	newp = CTI_PRIVATE(newidx);
-	oldp = CTI_PRIVATE(idx);
+	newp = CAMEL_TEXT_INDEX_GET_PRIVATE (newidx);
+	oldp = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 
-	CAMEL_TEXT_INDEX_LOCK(idx, lock);
+	CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
 	rb = (struct _CamelTextIndexRoot *)newp->blocks->root;
 
@@ -408,26 +476,26 @@ text_index_compress_nosync(CamelIndex *idx)
 
 	   For each word:
 	   Copy word's data to a new file
-	   Add new word to index(*) (can we just copy blocks?) */
+	   Add new word to index (*) (can we just copy blocks?) */
 
 	/* Copy undeleted names to new index file, creating new indices */
-	io(printf("Copying undeleted names to new file\n"));
-	remap = g_hash_table_new(NULL, NULL);
+	io (printf ("Copying undeleted names to new file\n"));
+	remap = g_hash_table_new (NULL, NULL);
 	oldkeyid = 0;
 	deleted = 0;
-	while ( (oldkeyid = camel_key_table_next(oldp->name_index, oldkeyid, &name, &flags, &data)) ) {
+	while ( (oldkeyid = camel_key_table_next (oldp->name_index, oldkeyid, &name, &flags, &data)) ) {
 		if ((flags&1) == 0) {
-			io(printf("copying name '%s'\n", name));
-			newkeyid = camel_key_table_add(newp->name_index, name, data, flags);
+			io (printf ("copying name '%s'\n", name));
+			newkeyid = camel_key_table_add (newp->name_index, name, data, flags);
 			if (newkeyid == 0)
 				goto fail;
 			rb->names++;
-			camel_partition_table_add(newp->name_hash, name, newkeyid);
-			g_hash_table_insert(remap, GINT_TO_POINTER(oldkeyid), GINT_TO_POINTER(newkeyid));
+			camel_partition_table_add (newp->name_hash, name, newkeyid);
+			g_hash_table_insert (remap, GINT_TO_POINTER (oldkeyid), GINT_TO_POINTER (newkeyid));
 		} else {
-			io(printf("deleted name '%s'\n", name));
+			io (printf ("deleted name '%s'\n", name));
 		}
-		g_free(name);
+		g_free (name);
 		name = NULL;
 		deleted |= flags;
 	}
@@ -436,8 +504,8 @@ text_index_compress_nosync(CamelIndex *idx)
 	/* We re-block the data into 256 entry lots while we're at it, since we only
 	   have to do 1 at a time and its cheap */
 	oldkeyid = 0;
-	while ( (oldkeyid = camel_key_table_next(oldp->word_index, oldkeyid, &name, &flags, &data)) ) {
-		io(printf("copying word '%s'\n", name));
+	while ( (oldkeyid = camel_key_table_next (oldp->word_index, oldkeyid, &name, &flags, &data)) ) {
+		io (printf ("copying word '%s'\n", name));
 		newdata = 0;
 		newcount = 0;
 		if (data) {
@@ -445,153 +513,153 @@ text_index_compress_nosync(CamelIndex *idx)
 			rb->keys++;
 		}
 		while (data) {
-			if (camel_key_file_read(oldp->links, &data, &count, &records) == -1) {
-				io(printf("could not read from old keys at %d for word '%s'\n", (gint)data, name));
+			if (camel_key_file_read (oldp->links, &data, &count, &records) == -1) {
+				io (printf ("could not read from old keys at %d for word '%s'\n", (gint)data, name));
 				goto fail;
 			}
 			for (i=0;i<count;i++) {
-				newkeyid = (camel_key_t)GPOINTER_TO_INT(g_hash_table_lookup(remap, GINT_TO_POINTER(records[i])));
+				newkeyid = (camel_key_t)GPOINTER_TO_INT (g_hash_table_lookup (remap, GINT_TO_POINTER (records[i])));
 				if (newkeyid) {
 					newrecords[newcount++] = newkeyid;
 					if (newcount == G_N_ELEMENTS (newrecords)) {
-						if (camel_key_file_write(newp->links, &newdata, newcount, newrecords) == -1) {
-							g_free(records);
+						if (camel_key_file_write (newp->links, &newdata, newcount, newrecords) == -1) {
+							g_free (records);
 							goto fail;
 						}
 						newcount = 0;
 					}
 				}
 			}
-			g_free(records);
+			g_free (records);
 		}
 
 		if (newcount > 0) {
-			if (camel_key_file_write(newp->links, &newdata, newcount, newrecords) == -1)
+			if (camel_key_file_write (newp->links, &newdata, newcount, newrecords) == -1)
 				goto fail;
 		}
 
 		if (newdata != 0) {
-			newkeyid = camel_key_table_add(newp->word_index, name, newdata, flags);
+			newkeyid = camel_key_table_add (newp->word_index, name, newdata, flags);
 			if (newkeyid == 0)
 				goto fail;
-			camel_partition_table_add(newp->word_hash, name, newkeyid);
+			camel_partition_table_add (newp->word_hash, name, newkeyid);
 		}
-		g_free(name);
+		g_free (name);
 		name = NULL;
 	}
 
-	camel_block_file_touch_block(newp->blocks, newp->blocks->root_block);
+	camel_block_file_touch_block (newp->blocks, newp->blocks->root_block);
 
-	if (camel_index_sync((CamelIndex *)newidx) == -1)
+	if (camel_index_sync ((CamelIndex *)newidx) == -1)
 		goto fail;
 
 	/* Rename underlying files to match */
-	ret = camel_index_rename(idx, savepath);
+	ret = camel_index_rename (idx, savepath);
 	if (ret == -1)
 		goto fail;
 
 	/* If this fails, we'll pick up something during restart? */
-	ret = camel_index_rename((CamelIndex *)newidx, oldpath);
+	ret = camel_index_rename ((CamelIndex *)newidx, oldpath);
 
 #define myswap(a, b) { gpointer tmp = a; a = b; b = tmp; }
 	/* Poke the private data across to the new object */
 	/* And change the fd's over, etc? */
 	/* Yes: This is a hack */
-	myswap(newp->blocks, oldp->blocks);
-	myswap(newp->links, oldp->links);
-	myswap(newp->word_index, oldp->word_index);
-	myswap(newp->word_hash, oldp->word_hash);
-	myswap(newp->name_index, oldp->name_index);
-	myswap(newp->name_hash, oldp->name_hash);
-	myswap(((CamelIndex *)newidx)->path, ((CamelIndex *)idx)->path);
+	myswap (newp->blocks, oldp->blocks);
+	myswap (newp->links, oldp->links);
+	myswap (newp->word_index, oldp->word_index);
+	myswap (newp->word_hash, oldp->word_hash);
+	myswap (newp->name_index, oldp->name_index);
+	myswap (newp->name_hash, oldp->name_hash);
+	myswap (((CamelIndex *)newidx)->path, ((CamelIndex *)idx)->path);
 #undef myswap
 
 	ret = 0;
 fail:
-	CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+	CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 
-	camel_index_delete((CamelIndex *)newidx);
+	camel_index_delete ((CamelIndex *)newidx);
 
-	camel_object_unref((CamelObject *)newidx);
-	g_free(name);
-	g_hash_table_destroy(remap);
+	g_object_unref (newidx);
+	g_free (name);
+	g_hash_table_destroy (remap);
 
 	/* clean up temp files always */
-	sprintf(savepath, "%s~.index", oldpath);
-	g_unlink(savepath);
-	sprintf(newpath, "%s.data", savepath);
-	g_unlink(newpath);
+	sprintf (savepath, "%s~.index", oldpath);
+	g_unlink (savepath);
+	sprintf (newpath, "%s.data", savepath);
+	g_unlink (newpath);
 
 	return ret;
 }
 
 static gint
-text_index_delete(CamelIndex *idx)
+text_index_delete (CamelIndex *idx)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	gint ret = 0;
 
-	if (camel_block_file_delete(p->blocks) == -1)
+	if (camel_block_file_delete (p->blocks) == -1)
 		ret = -1;
-	if (camel_key_file_delete(p->links) == -1)
+	if (camel_key_file_delete (p->links) == -1)
 		ret = -1;
 
 	return ret;
 }
 
 static gint
-text_index_rename(CamelIndex *idx, const gchar *path)
+text_index_rename (CamelIndex *idx, const gchar *path)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	gchar *newlink, *newblock;
 	gint err, ret;
 
-	CAMEL_TEXT_INDEX_LOCK(idx, lock);
+	CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
-	newblock = alloca(strlen(path)+8);
-	sprintf(newblock, "%s.index", path);
-	ret = camel_block_file_rename(p->blocks, newblock);
+	newblock = alloca (strlen (path)+8);
+	sprintf (newblock, "%s.index", path);
+	ret = camel_block_file_rename (p->blocks, newblock);
 	if (ret == -1) {
-		CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+		CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 		return -1;
 	}
 
-	newlink = alloca(strlen(path)+16);
-	sprintf(newlink, "%s.index.data", path);
-	ret = camel_key_file_rename(p->links, newlink);
+	newlink = alloca (strlen (path)+16);
+	sprintf (newlink, "%s.index.data", path);
+	ret = camel_key_file_rename (p->links, newlink);
 	if (ret == -1) {
 		err = errno;
-		camel_block_file_rename(p->blocks, idx->path);
-		CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+		camel_block_file_rename (p->blocks, idx->path);
+		CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 		errno = err;
 		return -1;
 	}
 
-	g_free(idx->path);
-	idx->path = g_strdup(newblock);
+	g_free (idx->path);
+	idx->path = g_strdup (newblock);
 
-	CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+	CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 
 	return 0;
 }
 
 static gint
-text_index_has_name(CamelIndex *idx, const gchar *name)
+text_index_has_name (CamelIndex *idx, const gchar *name)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 
-	return camel_partition_table_lookup(p->name_hash, name) != 0;
+	return camel_partition_table_lookup (p->name_hash, name) != 0;
 }
 
 static CamelIndexName *
-text_index_add_name(CamelIndex *idx, const gchar *name)
+text_index_add_name (CamelIndex *idx, const gchar *name)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	camel_key_t keyid;
 	CamelIndexName *idn;
 	struct _CamelTextIndexRoot *rb = (struct _CamelTextIndexRoot *)p->blocks->root;
 
-	CAMEL_TEXT_INDEX_LOCK(idx, lock);
+	CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
 	/* if we're adding words, up the cache limits a lot */
 	if (p->blocks) {
@@ -600,250 +668,223 @@ text_index_add_name(CamelIndex *idx, const gchar *name)
 	}
 
 	/* If we have it already replace it */
-	keyid = camel_partition_table_lookup(p->name_hash, name);
+	keyid = camel_partition_table_lookup (p->name_hash, name);
 	if (keyid != 0) {
 		/* TODO: We could just update the partition table's
 		   key pointer rather than having to delete it */
 		rb->deleted++;
-		camel_key_table_set_flags(p->name_index, keyid, 1, 1);
-		camel_partition_table_remove(p->name_hash, name);
+		camel_key_table_set_flags (p->name_index, keyid, 1, 1);
+		camel_partition_table_remove (p->name_hash, name);
 	}
 
-	keyid = camel_key_table_add(p->name_index, name, 0, 0);
+	keyid = camel_key_table_add (p->name_index, name, 0, 0);
 	if (keyid != 0) {
-		camel_partition_table_add(p->name_hash, name, keyid);
+		camel_partition_table_add (p->name_hash, name, keyid);
 		rb->names++;
 	}
 
-	camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+	camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 
 	/* TODO: if keyid == 0, we had a failure, we should somehow flag that, but for
 	   now just return a valid object but discard its results, see text_index_write_name */
 
-	CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+	CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 
-	idn = (CamelIndexName *)camel_text_index_name_new((CamelTextIndex *)idx, name, keyid);
+	idn = (CamelIndexName *)camel_text_index_name_new ((CamelTextIndex *)idx, name, keyid);
 
 	return idn;
 }
 
 /* call locked */
 static void
-hash_write_word(gchar *word, gpointer data, CamelIndexName *idn)
+hash_write_word (gchar *word, gpointer data, CamelIndexName *idn)
 {
 	CamelTextIndexName *tin = (CamelTextIndexName *)idn;
 
-	text_index_add_name_to_word(idn->index, word, tin->priv->nameid);
+	text_index_add_name_to_word (idn->index, word, tin->priv->nameid);
 }
 
 static gint
-text_index_write_name(CamelIndex *idx, CamelIndexName *idn)
+text_index_write_name (CamelIndex *idx, CamelIndexName *idn)
 {
 	/* force 'flush' of any outstanding data */
-	camel_index_name_add_buffer(idn, NULL, 0);
+	camel_index_name_add_buffer (idn, NULL, 0);
 
 	/* see text_index_add_name for when this can be 0 */
 	if (((CamelTextIndexName *)idn)->priv->nameid != 0) {
-		CAMEL_TEXT_INDEX_LOCK(idx, lock);
+		CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
-		g_hash_table_foreach(idn->words, (GHFunc)hash_write_word, idn);
+		g_hash_table_foreach (idn->words, (GHFunc)hash_write_word, idn);
 
-		CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+		CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 	}
 
 	return 0;
 }
 
 static CamelIndexCursor *
-text_index_find_name(CamelIndex *idx, const gchar *name)
+text_index_find_name (CamelIndex *idx, const gchar *name)
 {
 	/* what was this for, umm */
 	return NULL;
 }
 
 static void
-text_index_delete_name(CamelIndex *idx, const gchar *name)
+text_index_delete_name (CamelIndex *idx, const gchar *name)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	camel_key_t keyid;
 	struct _CamelTextIndexRoot *rb = (struct _CamelTextIndexRoot *)p->blocks->root;
 
-	d(printf("Delete name: %s\n", name));
+	d (printf ("Delete name: %s\n", name));
 
 	/* probably doesn't really need locking, but oh well */
-	CAMEL_TEXT_INDEX_LOCK(idx, lock);
+	CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
 	/* We just mark the key deleted, and remove it from the hash table */
-	keyid = camel_partition_table_lookup(p->name_hash, name);
+	keyid = camel_partition_table_lookup (p->name_hash, name);
 	if (keyid != 0) {
 		rb->deleted++;
-		camel_block_file_touch_block(p->blocks, p->blocks->root_block);
-		camel_key_table_set_flags(p->name_index, keyid, 1, 1);
-		camel_partition_table_remove(p->name_hash, name);
+		camel_block_file_touch_block (p->blocks, p->blocks->root_block);
+		camel_key_table_set_flags (p->name_index, keyid, 1, 1);
+		camel_partition_table_remove (p->name_hash, name);
 	}
 
-	CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+	CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 }
 
 static CamelIndexCursor *
-text_index_find(CamelIndex *idx, const gchar *word)
+text_index_find (CamelIndex *idx, const gchar *word)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	camel_key_t keyid;
 	camel_block_t data = 0;
 	guint flags;
 	CamelIndexCursor *idc;
 
-	CAMEL_TEXT_INDEX_LOCK(idx, lock);
+	CAMEL_TEXT_INDEX_LOCK (idx, lock);
 
-	keyid = camel_partition_table_lookup(p->word_hash, word);
+	keyid = camel_partition_table_lookup (p->word_hash, word);
 	if (keyid != 0) {
-		data = camel_key_table_lookup(p->word_index, keyid, NULL, &flags);
+		data = camel_key_table_lookup (p->word_index, keyid, NULL, &flags);
 		if (flags & 1)
 			data = 0;
 	}
 
-	CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+	CAMEL_TEXT_INDEX_UNLOCK (idx, lock);
 
-	idc = (CamelIndexCursor *)camel_text_index_cursor_new((CamelTextIndex *)idx, data);
+	idc = (CamelIndexCursor *)camel_text_index_cursor_new ((CamelTextIndex *)idx, data);
 
 	return idc;
 }
 
 static CamelIndexCursor *
-text_index_words(CamelIndex *idx)
+text_index_words (CamelIndex *idx)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 
-	return (CamelIndexCursor *)camel_text_index_key_cursor_new((CamelTextIndex *)idx, p->word_index);
+	return (CamelIndexCursor *)camel_text_index_key_cursor_new ((CamelTextIndex *)idx, p->word_index);
 }
 
 static CamelIndexCursor *
-text_index_names(CamelIndex *idx)
+text_index_names (CamelIndex *idx)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 
-	return (CamelIndexCursor *)camel_text_index_key_cursor_new((CamelTextIndex *)idx, p->name_index);
+	return (CamelIndexCursor *)camel_text_index_key_cursor_new ((CamelTextIndex *)idx, p->name_index);
 }
 
 static void
-camel_text_index_class_init(CamelTextIndexClass *klass)
+text_index_class_init (CamelTextIndexClass *class)
 {
-	CamelIndexClass *iklass = (CamelIndexClass *)klass;
-
-	camel_text_index_parent = CAMEL_OBJECT_CLASS(camel_type_get_global_classfuncs(camel_object_get_type()));
-
-	iklass->sync = text_index_sync;
-	iklass->compress = text_index_compress;
-	iklass->delete = text_index_delete;
-
-	iklass->rename = text_index_rename;
-
-	iklass->has_name = text_index_has_name;
-	iklass->add_name = text_index_add_name;
-	iklass->write_name = text_index_write_name;
-	iklass->find_name = text_index_find_name;
-	iklass->delete_name = text_index_delete_name;
-	iklass->find = text_index_find;
-
-	iklass->words = text_index_words;
-	iklass->names = text_index_names;
+	GObjectClass *object_class;
+	CamelIndexClass *index_class;
+
+	text_index_parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelTextIndexPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = text_index_dispose;
+	object_class->finalize = text_index_finalize;
+
+	index_class = CAMEL_INDEX_CLASS (class);
+	index_class->sync = text_index_sync;
+	index_class->compress = text_index_compress;
+	index_class->delete = text_index_delete;
+	index_class->rename = text_index_rename;
+	index_class->has_name = text_index_has_name;
+	index_class->add_name = text_index_add_name;
+	index_class->write_name = text_index_write_name;
+	index_class->find_name = text_index_find_name;
+	index_class->delete_name = text_index_delete_name;
+	index_class->find = text_index_find;
+	index_class->words = text_index_words;
+	index_class->names = text_index_names;
 }
 
 static void
-camel_text_index_init(CamelTextIndex *idx)
+text_index_init (CamelTextIndex *text_index)
 {
-	struct _CamelTextIndexPrivate *p;
+	text_index->priv = CAMEL_TEXT_INDEX_GET_PRIVATE (text_index);
 
-	p = CTI_PRIVATE(idx) = g_malloc0(sizeof(*p));
+	camel_dlist_init (&text_index->priv->word_cache);
+	text_index->priv->words = g_hash_table_new (g_str_hash, g_str_equal);
+	text_index->priv->word_cache_count = 0;
 
-	camel_dlist_init(&p->word_cache);
-	p->words = g_hash_table_new(g_str_hash, g_str_equal);
-	p->word_cache_count = 0;
-	/* this cache size and the block cache size have been tuned for about the best
-	   with moderate memory usage.  Doubling the memory usage barely affects performance. */
-	p->word_cache_limit = 4096; /* 1024 = 128K */
+	/* This cache size and the block cache size have been tuned for
+	 * about the best with moderate memory usage.  Doubling the memory
+	 * usage barely affects performance. */
+	text_index->priv->word_cache_limit = 4096; /* 1024 = 128K */
 
-	g_static_rec_mutex_init(&p->lock);
+	g_static_rec_mutex_init (&text_index->priv->lock);
 }
 
-static void
-camel_text_index_finalise(CamelTextIndex *idx)
+GType
+camel_text_index_get_type (void)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
-
-	camel_index_sync((CamelIndex *)idx);
-
-	g_assert(camel_dlist_empty(&p->word_cache));
-	g_assert(g_hash_table_size(p->words) == 0);
-
-	g_hash_table_destroy(p->words);
-
-	if (p->word_index)
-		camel_object_unref((CamelObject *)p->word_index);
-	if (p->word_hash)
-		camel_object_unref((CamelObject *)p->word_hash);
-	if (p->name_index)
-		camel_object_unref((CamelObject *)p->name_index);
-	if (p->name_hash)
-		camel_object_unref((CamelObject *)p->name_hash);
-
-	if (p->blocks)
-		camel_object_unref((CamelObject *)p->blocks);
-	if (p->links)
-		camel_object_unref((CamelObject *)p->links);
-
-	g_static_rec_mutex_free(&p->lock);
-
-	g_free(p);
-}
-
-CamelType
-camel_text_index_get_type(void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_index_get_type(), "CamelTextIndex",
-					   sizeof (CamelTextIndex),
-					   sizeof (CamelTextIndexClass),
-					   (CamelObjectClassInitFunc) camel_text_index_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_text_index_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_INDEX,
+			"CamelTextIndex",
+			sizeof (CamelTextIndexClass),
+			(GClassInitFunc) text_index_class_init,
+			sizeof (CamelTextIndex),
+			(GInstanceInitFunc) text_index_init,
+			0);
 
 	return type;
 }
 
 static gchar *
-text_index_normalise(CamelIndex *idx, const gchar *in, gpointer data)
+text_index_normalise (CamelIndex *idx, const gchar *in, gpointer data)
 {
 	gchar *word;
 
 	/* Sigh, this is really expensive */
-	/*g_utf8_normalize(in, strlen(in), G_NORMALIZE_ALL);*/
-	word = g_utf8_strdown(in, -1);
+	/*g_utf8_normalize (in, strlen (in), G_NORMALIZE_ALL);*/
+	word = g_utf8_strdown (in, -1);
 
 	return word;
 }
 
 CamelTextIndex *
-camel_text_index_new(const gchar *path, gint flags)
+camel_text_index_new (const gchar *path, gint flags)
 {
-	CamelTextIndex *idx = (CamelTextIndex *)camel_object_new(camel_text_index_get_type());
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndex *idx = g_object_new (CAMEL_TYPE_TEXT_INDEX, NULL);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	struct _CamelTextIndexRoot *rb;
 	gchar *link;
 	CamelBlock *bl;
 
-	camel_index_construct((CamelIndex *)idx, path, flags);
-	camel_index_set_normalise((CamelIndex *)idx, text_index_normalise, NULL);
+	camel_index_construct ((CamelIndex *)idx, path, flags);
+	camel_index_set_normalise ((CamelIndex *)idx, text_index_normalise, NULL);
 
-	p->blocks = camel_block_file_new(idx->parent.path, flags, CAMEL_TEXT_INDEX_VERSION, CAMEL_BLOCK_SIZE);
-	link = alloca(strlen(idx->parent.path)+7);
-	sprintf(link, "%s.data", idx->parent.path);
-	p->links = camel_key_file_new(link, flags, CAMEL_TEXT_INDEX_KEY_VERSION);
+	p->blocks = camel_block_file_new (idx->parent.path, flags, CAMEL_TEXT_INDEX_VERSION, CAMEL_BLOCK_SIZE);
+	link = alloca (strlen (idx->parent.path)+7);
+	sprintf (link, "%s.data", idx->parent.path);
+	p->links = camel_key_file_new (link, flags, CAMEL_TEXT_INDEX_KEY_VERSION);
 
 	if (p->blocks == NULL || p->links == NULL)
 		goto fail;
@@ -851,121 +892,121 @@ camel_text_index_new(const gchar *path, gint flags)
 	rb = (struct _CamelTextIndexRoot *)p->blocks->root;
 
 	if (rb->word_index_root == 0) {
-		bl = camel_block_file_new_block(p->blocks);
+		bl = camel_block_file_new_block (p->blocks);
 
 		if (bl == NULL)
 			goto fail;
 
 		rb->word_index_root = bl->id;
-		camel_block_file_unref_block(p->blocks, bl);
-		camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+		camel_block_file_unref_block (p->blocks, bl);
+		camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 	}
 
 	if (rb->word_hash_root == 0) {
-		bl = camel_block_file_new_block(p->blocks);
+		bl = camel_block_file_new_block (p->blocks);
 
 		if (bl == NULL)
 			goto fail;
 
 		rb->word_hash_root = bl->id;
-		camel_block_file_unref_block(p->blocks, bl);
-		camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+		camel_block_file_unref_block (p->blocks, bl);
+		camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 	}
 
 	if (rb->name_index_root == 0) {
-		bl = camel_block_file_new_block(p->blocks);
+		bl = camel_block_file_new_block (p->blocks);
 
 		if (bl == NULL)
 			goto fail;
 
 		rb->name_index_root = bl->id;
-		camel_block_file_unref_block(p->blocks, bl);
-		camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+		camel_block_file_unref_block (p->blocks, bl);
+		camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 	}
 
 	if (rb->name_hash_root == 0) {
-		bl = camel_block_file_new_block(p->blocks);
+		bl = camel_block_file_new_block (p->blocks);
 
 		if (bl == NULL)
 			goto fail;
 
 		rb->name_hash_root = bl->id;
-		camel_block_file_unref_block(p->blocks, bl);
-		camel_block_file_touch_block(p->blocks, p->blocks->root_block);
+		camel_block_file_unref_block (p->blocks, bl);
+		camel_block_file_touch_block (p->blocks, p->blocks->root_block);
 	}
 
-	p->word_index = camel_key_table_new(p->blocks, rb->word_index_root);
-	p->word_hash = camel_partition_table_new(p->blocks, rb->word_hash_root);
-	p->name_index = camel_key_table_new(p->blocks, rb->name_index_root);
-	p->name_hash = camel_partition_table_new(p->blocks, rb->name_hash_root);
+	p->word_index = camel_key_table_new (p->blocks, rb->word_index_root);
+	p->word_hash = camel_partition_table_new (p->blocks, rb->word_hash_root);
+	p->name_index = camel_key_table_new (p->blocks, rb->name_index_root);
+	p->name_hash = camel_partition_table_new (p->blocks, rb->name_hash_root);
 
 	if (p->word_index == NULL || p->word_hash == NULL
 	    || p->name_index == NULL || p->name_hash == NULL) {
-		camel_object_unref((CamelObject *)idx);
+		g_object_unref (idx);
 		idx = NULL;
 	}
 
 	return idx;
 
 fail:
-	camel_object_unref((CamelObject *)idx);
+	g_object_unref (idx);
 	return NULL;
 }
 
 /* returns 0 if the index exists, is valid, and synced, -1 otherwise */
 gint
-camel_text_index_check(const gchar *path)
+camel_text_index_check (const gchar *path)
 {
 	gchar *block, *key;
 	CamelBlockFile *blocks;
 	CamelKeyFile *keys;
 
-	block = alloca(strlen(path)+7);
-	sprintf(block, "%s.index", path);
-	blocks = camel_block_file_new(block, O_RDONLY, CAMEL_TEXT_INDEX_VERSION, CAMEL_BLOCK_SIZE);
+	block = alloca (strlen (path)+7);
+	sprintf (block, "%s.index", path);
+	blocks = camel_block_file_new (block, O_RDONLY, CAMEL_TEXT_INDEX_VERSION, CAMEL_BLOCK_SIZE);
 	if (blocks == NULL) {
-		io(printf("Check failed: No block file: %s\n", g_strerror (errno)));
+		io (printf ("Check failed: No block file: %s\n", g_strerror (errno)));
 		return -1;
 	}
-	key = alloca(strlen(path)+12);
-	sprintf(key, "%s.index.data", path);
-	keys = camel_key_file_new(key, O_RDONLY, CAMEL_TEXT_INDEX_KEY_VERSION);
+	key = alloca (strlen (path)+12);
+	sprintf (key, "%s.index.data", path);
+	keys = camel_key_file_new (key, O_RDONLY, CAMEL_TEXT_INDEX_KEY_VERSION);
 	if (keys == NULL) {
-		io(printf("Check failed: No key file: %s\n", g_strerror (errno)));
-		camel_object_unref((CamelObject *)blocks);
+		io (printf ("Check failed: No key file: %s\n", strerror (errno)));
+		g_object_unref (blocks);
 		return -1;
 	}
 
-	camel_object_unref((CamelObject *)keys);
-	camel_object_unref((CamelObject *)blocks);
+	g_object_unref (keys);
+	g_object_unref (blocks);
 
 	return 0;
 }
 
 gint
-camel_text_index_rename(const gchar *old, const gchar *new)
+camel_text_index_rename (const gchar *old, const gchar *new)
 {
 	gchar *oldname, *newname;
 	gint err;
 
 	/* TODO: camel_text_index_rename should find out if we have an active index and use that instead */
 
-	oldname = alloca(strlen(old)+12);
-	newname = alloca(strlen(new)+12);
-	sprintf(oldname, "%s.index", old);
-	sprintf(newname, "%s.index", new);
+	oldname = alloca (strlen (old)+12);
+	newname = alloca (strlen (new)+12);
+	sprintf (oldname, "%s.index", old);
+	sprintf (newname, "%s.index", new);
 
-	if (g_rename(oldname, newname) == -1 && errno != ENOENT)
+	if (g_rename (oldname, newname) == -1 && errno != ENOENT)
 		return -1;
 
-	sprintf(oldname, "%s.index.data", old);
-	sprintf(newname, "%s.index.data", new);
+	sprintf (oldname, "%s.index.data", old);
+	sprintf (newname, "%s.index.data", new);
 
-	if (g_rename(oldname, newname) == -1 && errno != ENOENT) {
+	if (g_rename (oldname, newname) == -1 && errno != ENOENT) {
 		err = errno;
-		sprintf(oldname, "%s.index", old);
-		sprintf(newname, "%s.index", new);
-		g_rename(newname, oldname);
+		sprintf (oldname, "%s.index", old);
+		sprintf (newname, "%s.index", new);
+		g_rename (newname, oldname);
 		errno = err;
 		return -1;
 	}
@@ -974,21 +1015,21 @@ camel_text_index_rename(const gchar *old, const gchar *new)
 }
 
 gint
-camel_text_index_remove(const gchar *old)
+camel_text_index_remove (const gchar *old)
 {
 	gchar *block, *key;
 	gint ret = 0;
 
 	/* TODO: needs to poke any active indices to remain unlinked */
 
-	block = alloca(strlen(old)+12);
-	key = alloca(strlen(old)+12);
-	sprintf(block, "%s.index", old);
-	sprintf(key, "%s.index.data", old);
+	block = alloca (strlen (old)+12);
+	key = alloca (strlen (old)+12);
+	sprintf (block, "%s.index", old);
+	sprintf (key, "%s.index.data", old);
 
-	if (g_unlink(block) == -1 && errno != ENOENT)
+	if (g_unlink (block) == -1 && errno != ENOENT)
 		ret = -1;
-	if (g_unlink(key) == -1 && errno != ENOENT)
+	if (g_unlink (key) == -1 && errno != ENOENT)
 		ret = -1;
 
 	return ret;
@@ -996,28 +1037,28 @@ camel_text_index_remove(const gchar *old)
 
 /* Debug */
 void
-camel_text_index_info(CamelTextIndex *idx)
+camel_text_index_info (CamelTextIndex *idx)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	struct _CamelTextIndexRoot *rb = (struct _CamelTextIndexRoot *)p->blocks->root;
 	gint frag;
 
-	printf("Path: '%s'\n", idx->parent.path);
-	printf("Version: %u\n", idx->parent.version);
-	printf("Flags: %08x\n", idx->parent.flags);
-	printf("Total words: %u\n", rb->words);
-	printf("Total names: %u\n", rb->names);
-	printf("Total deleted: %u\n", rb->deleted);
-	printf("Total key blocks: %u\n", rb->keys);
+	printf ("Path: '%s'\n", idx->parent.path);
+	printf ("Version: %u\n", idx->parent.version);
+	printf ("Flags: %08x\n", idx->parent.flags);
+	printf ("Total words: %u\n", rb->words);
+	printf ("Total names: %u\n", rb->names);
+	printf ("Total deleted: %u\n", rb->deleted);
+	printf ("Total key blocks: %u\n", rb->keys);
 
 	if (rb->words > 0) {
 		frag = ((rb->keys - rb->words) * 100)/ rb->words;
-		printf("Word fragmentation: %d%%\n", frag);
+		printf ("Word fragmentation: %d%%\n", frag);
 	}
 
 	if (rb->names > 0) {
 		frag = (rb->deleted * 100)/ rb->names;
-		printf("Name fragmentation: %d%%\n", frag);
+		printf ("Name fragmentation: %d%%\n", frag);
 	}
 }
 
@@ -1027,83 +1068,83 @@ camel_text_index_info(CamelTextIndex *idx)
 enum { KEY_ROOT = 1, KEY_DATA = 2, PARTITION_MAP = 4, PARTITION_DATA = 8 };
 
 static void
-add_type(GHashTable *map, camel_block_t id, gint type)
+add_type (GHashTable *map, camel_block_t id, gint type)
 {
 	camel_block_t old;
 
-	old = g_hash_table_lookup(map, id);
+	old = g_hash_table_lookup (map, id);
 	if (old == type)
 		return;
 
 	if (old != 0 && old != type)
-		g_warning("block %x redefined as type %d, already type %d\n", id, type, old);
-	g_hash_table_insert(map, id, GINT_TO_POINTER (type|old));
+		g_warning ("block %x redefined as type %d, already type %d\n", id, type, old);
+	g_hash_table_insert (map, id, GINT_TO_POINTER (type|old));
 }
 
 static void
-add_partition(GHashTable *map, CamelBlockFile *blocks, camel_block_t id)
+add_partition (GHashTable *map, CamelBlockFile *blocks, camel_block_t id)
 {
 	CamelBlock *bl;
 	CamelPartitionMapBlock *pm;
 	gint i;
 
 	while (id) {
-		add_type(map, id, PARTITION_MAP);
-		bl = camel_block_file_get_block(blocks, id);
+		add_type (map, id, PARTITION_MAP);
+		bl = camel_block_file_get_block (blocks, id);
 		if (bl == NULL) {
-			g_warning("couldn't get parition: %x\n", id);
+			g_warning ("couldn't get parition: %x\n", id);
 			return;
 		}
 
 		pm = (CamelPartitionMapBlock *)&bl->data;
 		if (pm->used > G_N_ELEMENTS (pm->partition)) {
-			g_warning("Partition block %x invalid\n", id);
-			camel_block_file_unref_block(blocks, bl);
+			g_warning ("Partition block %x invalid\n", id);
+			camel_block_file_unref_block (blocks, bl);
 			return;
 		}
 
 		for (i=0;i<pm->used;i++)
-			add_type(map, pm->partition[i].blockid, PARTITION_DATA);
+			add_type (map, pm->partition[i].blockid, PARTITION_DATA);
 
 		id = pm->next;
-		camel_block_file_unref_block(blocks, bl);
+		camel_block_file_unref_block (blocks, bl);
 	}
 }
 
 static void
-add_keys(GHashTable *map, CamelBlockFile *blocks, camel_block_t id)
+add_keys (GHashTable *map, CamelBlockFile *blocks, camel_block_t id)
 {
 	CamelBlock *rbl, *bl;
 	CamelKeyRootBlock *root;
 	CamelKeyBlock *kb;
 
-	add_type(map, id, KEY_ROOT);
-	rbl = camel_block_file_get_block(blocks, id);
+	add_type (map, id, KEY_ROOT);
+	rbl = camel_block_file_get_block (blocks, id);
 	if (rbl == NULL) {
-		g_warning("couldn't get key root: %x\n", id);
+		g_warning ("couldn't get key root: %x\n", id);
 		return;
 	}
 	root = (CamelKeyRootBlock *)&rbl->data;
 	id = root->first;
 
 	while (id) {
-		add_type(map, id, KEY_DATA);
-		bl = camel_block_file_get_block(blocks, id);
+		add_type (map, id, KEY_DATA);
+		bl = camel_block_file_get_block (blocks, id);
 		if (bl == NULL) {
-			g_warning("couldn't get key: %x\n", id);
+			g_warning ("couldn't get key: %x\n", id);
 			break;
 		}
 
 		kb = (CamelKeyBlock *)&bl->data;
 		id = kb->next;
-		camel_block_file_unref_block(blocks, bl);
+		camel_block_file_unref_block (blocks, bl);
 	}
 
-	camel_block_file_unref_block(blocks, rbl);
+	camel_block_file_unref_block (blocks, rbl);
 }
 
 static void
-dump_raw(GHashTable *map, gchar *path)
+dump_raw (GHashTable *map, gchar *path)
 {
 	gchar buf[1024];
 	gchar line[256];
@@ -1113,70 +1154,70 @@ dump_raw(GHashTable *map, gchar *path)
 	gint fd;
 	camel_block_t id, total;
 
-	fd = g_open(path, O_RDONLY|O_BINARY, 0);
+	fd = g_open (path, O_RDONLY|O_BINARY, 0);
 	if (fd == -1)
 		return;
 
 	total = 0;
-	while ((len = read(fd, buf, 1024)) == 1024) {
+	while ((len = read (fd, buf, 1024)) == 1024) {
 		id = total;
 
-		type = g_hash_table_lookup(map, id);
+		type = g_hash_table_lookup (map, id);
 		switch (type) {
 		case 0:
-			printf(" - unknown -\n");
+			printf (" - unknown -\n");
 			break;
 		default:
-			printf(" - invalid -\n");
+			printf (" - invalid -\n");
 			break;
 		case KEY_ROOT: {
 			CamelKeyRootBlock *r = (CamelKeyRootBlock *)buf;
-			printf("Key root:\n");
-			printf("First: %08x     Last: %08x     Free: %08x\n", r->first, r->last, r->free);
+			printf ("Key root:\n");
+			printf ("First: %08x     Last: %08x     Free: %08x\n", r->first, r->last, r->free);
 		} break;
 		case KEY_DATA: {
 			CamelKeyBlock *k = (CamelKeyBlock *)buf;
-			printf("Key data:\n");
-			printf("Next: %08x      Used: %u\n", k->next, k->used);
+			printf ("Key data:\n");
+			printf ("Next: %08x      Used: %u\n", k->next, k->used);
 			for (i=0;i<k->used;i++) {
 				if (i == 0)
-					len = sizeof(k->u.keydata);
+					len = sizeof (k->u.keydata);
 				else
 					len = k->u.keys[i-1].offset;
 				len -= k->u.keys[i].offset;
-				printf("[%03d]: %08x %5d %06x %3d '%.*s'\n", i,
+				printf ("[%03d]: %08x %5d %06x %3d '%.*s'\n", i,
 				       k->u.keys[i].data, k->u.keys[i].offset, k->u.keys[i].flags,
 				       len, len, k->u.keydata+k->u.keys[i].offset);
 			}
 		} break;
 		case PARTITION_MAP: {
 			CamelPartitionMapBlock *m = (CamelPartitionMapBlock *)buf;
-			printf("Partition map\n");
-			printf("Next: %08x      Used: %u\n", m->next, m->used);
+			printf ("Partition map\n");
+			printf ("Next: %08x      Used: %u\n", m->next, m->used);
 			for (i=0;i<m->used;i++) {
-				printf("[%03d]: %08x -> %08x\n", i, m->partition[i].hashid, m->partition[i].blockid);
+				printf ("[%03d]: %08x -> %08x\n", i, m->partition[i].hashid, m->partition[i].blockid);
 			}
 		} break;
 		case PARTITION_DATA: {
 			CamelPartitionKeyBlock *k = (CamelPartitionKeyBlock *)buf;
-			printf("Partition data\n");
-			printf("Used: %u\n", k->used);
+			printf ("Partition data\n");
+			printf ("Used: %u\n", k->used);
 		} break;
 		}
 
-		printf("--raw--\n");
+		printf ("--raw--\n");
 
 		len = 1024;
 		p = buf;
 		do {
-			sprintf(line, "%08x:                                                                      ", total);
+			sprintf (line, "%08x:                                                                      ", total);
 			total += 16;
 			o = line+10;
 			a = o+16*2+2;
 			i = 0;
 			while (len && i<16) {
 				c = *p++;
-				*a++ = isprint(c)?c:'.';
+				*a++ = isprint (c)?c:'.';
 				*o++ = hex[(c>>4)&0x0f];
 				*o++ = hex[c&0x0f];
 				i++;
@@ -1185,9 +1226,9 @@ dump_raw(GHashTable *map, gchar *path)
 				len--;
 			}
 			*a = 0;
-			printf("%s\n", line);
+			printf ("%s\n", line);
 		} while (len);
-		printf("\n");
+		printf ("\n");
 	}
 	close (fd);
 }
@@ -1195,9 +1236,9 @@ dump_raw(GHashTable *map, gchar *path)
 
 /* Debug */
 void
-camel_text_index_dump(CamelTextIndex *idx)
+camel_text_index_dump (CamelTextIndex *idx)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 #ifndef DUMP_RAW
 	camel_key_t keyid;
 	gchar *word;
@@ -1207,56 +1248,56 @@ camel_text_index_dump(CamelTextIndex *idx)
 
 	/* Iterate over all names in the file first */
 
-	printf("UID's in index\n");
+	printf ("UID's in index\n");
 
 	keyid = 0;
-	while ( (keyid = camel_key_table_next(p->name_index, keyid, &word, &flags, &data)) ) {
+	while ( (keyid = camel_key_table_next (p->name_index, keyid, &word, &flags, &data)) ) {
 		if ((flags & 1) == 0)
-			printf(" %s\n", word);
+			printf (" %s\n", word);
 		else
-			printf(" %s (deleted)\n", word);
-		g_free(word);
+			printf (" %s (deleted)\n", word);
+		g_free (word);
 	}
 
-	printf("Word's in index\n");
+	printf ("Word's in index\n");
 
 	keyid = 0;
-	while ( (keyid = camel_key_table_next(p->word_index, keyid, &word, &flags, &data)) ) {
+	while ( (keyid = camel_key_table_next (p->word_index, keyid, &word, &flags, &data)) ) {
 		CamelIndexCursor *idc;
 
-		printf("Word: '%s':\n", word);
+		printf ("Word: '%s':\n", word);
 
-		idc = camel_index_find((CamelIndex *)idx, word);
-		while ( (name = camel_index_cursor_next(idc)) ) {
-			printf(" %s", name);
+		idc = camel_index_find ((CamelIndex *)idx, word);
+		while ( (name = camel_index_cursor_next (idc)) ) {
+			printf (" %s", name);
 		}
-		printf("\n");
-		camel_object_unref((CamelObject *)idc);
-		g_free(word);
+		printf ("\n");
+		g_object_unref (idc);
+		g_free (word);
 	}
 #else
 	/* a more low-level dump routine */
-	GHashTable *block_type = g_hash_table_new(NULL, NULL);
+	GHashTable *block_type = g_hash_table_new (NULL, NULL);
 	camel_block_t id;
 	struct stat st;
 	gint type;
 
-	add_keys(block_type, p->blocks, p->word_index->rootid);
-	add_keys(block_type, p->blocks, p->name_index->rootid);
+	add_keys (block_type, p->blocks, p->word_index->rootid);
+	add_keys (block_type, p->blocks, p->name_index->rootid);
 
-	add_partition(block_type, p->blocks, p->word_hash->rootid);
-	add_partition(block_type, p->blocks, p->name_hash->rootid);
+	add_partition (block_type, p->blocks, p->word_hash->rootid);
+	add_partition (block_type, p->blocks, p->name_hash->rootid);
 
-	dump_raw(block_type, p->blocks->path);
-	g_hash_table_destroy(block_type);
+	dump_raw (block_type, p->blocks->path);
+	g_hash_table_destroy (block_type);
 #endif
 }
 
 /* more debug stuff */
 void
-camel_text_index_validate(CamelTextIndex *idx)
+camel_text_index_validate (CamelTextIndex *idx)
 {
-	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+	CamelTextIndexPrivate *p = CAMEL_TEXT_INDEX_GET_PRIVATE (idx);
 	camel_key_t keyid;
 	gchar *word;
 	const gchar *name;
@@ -1268,132 +1309,145 @@ camel_text_index_validate(CamelTextIndex *idx)
 
 	GHashTable *names, *deleted, *words, *keys, *name_word, *word_word;
 
-	names = g_hash_table_new(NULL, NULL);
-	deleted = g_hash_table_new(NULL, NULL);
+	names = g_hash_table_new (NULL, NULL);
+	deleted = g_hash_table_new (NULL, NULL);
 
-	name_word = g_hash_table_new(g_str_hash, g_str_equal);
+	name_word = g_hash_table_new (g_str_hash, g_str_equal);
 
-	words = g_hash_table_new(NULL, NULL);
-	keys = g_hash_table_new(NULL, NULL);
+	words = g_hash_table_new (NULL, NULL);
+	keys = g_hash_table_new (NULL, NULL);
 
-	word_word = g_hash_table_new(g_str_hash, g_str_equal);
+	word_word = g_hash_table_new (g_str_hash, g_str_equal);
 
 	/* Iterate over all names in the file first */
 
-	printf("Checking UID consistency\n");
+	printf ("Checking UID consistency\n");
 
 	keyid = 0;
-	while ( (keyid = camel_key_table_next(p->name_index, keyid, &word, &flags, &data)) ) {
-		if ((oldword = g_hash_table_lookup(names, GINT_TO_POINTER(keyid))) != NULL
-		    || (oldword = g_hash_table_lookup(deleted, GINT_TO_POINTER(keyid))) != NULL) {
-			printf("Warning, name '%s' duplicates key (%x) with name '%s'\n", word, keyid, oldword);
-			g_free(word);
+	while ( (keyid = camel_key_table_next (p->name_index, keyid, &word, &flags, &data)) ) {
+		if ((oldword = g_hash_table_lookup (names, GINT_TO_POINTER (keyid))) != NULL
+		    || (oldword = g_hash_table_lookup (deleted, GINT_TO_POINTER (keyid))) != NULL) {
+			printf ("Warning, name '%s' duplicates key (%x) with name '%s'\n", word, keyid, oldword);
+			g_free (word);
 		} else {
-			g_hash_table_insert(name_word, word, GINT_TO_POINTER (1));
+			g_hash_table_insert (name_word, word, GINT_TO_POINTER (1));
 			if ((flags & 1) == 0) {
-				g_hash_table_insert(names, GINT_TO_POINTER(keyid), word);
+				g_hash_table_insert (names, GINT_TO_POINTER (keyid), word);
 			} else {
-				g_hash_table_insert(deleted, GINT_TO_POINTER(keyid), word);
+				g_hash_table_insert (deleted, GINT_TO_POINTER (keyid), word);
 			}
 		}
 	}
 
-	printf("Checking WORD member consistency\n");
+	printf ("Checking WORD member consistency\n");
 
 	keyid = 0;
-	while ( (keyid = camel_key_table_next(p->word_index, keyid, &word, &flags, &data)) ) {
+	while ( (keyid = camel_key_table_next (p->word_index, keyid, &word, &flags, &data)) ) {
 		CamelIndexCursor *idc;
 		GHashTable *used;
 
 		/* first, check for duplicates of keyid, and data */
-		if ((oldword = g_hash_table_lookup(words, GINT_TO_POINTER(keyid))) != NULL) {
-			printf("Warning, word '%s' duplicates key (%x) with name '%s'\n", word, keyid, oldword);
-			g_free(word);
+		if ((oldword = g_hash_table_lookup (words, GINT_TO_POINTER (keyid))) != NULL) {
+			printf ("Warning, word '%s' duplicates key (%x) with name '%s'\n", word, keyid, oldword);
+			g_free (word);
 			word = oldword;
 		} else {
-			g_hash_table_insert(words, GINT_TO_POINTER(keyid), word);
+			g_hash_table_insert (words, GINT_TO_POINTER (keyid), word);
 		}
 
 		if (data == 0) {
 			/* This may not be an issue if things have been removed over time,
 			   though it is a problem if its a fresh index */
-			printf("Word '%s' has no data associated with it\n", word);
+			printf ("Word '%s' has no data associated with it\n", word);
 		} else {
-			if ((oldword = g_hash_table_lookup(keys, GUINT_TO_POINTER(data))) != NULL) {
-				printf("Warning, word '%s' duplicates data (%x) with name '%s'\n", word, data, oldword);
+			if ((oldword = g_hash_table_lookup (keys, GUINT_TO_POINTER (data))) != NULL) {
+				printf ("Warning, word '%s' duplicates data (%x) with name '%s'\n", word, data, oldword);
 			} else {
-				g_hash_table_insert(keys, GUINT_TO_POINTER(data), word);
+				g_hash_table_insert (keys, GUINT_TO_POINTER (data), word);
 			}
 		}
 
-		if ((oldword = g_hash_table_lookup(word_word, word)) != NULL) {
-			printf("Warning, word '%s' occurs more than once\n", word);
+		if ((oldword = g_hash_table_lookup (word_word, word)) != NULL) {
+			printf ("Warning, word '%s' occurs more than once\n", word);
 		} else {
-			g_hash_table_insert(word_word, word, word);
+			g_hash_table_insert (word_word, word, word);
 		}
 
-		used = g_hash_table_new(g_str_hash, g_str_equal);
+		used = g_hash_table_new (g_str_hash, g_str_equal);
 
-		idc = camel_index_find((CamelIndex *)idx, word);
-		while ( (name = camel_index_cursor_next(idc)) ) {
-			if (g_hash_table_lookup(name_word, name) == NULL) {
-				printf("word '%s' references non-existant name '%s'\n", word, name);
+		idc = camel_index_find ((CamelIndex *)idx, word);
+		while ( (name = camel_index_cursor_next (idc)) ) {
+			if (g_hash_table_lookup (name_word, name) == NULL) {
+				printf ("word '%s' references non-existant name '%s'\n", word, name);
 			}
-			if (g_hash_table_lookup(used, name) != NULL) {
-				printf("word '%s' uses word '%s' more than once\n", word, name);
+			if (g_hash_table_lookup (used, name) != NULL) {
+				printf ("word '%s' uses word '%s' more than once\n", word, name);
 			} else {
-				g_hash_table_insert(used, g_strdup(name), (gpointer)1);
+				g_hash_table_insert (used, g_strdup (name), (gpointer)1);
 			}
 		}
-		camel_object_unref((CamelObject *)idc);
+		g_object_unref (idc);
 
-		g_hash_table_foreach(used, (GHFunc)g_free, NULL);
-		g_hash_table_destroy(used);
+		g_hash_table_foreach (used, (GHFunc)g_free, NULL);
+		g_hash_table_destroy (used);
 
-		printf("word '%s'\n", word);
+		printf ("word '%s'\n", word);
 
 		while (data) {
-			printf(" data %x ", data);
-			if (camel_key_file_read(p->links, &data, &count, &records) == -1) {
-				printf("Warning, read failed for word '%s', at data '%u'\n", word, data);
+			printf (" data %x ", data);
+			if (camel_key_file_read (p->links, &data, &count, &records) == -1) {
+				printf ("Warning, read failed for word '%s', at data '%u'\n", word, data);
 				data = 0;
 			} else {
-				printf("(%d)\n", (gint)count);
-				g_free(records);
+				printf ("(%d)\n", (gint)count);
+				g_free (records);
 			}
 		}
 	}
 
-	g_hash_table_destroy(names);
-	g_hash_table_destroy(deleted);
-	g_hash_table_destroy(words);
-	g_hash_table_destroy(keys);
+	g_hash_table_destroy (names);
+	g_hash_table_destroy (deleted);
+	g_hash_table_destroy (words);
+	g_hash_table_destroy (keys);
 
-	g_hash_table_foreach(name_word, (GHFunc)g_free, NULL);
-	g_hash_table_destroy(name_word);
+	g_hash_table_foreach (name_word, (GHFunc)g_free, NULL);
+	g_hash_table_destroy (name_word);
 
-	g_hash_table_foreach(word_word, (GHFunc)g_free, NULL);
-	g_hash_table_destroy(word_word);
+	g_hash_table_foreach (word_word, (GHFunc)g_free, NULL);
+	g_hash_table_destroy (word_word);
 }
 
 /* ********************************************************************** */
 /* CamelTextIndexName */
 /* ********************************************************************** */
 
-static CamelIndexNameClass *camel_text_index_name_parent;
+static gpointer text_index_name_parent_class;
+
+static void
+text_index_name_finalize (GObject *object)
+{
+	CamelTextIndexNamePrivate *priv;
+
+	priv = CAMEL_TEXT_INDEX_NAME_GET_PRIVATE (object);
+
+	g_hash_table_destroy (CAMEL_TEXT_INDEX_NAME (object)->parent.words);
 
-#define CIN_CLASS(o) ((CamelTextIndexNameClass *)(((CamelObject *)o)->classfuncs))
-#define CIN_PRIVATE(o) (((CamelTextIndexName *)(o))->priv)
+	g_string_free (priv->buffer, TRUE);
+	e_mempool_destroy (priv->pool);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (text_index_name_parent_class)->finalize (object);
+}
 
 static void
-text_index_name_add_word(CamelIndexName *idn, const gchar *word)
+text_index_name_add_word (CamelIndexName *idn, const gchar *word)
 {
-	struct _CamelTextIndexNamePrivate *p = ((CamelTextIndexName *)idn)->priv;
+	CamelTextIndexNamePrivate *p = ((CamelTextIndexName *)idn)->priv;
 
-	if (g_hash_table_lookup(idn->words, word) == NULL) {
-		gchar *w = e_mempool_strdup(p->pool, word);
+	if (g_hash_table_lookup (idn->words, word) == NULL) {
+		gchar *w = e_mempool_strdup (p->pool, word);
 
-		g_hash_table_insert(idn->words, w, w);
+		g_hash_table_insert (idn->words, w, w);
 	}
 }
 
@@ -1402,7 +1456,7 @@ text_index_name_add_word(CamelIndexName *idn, const gchar *word)
    Used to clean up utf8 before it gets further */
 
 static inline guint32
-camel_utf8_next(const guchar **ptr, const guchar *ptrend)
+camel_utf8_next (const guchar **ptr, const guchar *ptrend)
 {
 	register guchar *p = (guchar *)*ptr;
 	register guint c;
@@ -1462,9 +1516,9 @@ camel_utf8_next(const guchar **ptr, const guchar *ptrend)
 }
 
 static gsize
-text_index_name_add_buffer(CamelIndexName *idn, const gchar *buffer, gsize len)
+text_index_name_add_buffer (CamelIndexName *idn, const gchar *buffer, gsize len)
 {
-	CamelTextIndexNamePrivate *p = CIN_PRIVATE(idn);
+	CamelTextIndexNamePrivate *p = CAMEL_TEXT_INDEX_NAME_GET_PRIVATE (idn);
 	const guchar *ptr, *ptrend;
 	guint32 c;
 	gchar utf8[8];
@@ -1472,24 +1526,24 @@ text_index_name_add_buffer(CamelIndexName *idn, const gchar *buffer, gsize len)
 
 	if (buffer == NULL) {
 		if (p->buffer->len) {
-			camel_index_name_add_word(idn, p->buffer->str);
-			g_string_truncate(p->buffer, 0);
+			camel_index_name_add_word (idn, p->buffer->str);
+			g_string_truncate (p->buffer, 0);
 		}
 		return 0;
 	}
 
 	ptr = (const guchar *) buffer;
 	ptrend = (const guchar *) buffer+len;
-	while ((c = camel_utf8_next(&ptr, ptrend))) {
-		if (g_unichar_isalnum(c)) {
-			c = g_unichar_tolower(c);
-			utf8len = g_unichar_to_utf8(c, utf8);
+	while ((c = camel_utf8_next (&ptr, ptrend))) {
+		if (g_unichar_isalnum (c)) {
+			c = g_unichar_tolower (c);
+			utf8len = g_unichar_to_utf8 (c, utf8);
 			utf8[utf8len] = 0;
-			g_string_append(p->buffer, utf8);
+			g_string_append (p->buffer, utf8);
 		} else {
 			if (p->buffer->len > 0 && p->buffer->len <= CAMEL_TEXT_INDEX_MAX_WORDLEN) {
-				text_index_name_add_word(idn, p->buffer->str);
-				/*camel_index_name_add_word(idn, p->buffer->str);*/
+				text_index_name_add_word (idn, p->buffer->str);
+				/*camel_index_name_add_word (idn, p->buffer->str);*/
 			}
 
 			g_string_truncate (p->buffer, 0);
@@ -1500,69 +1554,65 @@ text_index_name_add_buffer(CamelIndexName *idn, const gchar *buffer, gsize len)
 }
 
 static void
-camel_text_index_name_class_init(CamelTextIndexNameClass *klass)
+text_index_name_class_init (CamelTextIndexNameClass *class)
 {
-	CamelIndexNameClass *nklass = (CamelIndexNameClass *)klass;
-
-	camel_text_index_name_parent = CAMEL_INDEX_NAME_CLASS(camel_type_get_global_classfuncs(camel_index_name_get_type()));
-
-	nklass->add_word = text_index_name_add_word;
-	nklass->add_buffer = text_index_name_add_buffer;
-}
+	GObjectClass *object_class;
+	CamelIndexNameClass *index_name_class;
 
-static void
-camel_text_index_name_init(CamelTextIndexName *idn)
-{
-	CamelTextIndexNamePrivate *p;
+	text_index_name_parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelTextIndexNamePrivate));
 
-	idn->parent.words = g_hash_table_new(g_str_hash, g_str_equal);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = text_index_name_finalize;
 
-	p = idn->priv = g_malloc0(sizeof(*idn->priv));
-	p->buffer = g_string_new("");
-	p->pool = e_mempool_new(256, 128, E_MEMPOOL_ALIGN_BYTE);
+	index_name_class = CAMEL_INDEX_NAME_CLASS (class);
+	index_name_class->add_word = text_index_name_add_word;
+	index_name_class->add_buffer = text_index_name_add_buffer;
 }
 
 static void
-camel_text_index_name_finalise(CamelTextIndexName *idn)
+text_index_name_init (CamelTextIndexName *text_index_name)
 {
-	CamelTextIndexNamePrivate *p = CIN_PRIVATE(idn);
-
-	g_hash_table_destroy(idn->parent.words);
+	text_index_name->priv =
+		CAMEL_TEXT_INDEX_NAME_GET_PRIVATE (text_index_name);
 
-	g_string_free(p->buffer, TRUE);
-	e_mempool_destroy(p->pool);
+	text_index_name->parent.words = g_hash_table_new (
+		g_str_hash, g_str_equal);
 
-	g_free(p);
+	text_index_name->priv->buffer = g_string_new ("");
+	text_index_name->priv->pool =
+		e_mempool_new (256, 128, E_MEMPOOL_ALIGN_BYTE);
 }
 
-CamelType
-camel_text_index_name_get_type(void)
+GType
+camel_text_index_name_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_index_name_get_type(), "CamelTextIndexName",
-					   sizeof (CamelTextIndexName),
-					   sizeof (CamelTextIndexNameClass),
-					   (CamelObjectClassInitFunc) camel_text_index_name_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_text_index_name_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_name_finalise);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID)) {
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_INDEX_NAME,
+			"CamelTextIndexName",
+			sizeof (CamelTextIndexNameClass),
+			(GClassInitFunc) text_index_name_class_init,
+			sizeof (CamelTextIndexName),
+			(GInstanceInitFunc) text_index_name_init,
+			0);
 	}
 
 	return type;
 }
 
 CamelTextIndexName *
-camel_text_index_name_new(CamelTextIndex *idx, const gchar *name, camel_key_t nameid)
+camel_text_index_name_new (CamelTextIndex *idx, const gchar *name, camel_key_t nameid)
 {
-	CamelTextIndexName *idn = (CamelTextIndexName *)camel_object_new(camel_text_index_name_get_type());
+	CamelTextIndexName *idn = g_object_new (CAMEL_TYPE_TEXT_INDEX_NAME, NULL);
 	CamelIndexName *cin = &idn->parent;
-	CamelTextIndexNamePrivate *p = CIN_PRIVATE(idn);
+	CamelTextIndexNamePrivate *p = CAMEL_TEXT_INDEX_NAME_GET_PRIVATE (idn);
 
 	cin->index = (CamelIndex *)idx;
-	camel_object_ref((CamelObject *)idx);
-	cin->name = e_mempool_strdup(p->pool, name);
+	g_object_ref (idx);
+	cin->name = e_mempool_strdup (p->pool, name);
 	p->nameid = nameid;
 
 	return idn;
@@ -1572,36 +1622,47 @@ camel_text_index_name_new(CamelTextIndex *idx, const gchar *name, camel_key_t na
 /* CamelTextIndexCursor */
 /* ********************************************************************** */
 
-static CamelIndexCursorClass *camel_text_index_cursor_parent;
+static gpointer text_index_cursor_parent_class;
+
+static void
+text_index_cursor_finalize (GObject *object)
+{
+	CamelTextIndexCursorPrivate *priv;
+
+	priv = CAMEL_TEXT_INDEX_CURSOR_GET_PRIVATE (object);
+
+	g_free (priv->records);
+	g_free (priv->current);
 
-#define CIC_CLASS(o) ((CamelTextIndexCursorClass *)(((CamelObject *)o)->classfuncs))
-#define CIC_PRIVATE(o) (((CamelTextIndexCursor *)(o))->priv)
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (text_index_cursor_parent_class)->finalize (object);
+}
 
 static const gchar *
-text_index_cursor_next(CamelIndexCursor *idc)
+text_index_cursor_next (CamelIndexCursor *idc)
 {
-	struct _CamelTextIndexCursorPrivate *p = CIC_PRIVATE(idc);
-	struct _CamelTextIndexPrivate *tip = CTI_PRIVATE(idc->index);
+	CamelTextIndexCursorPrivate *p = CAMEL_TEXT_INDEX_CURSOR_GET_PRIVATE (idc);
+	CamelTextIndexPrivate *tip = CAMEL_TEXT_INDEX_GET_PRIVATE (idc->index);
 	guint flags;
 
-	c(printf("Going to next cursor for word with data '%08x' next %08x\n", p->first, p->next));
+	c (printf ("Going to next cursor for word with data '%08x' next %08x\n", p->first, p->next));
 
 	do {
 		while (p->record_index >= p->record_count) {
-			g_free(p->records);
+			g_free (p->records);
 			p->records = NULL;
 			p->record_index = 0;
 			p->record_count = 0;
 			if (p->next == 0)
 				return NULL;
-			if (camel_key_file_read(tip->links, &p->next, &p->record_count, &p->records) == -1)
+			if (camel_key_file_read (tip->links, &p->next, &p->record_count, &p->records) == -1)
 				return NULL;
 		}
 
-		g_free(p->current);
-		camel_key_table_lookup(tip->name_index, p->records[p->record_index], &p->current, &flags);
+		g_free (p->current);
+		camel_key_table_lookup (tip->name_index, p->records[p->record_index], &p->current, &flags);
 		if (flags & 1) {
-			g_free(p->current);
+			g_free (p->current);
 			p->current = NULL;
 		}
 		p->record_index++;
@@ -1611,13 +1672,13 @@ text_index_cursor_next(CamelIndexCursor *idc)
 }
 
 static void
-text_index_cursor_reset(CamelIndexCursor *idc)
+text_index_cursor_reset (CamelIndexCursor *idc)
 {
-	struct _CamelTextIndexCursorPrivate *p = CIC_PRIVATE(idc);
+	CamelTextIndexCursorPrivate *p = CAMEL_TEXT_INDEX_CURSOR_GET_PRIVATE (idc);
 
-	g_free(p->records);
+	g_free (p->records);
 	p->records = NULL;
-	g_free(p->current);
+	g_free (p->current);
 	p->current = NULL;
 	p->record_count = 0;
 	p->record_index = 0;
@@ -1625,59 +1686,57 @@ text_index_cursor_reset(CamelIndexCursor *idc)
 }
 
 static void
-camel_text_index_cursor_class_init(CamelTextIndexCursorClass *klass)
+text_index_cursor_class_init (CamelTextIndexCursorClass *class)
 {
-	CamelIndexCursorClass *cklass = (CamelIndexCursorClass *)klass;
+	GObjectClass *object_class;
+	CamelIndexCursorClass *index_cursor_class;
 
-	camel_text_index_cursor_parent = CAMEL_INDEX_CURSOR_CLASS(camel_type_get_global_classfuncs(camel_index_cursor_get_type()));
+	text_index_cursor_parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelTextIndexCursorPrivate));
 
-	cklass->next = text_index_cursor_next;
-	cklass->reset = text_index_cursor_reset;
-}
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = text_index_cursor_finalize;
 
-static void
-camel_text_index_cursor_init(CamelTextIndexCursor *idc)
-{
-	CIC_PRIVATE(idc) = g_malloc0(sizeof(struct _CamelTextIndexCursorPrivate));
+	index_cursor_class = CAMEL_INDEX_CURSOR_CLASS (class);
+	index_cursor_class->next = text_index_cursor_next;
+	index_cursor_class->reset = text_index_cursor_reset;
 }
 
 static void
-camel_text_index_cursor_finalise(CamelTextIndexCursor *idc)
+text_index_cursor_init (CamelTextIndexCursor *text_index_cursor)
 {
-	struct _CamelTextIndexCursorPrivate *p = CIC_PRIVATE(idc);
-
-	g_free(p->records);
-	g_free(p->current);
-	g_free(p);
+	text_index_cursor->priv =
+		CAMEL_TEXT_INDEX_CURSOR_GET_PRIVATE (text_index_cursor);
 }
 
-CamelType
-camel_text_index_cursor_get_type(void)
+GType
+camel_text_index_cursor_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_index_cursor_get_type(), "CamelTextIndexCursor",
-					   sizeof (CamelTextIndexCursor),
-					   sizeof (CamelTextIndexCursorClass),
-					   (CamelObjectClassInitFunc) camel_text_index_cursor_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_text_index_cursor_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_cursor_finalise);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID)) {
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_INDEX_CURSOR,
+			"CamelTextIndexCursor",
+			sizeof (CamelTextIndexCursorClass),
+			(GClassInitFunc) text_index_cursor_class_init,
+			sizeof (CamelTextIndexCursor),
+			(GInstanceInitFunc) text_index_cursor_init,
+			0);
 	}
 
 	return type;
 }
 
 CamelTextIndexCursor *
-camel_text_index_cursor_new(CamelTextIndex *idx, camel_block_t data)
+camel_text_index_cursor_new (CamelTextIndex *idx, camel_block_t data)
 {
-	CamelTextIndexCursor *idc = (CamelTextIndexCursor *)camel_object_new(camel_text_index_cursor_get_type());
+	CamelTextIndexCursor *idc = g_object_new (CAMEL_TYPE_TEXT_INDEX_CURSOR, NULL);
 	CamelIndexCursor *cic = &idc->parent;
-	struct _CamelTextIndexCursorPrivate *p = CIC_PRIVATE(idc);
+	CamelTextIndexCursorPrivate *p = CAMEL_TEXT_INDEX_CURSOR_GET_PRIVATE (idc);
 
 	cic->index = (CamelIndex *)idx;
-	camel_object_ref((CamelObject *)idx);
+	g_object_ref (idx);
 	p->first = data;
 	p->next = data;
 	p->record_count = 0;
@@ -1690,26 +1749,52 @@ camel_text_index_cursor_new(CamelTextIndex *idx, camel_block_t data)
 /* CamelTextIndexKeyCursor */
 /* ********************************************************************** */
 
-static CamelIndexCursorClass *camel_text_index_key_cursor_parent;
+static gpointer text_index_key_cursor_parent_class;
+
+static void
+text_index_key_cursor_dispose (GObject *object)
+{
+	CamelTextIndexKeyCursorPrivate *priv;
+
+	priv = CAMEL_TEXT_INDEX_KEY_CURSOR_GET_PRIVATE (object);
+
+	if (priv->table != NULL) {
+		g_object_unref (priv->table);
+		priv->table = NULL;
+	}
+
+	/* Chain up parent's dispose() method. */
+	G_OBJECT_CLASS (text_index_key_cursor_parent_class)->dispose (object);
+}
+
+static void
+text_index_key_cursor_finalize (GObject *object)
+{
+	CamelTextIndexKeyCursorPrivate *priv;
 
-#define CIKC_CLASS(o) ((CamelTextIndexKeyCursorClass *)(((CamelObject *)o)->classfuncs))
-#define CIKC_PRIVATE(o) (((CamelTextIndexKeyCursor *)(o))->priv)
+	priv = CAMEL_TEXT_INDEX_KEY_CURSOR_GET_PRIVATE (object);
+
+	g_free (priv->current);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (text_index_key_cursor_parent_class)->finalize (object);
+}
 
 static const gchar *
-text_index_key_cursor_next(CamelIndexCursor *idc)
+text_index_key_cursor_next (CamelIndexCursor *idc)
 {
-	struct _CamelTextIndexKeyCursorPrivate *p = CIKC_PRIVATE(idc);
+	CamelTextIndexKeyCursorPrivate *p = CAMEL_TEXT_INDEX_KEY_CURSOR_GET_PRIVATE (idc);
 
-	c(printf("Going to next cursor for keyid %08x\n", p->keyid));
+	c (printf ("Going to next cursor for keyid %08x\n", p->keyid));
 
-	g_free(p->current);
+	g_free (p->current);
 	p->current = NULL;
 
-	while ( (p->keyid = camel_key_table_next(p->table, p->keyid, &p->current, &p->flags, &p->data)) ) {
+	while ( (p->keyid = camel_key_table_next (p->table, p->keyid, &p->current, &p->flags, &p->data)) ) {
 		if ((p->flags & 1) == 0) {
 			return p->current;
 		} else {
-			g_free(p->current);
+			g_free (p->current);
 			p->current = NULL;
 		}
 	}
@@ -1718,80 +1803,77 @@ text_index_key_cursor_next(CamelIndexCursor *idc)
 }
 
 static void
-text_index_key_cursor_reset(CamelIndexCursor *idc)
+text_index_key_cursor_reset (CamelIndexCursor *idc)
 {
-	struct _CamelTextIndexKeyCursorPrivate *p = CIKC_PRIVATE(idc);
+	CamelTextIndexKeyCursorPrivate *p = CAMEL_TEXT_INDEX_KEY_CURSOR_GET_PRIVATE (idc);
 
 	p->keyid = 0;
 	p->flags = 0;
 	p->data = 0;
-	g_free(p->current);
+	g_free (p->current);
 	p->current = NULL;
 }
 
 static void
-camel_text_index_key_cursor_class_init(CamelTextIndexKeyCursorClass *klass)
+text_index_key_cursor_class_init (CamelTextIndexKeyCursorClass *class)
 {
-	CamelIndexCursorClass *cklass = (CamelIndexCursorClass *)klass;
+	GObjectClass *object_class;
+	CamelIndexCursorClass *index_cursor_class;
 
-	camel_text_index_key_cursor_parent = CAMEL_INDEX_CURSOR_CLASS(camel_type_get_global_classfuncs(camel_index_cursor_get_type()));
+	text_index_key_cursor_parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelTextIndexKeyCursorPrivate));
 
-	cklass->next = text_index_key_cursor_next;
-	cklass->reset = text_index_key_cursor_reset;
-}
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = text_index_key_cursor_dispose;
+	object_class->finalize = text_index_key_cursor_finalize;
 
-static void
-camel_text_index_key_cursor_init(CamelTextIndexKeyCursor *idc)
-{
-	struct _CamelTextIndexKeyCursorPrivate *p;
-
-	p = idc->priv = g_malloc0(sizeof(struct _CamelTextIndexKeyCursorPrivate));
-	p->keyid = 0;
-	p->flags = 0;
-	p->data = 0;
-	p->current = NULL;
+	index_cursor_class = CAMEL_INDEX_CURSOR_CLASS (class);
+	index_cursor_class->next = text_index_key_cursor_next;
+	index_cursor_class->reset = text_index_key_cursor_reset;
 }
 
 static void
-camel_text_index_key_cursor_finalise(CamelTextIndexKeyCursor *idc)
+text_index_key_cursor_init (CamelTextIndexKeyCursor *text_index_key_cursor)
 {
-	struct _CamelTextIndexKeyCursorPrivate *p = CIKC_PRIVATE(idc);
+	text_index_key_cursor->priv =
+		CAMEL_TEXT_INDEX_KEY_CURSOR_GET_PRIVATE (text_index_key_cursor);
 
-	g_free(p->current);
-	if (p->table)
-		camel_object_unref((CamelObject *)p->table);
-	g_free(p);
+	text_index_key_cursor->priv->keyid = 0;
+	text_index_key_cursor->priv->flags = 0;
+	text_index_key_cursor->priv->data = 0;
+	text_index_key_cursor->priv->current = NULL;
 }
 
-CamelType
-camel_text_index_key_cursor_get_type(void)
+GType
+camel_text_index_key_cursor_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_index_cursor_get_type(), "CamelTextIndexKeyCursor",
-					   sizeof (CamelTextIndexKeyCursor),
-					   sizeof (CamelTextIndexKeyCursorClass),
-					   (CamelObjectClassInitFunc) camel_text_index_key_cursor_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_text_index_key_cursor_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_key_cursor_finalise);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID)) {
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_INDEX_CURSOR,
+			"CamelTextIndexKeyCursor",
+			sizeof (CamelTextIndexKeyCursorClass),
+			(GClassInitFunc) text_index_key_cursor_class_init,
+			sizeof (CamelTextIndexKeyCursor),
+			(GInstanceInitFunc) text_index_key_cursor_init,
+			0);
 	}
 
 	return type;
 }
 
 CamelTextIndexKeyCursor *
-camel_text_index_key_cursor_new(CamelTextIndex *idx, CamelKeyTable *table)
+camel_text_index_key_cursor_new (CamelTextIndex *idx, CamelKeyTable *table)
 {
-	CamelTextIndexKeyCursor *idc = (CamelTextIndexKeyCursor *)camel_object_new(camel_text_index_key_cursor_get_type());
+	CamelTextIndexKeyCursor *idc = g_object_new (CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR, NULL);
 	CamelIndexCursor *cic = &idc->parent;
-	struct _CamelTextIndexKeyCursorPrivate *p = CIKC_PRIVATE(idc);
+	CamelTextIndexKeyCursorPrivate *p = CAMEL_TEXT_INDEX_KEY_CURSOR_GET_PRIVATE (idc);
 
 	cic->index = (CamelIndex *)idx;
-	camel_object_ref((CamelObject *)idx);
+	g_object_ref (idx);
 	p->table = table;
-	camel_object_ref((CamelObject *)table);
+	g_object_ref (table);
 
 	return idc;
 }
@@ -1817,7 +1899,7 @@ gchar wordbuffer[] = "This is a buffer of multiple words.  Some of the words are
 " with,with:with;with-with'with\"'\"various punctuation as well.  So much for those Words. and 10"
 " numbers in a row too 1,2,3,4,5,6,7,8,9,10!  Yay!.";
 
-gint main(gint argc, gchar **argv)
+gint main (gint argc, gchar **argv)
 {
 #if 0
 	CamelBlockFile *bs;
@@ -1836,15 +1918,15 @@ gint main(gint argc, gchar **argv)
 	const gchar *word;
 	gint i;
 
-	printf("Camel text index tester!\n");
+	printf ("Camel text index tester!\n");
 
-	g_thread_init(NULL);
-	camel_init(NULL, 0);
+	g_thread_init (NULL);
+	camel_init (NULL, 0);
 
-	idx = (CamelIndex *)camel_text_index_new("textindex", O_CREAT|O_RDWR|O_TRUNC);
+	idx = (CamelIndex *)camel_text_index_new ("textindex", O_CREAT|O_RDWR|O_TRUNC);
 
 #if 1
-	camel_index_compress(idx);
+	camel_index_compress (idx);
 
 	return 0;
 #endif
@@ -1852,115 +1934,115 @@ gint main(gint argc, gchar **argv)
 	for (i=0;i<100;i++) {
 		gchar name[16];
 
-		sprintf(name, "%d", i);
-		printf("Adding words to name '%s'\n", name);
-		idn = camel_index_add_name(idx, name);
-		camel_index_name_add_buffer(idn, wordbuffer, sizeof(wordbuffer)-1);
-		camel_index_write_name(idx, idn);
-		camel_object_unref((CamelObject *)idn);
+		sprintf (name, "%d", i);
+		printf ("Adding words to name '%s'\n", name);
+		idn = camel_index_add_name (idx, name);
+		camel_index_name_add_buffer (idn, wordbuffer, sizeof (wordbuffer)-1);
+		camel_index_write_name (idx, idn);
+		g_object_unref (idn);
 	}
 
-	printf("Looking up which names contain word 'word'\n");
-	idc = camel_index_find(idx, "words");
-	while ( (word = camel_index_cursor_next(idc)) != NULL ) {
-		printf(" name is '%s'\n", word);
+	printf ("Looking up which names contain word 'word'\n");
+	idc = camel_index_find (idx, "words");
+	while ( (word = camel_index_cursor_next (idc)) != NULL ) {
+		printf (" name is '%s'\n", word);
 	}
-	camel_object_unref((CamelObject *)idc);
-	printf("done.\n");
+	g_object_unref (idc);
+	printf ("done.\n");
 
-	printf("Looking up which names contain word 'truncate'\n");
-	idc = camel_index_find(idx, "truncate");
-	while ( (word = camel_index_cursor_next(idc)) != NULL ) {
-		printf(" name is '%s'\n", word);
+	printf ("Looking up which names contain word 'truncate'\n");
+	idc = camel_index_find (idx, "truncate");
+	while ( (word = camel_index_cursor_next (idc)) != NULL ) {
+		printf (" name is '%s'\n", word);
 	}
-	camel_object_unref((CamelObject *)idc);
-	printf("done.\n");
+	g_object_unref (idc);
+	printf ("done.\n");
 
-	camel_index_sync(idx);
-	camel_object_unref((CamelObject *)idx);
+	camel_index_sync (idx);
+	g_object_unref (idx);
 
 #if 0
-	bs = camel_block_file_new("blocks", "TESTINDX", CAMEL_BLOCK_SIZE);
+	bs = camel_block_file_new ("blocks", "TESTINDX", CAMEL_BLOCK_SIZE);
 
 	root = (struct _CamelIndexRoot *)bs->root;
 	if (root->word_root == 0) {
-		keyroot = camel_block_file_new_block(bs);
+		keyroot = camel_block_file_new_block (bs);
 		root->word_root = keyroot->id;
-		camel_block_file_touch_block(bs, bs->root_block);
+		camel_block_file_touch_block (bs, bs->root_block);
 	}
 	if (root->word_hash_root == 0) {
-		partroot = camel_block_file_new_block(bs);
+		partroot = camel_block_file_new_block (bs);
 		root->word_hash_root = partroot->id;
-		camel_block_file_touch_block(bs, bs->root_block);
+		camel_block_file_touch_block (bs, bs->root_block);
 	}
 
-	ki = camel_key_table_new(bs, root->word_root);
-	cpi = camel_partition_table_new(bs, root->word_hash_root);
+	ki = camel_key_table_new (bs, root->word_root);
+	cpi = camel_partition_table_new (bs, root->word_hash_root);
 
-	fp = fopen("/usr/dict/words", "r");
+	fp = fopen ("/usr/dict/words", "r");
 	if (fp == NULL) {
-		perror("fopen");
+		perror ("fopen");
 		return 1;
 	}
 
-	while (fgets(line, sizeof(line), fp) != NULL) {
-		line[strlen(line)-1] = 0;
+	while (fgets (line, sizeof (line), fp) != NULL) {
+		line[strlen (line)-1] = 0;
 
 		/* see if its already there */
-		keyid = camel_partition_table_lookup(cpi, line);
+		keyid = camel_partition_table_lookup (cpi, line);
 		if (keyid == 0) {
-			m(printf("Adding word '%s' %d\n", line, index));
+			m (printf ("Adding word '%s' %d\n", line, index));
 
-			keyid = camel_key_table_add(ki, line, index, 0);
-			m(printf(" key = %08x\n", keyid));
+			keyid = camel_key_table_add (ki, line, index, 0);
+			m (printf (" key = %08x\n", keyid));
 
-			camel_partition_table_add(cpi, line, keyid);
+			camel_partition_table_add (cpi, line, keyid);
 
-			m(printf("Lookup word '%s'\n", line));
-			keyid = camel_partition_table_lookup(cpi, line);
-			m(printf(" key = %08x\n", keyid));
+			m (printf ("Lookup word '%s'\n", line));
+			keyid = camel_partition_table_lookup (cpi, line);
+			m (printf (" key = %08x\n", keyid));
 		}
 
-		m(printf("Lookup key %08x\n", keyid));
+		m (printf ("Lookup key %08x\n", keyid));
 
-		camel_key_table_set_flags(ki, keyid, index, 1);
+		camel_key_table_set_flags (ki, keyid, index, 1);
 
-		data = camel_key_table_lookup(ki, keyid, &key, &flags);
-		m(printf(" word = '%s' %d %04x\n", key, data, flags));
+		data = camel_key_table_lookup (ki, keyid, &key, &flags);
+		m (printf (" word = '%s' %d %04x\n", key, data, flags));
 
-		g_assert(data == index && strcmp(key, line) == 0);
+		g_assert (data == index && strcmp (key, line) == 0);
 
-		g_free(key);
+		g_free (key);
 
 		index++;
 	}
 
-	printf("Scanning again\n");
-	fseek(fp, SEEK_SET, 0);
+	printf ("Scanning again\n");
+	fseek (fp, SEEK_SET, 0);
 	index = 0;
-	while (fgets(line, sizeof(line), fp) != NULL) {
-		line[strlen(line)-1] = 0;
-		m(printf("Lookup word '%s' %d\n", line, index));
-		keyid = camel_partition_table_lookup(cpi, line);
-		m(printf(" key = %08d\n", keyid));
+	while (fgets (line, sizeof (line), fp) != NULL) {
+		line[strlen (line)-1] = 0;
+		m (printf ("Lookup word '%s' %d\n", line, index));
+		keyid = camel_partition_table_lookup (cpi, line);
+		m (printf (" key = %08d\n", keyid));
 
-		m(printf("Lookup key %08x\n", keyid));
-		data = camel_key_table_lookup(ki, keyid, &key, &flags);
-		m(printf(" word = '%s' %d\n", key, data));
+		m (printf ("Lookup key %08x\n", keyid));
+		data = camel_key_table_lookup (ki, keyid, &key, &flags);
+		m (printf (" word = '%s' %d\n", key, data));
 
-		g_assert(data == index && strcmp(key, line) == 0);
+		g_assert (data == index && strcmp (key, line) == 0);
 
-		g_free(key);
+		g_free (key);
 
 		index++;
 	}
 	fclose (fp);
 
-	printf("Freeing partition index\n");
-	camel_partition_table_free(cpi);
+	printf ("Freeing partition index\n");
+	camel_partition_table_free (cpi);
 
-	printf("Syncing block file\n");
-	camel_block_file_sync(bs);
+	printf ("Syncing block file\n");
+	camel_block_file_sync (bs);
 #endif
 	return 0;
 }
diff --git a/camel/camel-text-index.h b/camel/camel-text-index.h
index 01b0078..48c5c6a 100644
--- a/camel/camel-text-index.h
+++ b/camel/camel-text-index.h
@@ -19,30 +19,107 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_TEXT_INDEX_H
-#define _CAMEL_TEXT_INDEX_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_TEXT_INDEX_H
+#define CAMEL_TEXT_INDEX_H
 
 #include <camel/camel-exception.h>
 #include <camel/camel-object.h>
 #include "camel-index.h"
 
-#define CAMEL_TEXT_INDEX(obj)         CAMEL_CHECK_CAST (obj, camel_text_index_get_type (), CamelTextIndex)
-#define CAMEL_TEXT_INDEX_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_text_index_get_type (), CamelTextIndexClass)
-#define CAMEL_IS_TEXT_INDEX(obj)      CAMEL_CHECK_TYPE (obj, camel_text_index_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_TEXT_INDEX \
+	(camel_text_index_get_type ())
+#define CAMEL_TEXT_INDEX(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TEXT_INDEX, CamelTextIndex))
+#define CAMEL_TEXT_INDEX_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TEXT_INDEX, CamelTextIndexClass))
+#define CAMEL_IS_TEXT_INDEX(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TEXT_INDEX))
+#define CAMEL_IS_TEXT_INDEX_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TEXT_INDEX))
+#define CAMEL_TEXT_INDEX_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TEXT_INDEX, CamelTextIndexClass))
+
+#define CAMEL_TYPE_TEXT_INDEX_NAME \
+	(camel_text_index_name_get_type ())
+#define CAMEL_TEXT_INDEX_NAME(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TEXT_INDEX_NAME, CamelTextIndexName))
+#define CAMEL_TEXT_INDEX_NAME_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TEXT_INDEX_NAME, CamelTextIndexNameClass))
+#define CAMEL_IS_TEXT_INDEX_NAME(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TEXT_INDEX_NAME))
+#define CAMEL_IS_TEXT_INDEX_NAME_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TEXT_INDEX_NAME))
+#define CAMEL_TEXT_INDEX_NAME_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TEXT_INDEX_NAME, CamelTextIndexNameClass))
+
+#define CAMEL_TYPE_TEXT_INDEX_CURSOR \
+	(camel_text_index_cursor_get_type ())
+#define CAMEL_TEXT_INDEX_CURSOR(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TEXT_INDEX_CURSOR, CamelTextIndexCursor))
+#define CAMEL_TEXT_INDEX_CURSOR_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TEXT_INDEX_CURSOR, CamelTextIndexCursorClass))
+#define CAMEL_IS_TEXT_INDEX_CURSOR(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TEXT_INDEX_CURSOR))
+#define CAMEL_IS_TEXT_INDEX_CURSOR_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TEXT_INDEX_CURSOR))
+#define CAMEL_TEXT_INDEX_CURSOR_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TEXT_INDEX_CURSOR, CamelTextIndexCursorClass))
+
+#define CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR \
+	(camel_text_index_key_cursor_get_type ())
+#define CAMEL_TEXT_INDEX_KEY_CURSOR(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR, CamelTextIndexKeyCursor))
+#define CAMEL_TEXT_INDEX_KEY_CURSOR_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR, CamelTextIndexKeyCursorClass))
+#define CAMEL_IS_TEXT_INDEX_KEY_CURSOR(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR))
+#define CAMEL_IS_TEXT_INDEX_KEY_CURSOR_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR))
+#define CAMEL_TEXT_INDEX_KEY_CURSOR_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR, CamelTextIndexKeyCursorClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelTextIndex      CamelTextIndex;
+typedef struct _CamelTextIndex CamelTextIndex;
 typedef struct _CamelTextIndexClass CamelTextIndexClass;
+typedef struct _CamelTextIndexPrivate CamelTextIndexPrivate;
 
-typedef struct _CamelTextIndexName      CamelTextIndexName;
+typedef struct _CamelTextIndexName CamelTextIndexName;
 typedef struct _CamelTextIndexNameClass CamelTextIndexNameClass;
+typedef struct _CamelTextIndexNamePrivate CamelTextIndexNamePrivate;
 
-typedef struct _CamelTextIndexCursor      CamelTextIndexCursor;
+typedef struct _CamelTextIndexCursor CamelTextIndexCursor;
 typedef struct _CamelTextIndexCursorClass CamelTextIndexCursorClass;
+typedef struct _CamelTextIndexCursorPrivate CamelTextIndexCursorPrivate;
 
-typedef struct _CamelTextIndexKeyCursor      CamelTextIndexKeyCursor;
+typedef struct _CamelTextIndexKeyCursor CamelTextIndexKeyCursor;
 typedef struct _CamelTextIndexKeyCursorClass CamelTextIndexKeyCursorClass;
+typedef struct _CamelTextIndexKeyCursorPrivate CamelTextIndexKeyCursorPrivate;
 
 typedef void (*CamelTextIndexFunc)(CamelTextIndex *idx, const gchar *word, gchar *buffer);
 
@@ -50,57 +127,53 @@ typedef void (*CamelTextIndexFunc)(CamelTextIndex *idx, const gchar *word, gchar
 
 struct _CamelTextIndexCursor {
 	CamelIndexCursor parent;
-
-	struct _CamelTextIndexCursorPrivate *priv;
+	CamelTextIndexCursorPrivate *priv;
 };
 
 struct _CamelTextIndexCursorClass {
-	CamelIndexCursorClass parent;
+	CamelIndexCursorClass parent_class;
 };
 
-CamelType camel_text_index_cursor_get_type(void);
+GType camel_text_index_cursor_get_type(void);
 
 /* ********************************************************************** */
 
 struct _CamelTextIndexKeyCursor {
 	CamelIndexCursor parent;
-
-	struct _CamelTextIndexKeyCursorPrivate *priv;
+	CamelTextIndexKeyCursorPrivate *priv;
 };
 
 struct _CamelTextIndexKeyCursorClass {
-	CamelIndexCursorClass parent;
+	CamelIndexCursorClass parent_class;
 };
 
-CamelType camel_text_index_key_cursor_get_type(void);
+GType camel_text_index_key_cursor_get_type(void);
 
 /* ********************************************************************** */
 
 struct _CamelTextIndexName {
 	CamelIndexName parent;
-
-	struct _CamelTextIndexNamePrivate *priv;
+	CamelTextIndexNamePrivate *priv;
 };
 
 struct _CamelTextIndexNameClass {
-	CamelIndexNameClass parent;
+	CamelIndexNameClass parent_class;
 };
 
-CamelType camel_text_index_name_get_type(void);
+GType camel_text_index_name_get_type(void);
 
 /* ********************************************************************** */
 
 struct _CamelTextIndex {
 	CamelIndex parent;
-
-	struct _CamelTextIndexPrivate *priv;
+	CamelTextIndexPrivate *priv;
 };
 
 struct _CamelTextIndexClass {
 	CamelIndexClass parent_class;
 };
 
-CamelType		   camel_text_index_get_type	(void);
+GType           camel_text_index_get_type	(void);
 CamelTextIndex    *camel_text_index_new(const gchar *path, gint flags);
 
 /* static utility functions */
@@ -114,4 +187,4 @@ void camel_text_index_validate(CamelTextIndex *idx);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_TEXT_INDEX_H */
+#endif /* CAMEL_TEXT_INDEX_H */
diff --git a/camel/camel-transport.c b/camel/camel-transport.c
index eac38e5..986fd8d 100644
--- a/camel/camel-transport.c
+++ b/camel/camel-transport.c
@@ -32,77 +32,63 @@
 #include "camel-private.h"
 #include "camel-transport.h"
 
-static CamelServiceClass *parent_class = NULL;
+#define CAMEL_TRANSPORT_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_TRANSPORT, CamelTransportPrivate))
 
-/* 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 gpointer parent_class;
 
 static void
-camel_transport_class_init (CamelTransportClass *camel_transport_class)
+transport_finalize (GObject *object)
 {
-	CamelObjectClass *camel_object_class = CAMEL_OBJECT_CLASS (camel_transport_class);
+	CamelTransportPrivate *priv;
+
+	priv = CAMEL_TRANSPORT_GET_PRIVATE (object);
 
-	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;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_transport_init (gpointer object, gpointer klass)
+transport_class_init (CamelTransportClass *class)
 {
-	CamelTransport *xport = object;
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelTransportPrivate));
 
-	xport->priv = g_malloc0 (sizeof (struct _CamelTransportPrivate));
-	xport->priv->send_lock = g_mutex_new ();
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = transport_finalize;
 }
 
 static void
-camel_transport_finalize (CamelObject *object)
+transport_init (CamelTransport *transport)
 {
-	CamelTransport *xport = CAMEL_TRANSPORT (object);
+	transport->priv = CAMEL_TRANSPORT_GET_PRIVATE (transport);
 
-	g_mutex_free (xport->priv->send_lock);
-	g_free (xport->priv);
+	transport->priv->send_lock = g_mutex_new ();
 }
 
-CamelType
+GType
 camel_transport_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_SERVICE_TYPE,
-					    "CamelTransport",
-					    sizeof (CamelTransport),
-					    sizeof (CamelTransportClass),
-					    (CamelObjectClassInitFunc) camel_transport_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_transport_init,
-					    (CamelObjectFinalizeFunc) camel_transport_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_SERVICE,
+			"CamelTransport",
+			sizeof (CamelTransportClass),
+			(GClassInitFunc) transport_class_init,
+			sizeof (CamelTransport),
+			(GInstanceInitFunc) transport_init,
+			0);
 
 	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 +104,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 +118,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 3c3bbac..3656287 100644
--- a/camel/camel-transport.h
+++ b/camel/camel-transport.h
@@ -23,38 +23,59 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_TRANSPORT_H
-#define CAMEL_TRANSPORT_H 1
+#define CAMEL_TRANSPORT_H
 
-#include <glib.h>
+#include <camel/camel-address.h>
+#include <camel/camel-mime-message.h>
 #include <camel/camel-service.h>
 
-#define CAMEL_TRANSPORT_TYPE     (camel_transport_get_type ())
-#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))
+/* Standard GObject macros */
+#define CAMEL_TYPE_TRANSPORT \
+	(camel_transport_get_type ())
+#define CAMEL_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TRANSPORT, CamelTransport))
+#define CAMEL_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TRANSPORT, CamelTransportClass))
+#define CAMEL_IS_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TRANSPORT))
+#define CAMEL_IS_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TRANSPORT))
+#define CAMEL_TRANSPORT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TRANSPORT, CamelTransportClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelTransport CamelTransport;
+typedef struct _CamelTransportClass CamelTransportClass;
+typedef struct _CamelTransportPrivate CamelTransportPrivate;
+
 enum {
 	CAMEL_TRANSPORT_ARG_FIRST  = CAMEL_SERVICE_ARG_FIRST + 100
 };
 
-struct _CamelTransport
-{
-	CamelService parent_object;
-
-	struct _CamelTransportPrivate *priv;
+struct _CamelTransport {
+	CamelService parent;
+	CamelTransportPrivate *priv;
 };
 
-typedef struct {
+struct _CamelTransportClass {
 	CamelServiceClass parent_class;
 
 	gboolean (*send_to) (CamelTransport *transport,
 			     CamelMimeMessage *message,
 			     CamelAddress *from, CamelAddress *recipients,
 			     CamelException *ex);
-} CamelTransportClass;
+};
 
 /* public methods */
 gboolean camel_transport_send_to (CamelTransport *transport,
@@ -63,8 +84,7 @@ gboolean camel_transport_send_to (CamelTransport *transport,
 				  CamelAddress *recipients,
 				  CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_transport_get_type (void);
+GType camel_transport_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/camel-trie.h b/camel/camel-trie.h
index a81a2cd..84d07ce 100644
--- a/camel/camel-trie.h
+++ b/camel/camel-trie.h
@@ -18,6 +18,10 @@
  *
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_TRIE_H
 #define CAMEL_TRIE_H
 
diff --git a/camel/camel-uid-cache.c b/camel/camel-uid-cache.c
index 1ebdd47..0a5c5a5 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 <libedataserver/e-data-server-util.h>
diff --git a/camel/camel-uid-cache.h b/camel/camel-uid-cache.h
index 9acc06b..ef0d477 100644
--- a/camel/camel-uid-cache.h
+++ b/camel/camel-uid-cache.h
@@ -22,8 +22,12 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_UID_CACHE_H
-#define CAMEL_UID_CACHE_H 1
+#define CAMEL_UID_CACHE_H
 
 #include <glib.h>
 
diff --git a/camel/camel-url-scanner.h b/camel/camel-url-scanner.h
index 249f414..2a1d6b4 100644
--- a/camel/camel-url-scanner.h
+++ b/camel/camel-url-scanner.h
@@ -20,8 +20,12 @@
  *
  */
 
-#ifndef __CAMEL_URL_SCANNER_H__
-#define __CAMEL_URL_SCANNER_H__
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_URL_SCANNER_H
+#define CAMEL_URL_SCANNER_H
 
 #include <glib.h>
 #include <sys/types.h>
@@ -63,4 +67,4 @@ gboolean camel_url_scanner_scan (CamelUrlScanner *scanner, const gchar *in, gsiz
 
 G_END_DECLS
 
-#endif /* __CAMEL_URL_SCANNER_H__ */
+#endif /* CAMEL_URL_SCANNER_H */
diff --git a/camel/camel-url.c b/camel/camel-url.c
index e9b637d..96399a8 100644
--- a/camel/camel-url.c
+++ b/camel/camel-url.c
@@ -32,7 +32,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
diff --git a/camel/camel-url.h b/camel/camel-url.h
index afce4e2..d326bdb 100644
--- a/camel/camel-url.h
+++ b/camel/camel-url.h
@@ -23,11 +23,14 @@
  * USA
  */
 
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
 #ifndef CAMEL_URL_H
-#define CAMEL_URL_H 1
+#define CAMEL_URL_H
 
-#include <glib.h>
-#include <camel/camel-types.h>
+#include <camel/camel-exception.h>
 
 G_BEGIN_DECLS
 
diff --git a/camel/camel-utf8.h b/camel/camel-utf8.h
index 24c7221..d454bcd 100644
--- a/camel/camel-utf8.h
+++ b/camel/camel-utf8.h
@@ -20,8 +20,12 @@
  *
  */
 
-#ifndef _CAMEL_UTF8_H
-#define _CAMEL_UTF8_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_UTF8_H
+#define CAMEL_UTF8_H
 
 G_BEGIN_DECLS
 
@@ -45,4 +49,4 @@ gchar *camel_utf8_make_valid (const gchar *text);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_UTF8_H */
+#endif /* CAMEL_UTF8_H */
diff --git a/camel/camel-vee-folder.c b/camel/camel-vee-folder.c
index 6ef8718..6e85435 100644
--- a/camel/camel-vee-folder.c
+++ b/camel/camel-vee-folder.c
@@ -26,7 +26,6 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-db.h"
@@ -44,450 +43,639 @@
 #include "camel-vee-folder.h"
 
 #define d(x)
-#define dd(x) (camel_debug("vfolder")?(x):0)
+#define dd(x) (camel_debug ("vfolder")?(x):0)
 
-#define _PRIVATE(o) (((CamelVeeFolder *)(o))->priv)
+#define CAMEL_VEE_FOLDER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_VEE_FOLDER, CamelVeeFolderPrivate))
 
-#if 0
-static void vee_refresh_info(CamelFolder *folder, CamelException *ex);
-
-static void vee_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
-static void vee_expunge (CamelFolder *folder, CamelException *ex);
-
-static void vee_freeze(CamelFolder *folder);
-static void vee_thaw(CamelFolder *folder);
-
-static CamelMimeMessage *vee_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex);
-static void vee_append_message(CamelFolder *folder, CamelMimeMessage *message, const CamelMessageInfo *info, gchar **appended_uid, CamelException *ex);
-static void vee_transfer_messages_to(CamelFolder *source, GPtrArray *uids, CamelFolder *dest, GPtrArray **transferred_uids, gboolean delete_originals, CamelException *ex);
-
-static guint32 vee_count_by_expression(CamelFolder *folder, const gchar *expression, CamelException *ex);
-static GPtrArray *vee_search_by_expression(CamelFolder *folder, const gchar *expression, CamelException *ex);
-static GPtrArray *vee_search_by_uids(CamelFolder *folder, const gchar *expression, GPtrArray *uids, CamelException *ex);
-
-static void vee_rename(CamelFolder *folder, const gchar *new);
-#endif
-
-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 gint vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex);
-static void vee_folder_remove_folder(CamelVeeFolder *vf, CamelFolder *source);
+struct _update_data {
+	CamelFolder *source;
+	CamelVeeFolder *vee_folder;
+	gchar hash[8];
+	CamelVeeFolder *folder_unmatched;
+	GHashTable *unmatched_uids;
+	gboolean rebuilt, correlating;
+};
 
-static void folder_changed(CamelFolder *sub, CamelFolderChangeInfo *changes, CamelVeeFolder *vf);
-static void subfolder_deleted(CamelFolder *f, gpointer event_data, CamelVeeFolder *vf);
-static void folder_renamed(CamelFolder *f, const gchar *old, CamelVeeFolder *vf);
+static gpointer parent_class;
 
-static CamelFolderClass *camel_vee_folder_parent;
+struct _folder_changed_msg {
+	CamelSessionThreadMsg msg;
+	CamelFolderChangeInfo *changes;
+	CamelFolder *sub;
+	CamelVeeFolder *vee_folder;
+};
 
-CamelType
-camel_vee_folder_get_type (void)
+/* must be called with summary_lock held */
+static CamelVeeMessageInfo *
+vee_folder_add_uid (CamelVeeFolder *vf,
+                    CamelFolder *f,
+                    const gchar *inuid,
+                    const gchar hash[8])
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	CamelVeeMessageInfo *mi = NULL;
 
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_folder_get_type (), "CamelVeeFolder",
-					    sizeof (CamelVeeFolder),
-					    sizeof (CamelVeeFolderClass),
-					    (CamelObjectClassInitFunc) camel_vee_folder_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_vee_folder_init,
-					    (CamelObjectFinalizeFunc) camel_vee_folder_finalise);
-	}
+	mi = camel_vee_summary_add ((CamelVeeSummary *)((CamelFolder *)vf)->summary, f->summary, (gchar *)inuid, hash);
+	return mi;
+}
 
-	return type;
+/* A "correlating" expression has the property that whether a message matches
+ * depends on the other messages being searched.  folder_changed_change on a
+ * vfolder with a correlating expression may not make all the necessary updates,
+ * so the query is redone on the entire changed source folder the next time
+ * the vfolder is opened.
+ *
+ * The only current example of a correlating expression is one that uses
+ * "match-threads". */
+static gboolean
+expression_is_correlating (const gchar *expr)
+{
+	/* XXX: Actually parse the expression to avoid triggering on
+	 * "match-threads" in the text the user is searching for! */
+	return (strstr (expr, "match-threads") != NULL);
 }
 
-void
-camel_vee_folder_construct (CamelVeeFolder *vf, CamelStore *parent_store, const gchar *full, const gchar *name, guint32 flags)
+/* Hold all these with summary lock and unmatched summary lock held */
+static void
+folder_changed_add_uid (CamelFolder *sub, const gchar *uid, const gchar hash[8], CamelVeeFolder *vf, gboolean use_db)
 {
 	CamelFolder *folder = (CamelFolder *)vf;
+	CamelVeeMessageInfo *vinfo;
+	const gchar *vuid;
+	gchar *oldkey;
+	gpointer oldval;
+	gint n;
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
+	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
 
-	vf->flags = flags;
-	camel_folder_construct(folder, parent_store, full, name);
-
-	folder->summary = camel_vee_summary_new(folder);
+	vinfo = vee_folder_add_uid (vf, sub, uid, hash);
+	if (vinfo == NULL)
+		return;
 
-	if (CAMEL_IS_VEE_STORE(parent_store))
-		vf->parent_vee_store = (CamelVeeStore *)parent_store;
+	vuid = camel_message_info_uid (vinfo);
+	if (use_db) {
+		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+		camel_db_add_to_vfolder_transaction (folder->parent_store->cdb_w, folder->full_name, (gchar *)vuid, &ex);
+		camel_exception_clear (&ex);
+	}
+	camel_folder_change_info_add_uid (vf->changes,  vuid);
+	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER (sub) && folder_unmatched != NULL) {
+		if (g_hash_table_lookup_extended (unmatched_uids, vuid, (gpointer *)&oldkey, &oldval)) {
+			n = GPOINTER_TO_INT (oldval);
+			g_hash_table_insert (unmatched_uids, oldkey, GINT_TO_POINTER (n+1));
+		} else {
+			g_hash_table_insert (unmatched_uids, g_strdup (vuid), GINT_TO_POINTER (1));
+		}
+		vinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info ((CamelFolder *)folder_unmatched, vuid);
+		if (vinfo) {
+			CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+			camel_folder_change_info_remove_uid (folder_unmatched->changes, vuid);
+			camel_db_delete_uid_from_vfolder_transaction (folder->parent_store->cdb_w, ((CamelFolder *)folder_unmatched)->full_name, vuid, &ex);
+			camel_folder_summary_remove_uid_fast (((CamelFolder *)folder_unmatched)->summary, vuid);
+			camel_folder_free_message_info ((CamelFolder *)folder_unmatched, (CamelMessageInfo *)vinfo);
+			camel_exception_clear (&ex);
+		}
+	}
 }
 
-/**
- * camel_vee_folder_new:
- * @parent_store: the parent CamelVeeStore
- * @full: the full path to the vfolder.
- * @flags: flags of some kind
- *
- * Create a new CamelVeeFolder object.
- *
- * Return value: A new CamelVeeFolder widget.
- **/
-CamelFolder *
-camel_vee_folder_new(CamelStore *parent_store, const gchar *full, guint32 flags)
+static void
+folder_changed_remove_uid (CamelFolder *sub, const gchar *uid, const gchar hash[8], gint keep, CamelVeeFolder *vf, gboolean use_db)
 {
-	CamelVeeFolder *vf;
-	gchar *tmp;
+	CamelFolder *folder = (CamelFolder *)vf;
+	gchar *vuid, *oldkey;
+	gpointer oldval;
+	gint n;
+	CamelVeeMessageInfo *vinfo;
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
+	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
 
-	if (CAMEL_IS_VEE_STORE(parent_store) && strcmp(full, CAMEL_UNMATCHED_NAME) == 0) {
-		vf = ((CamelVeeStore *)parent_store)->folder_unmatched;
-		camel_object_ref(vf);
-	} else {
-		const gchar *name = strrchr(full, '/');
+	vuid = alloca (strlen (uid)+9);
+	memcpy (vuid, hash, 8);
+	strcpy (vuid+8, uid);
 
-		if (name == NULL)
-			name = full;
-		else
-			name++;
-		vf = (CamelVeeFolder *)camel_object_new(camel_vee_folder_get_type());
-		camel_vee_folder_construct(vf, parent_store, full, name, flags);
+	camel_folder_change_info_remove_uid (vf->changes, vuid);
+	if (use_db) {
+		/* FIXME[disk-summary] Handle exception */
+		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+		camel_db_delete_uid_from_vfolder_transaction (folder->parent_store->cdb_w, folder->full_name, vuid, &ex);
+		camel_exception_clear (&ex);
 	}
+	camel_folder_summary_remove_uid_fast (folder->summary, vuid);
 
-	d(printf("returning folder %s %p, count = %d\n", full, vf, camel_folder_get_message_count((CamelFolder *)vf)));
+	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER (sub) && folder_unmatched != NULL) {
+		if (keep) {
+			if (g_hash_table_lookup_extended (unmatched_uids, vuid, (gpointer *)&oldkey, &oldval)) {
+				n = GPOINTER_TO_INT (oldval);
+				if (n == 1) {
+					g_hash_table_remove (unmatched_uids, oldkey);
+					if (vee_folder_add_uid (folder_unmatched, sub, uid, hash))
+						camel_folder_change_info_add_uid (folder_unmatched->changes, oldkey);
+					g_free (oldkey);
+				} else {
+					g_hash_table_insert (unmatched_uids, oldkey, GINT_TO_POINTER (n-1));
+				}
+			} else {
+				if (vee_folder_add_uid (folder_unmatched, sub, uid, hash))
+					camel_folder_change_info_add_uid (folder_unmatched->changes, oldkey);
+			}
+		} else {
+			if (g_hash_table_lookup_extended (unmatched_uids, vuid, (gpointer *)&oldkey, &oldval)) {
+				g_hash_table_remove (unmatched_uids, oldkey);
+				g_free (oldkey);
+			}
 
-	if (vf) {
-		tmp = g_strdup_printf("%s/%s.cmeta", ((CamelService *)parent_store)->url->path, full);
-		camel_object_set(vf, NULL, CAMEL_OBJECT_STATE_FILE, tmp, NULL);
-		g_free(tmp);
-		if (camel_object_state_read(vf) == -1) {
-			/* setup defaults: we have none currently */
+			vinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info ((CamelFolder *)folder_unmatched, vuid);
+			if (vinfo) {
+				CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+				camel_folder_change_info_remove_uid (folder_unmatched->changes, vuid);
+				camel_db_delete_uid_from_vfolder_transaction (folder->parent_store->cdb_w, ((CamelFolder *)folder_unmatched)->full_name, vuid, &ex);
+				camel_folder_summary_remove_uid_fast (((CamelFolder *)folder_unmatched)->summary, vuid);
+				camel_folder_free_message_info ((CamelFolder *)folder_unmatched, (CamelMessageInfo *)vinfo);
+				camel_exception_clear (&ex);
+			}
 		}
 	}
-	return (CamelFolder *)vf;
 }
 
-void
-camel_vee_folder_set_expression(CamelVeeFolder *vf, const gchar *query)
-{
-	((CamelVeeFolderClass *)((CamelObject *)vf)->klass)->set_expression(vf, query);
-}
-
-/**
- * camel_vee_folder_add_folder:
- * @vf: Virtual Folder object
- * @sub: source CamelFolder to add to @vf
- *
- * Adds @sub as a source folder to @vf.
- **/
-void
-camel_vee_folder_add_folder(CamelVeeFolder *vf, CamelFolder *sub)
+static void
+folder_changed_change_uid (CamelFolder *sub, const gchar *uid, const gchar hash[8], CamelVeeFolder *vf, gboolean use_db)
 {
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	gint i;
+	gchar *vuid;
+	CamelVeeMessageInfo *vinfo, *uinfo = NULL;
+	CamelMessageInfo *info;
+	CamelFolder *folder = (CamelFolder *)vf;
 	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
 
-	if (vf == (CamelVeeFolder *)sub) {
-		g_warning("Adding a virtual folder to itself as source, ignored");
-		return;
-	}
+	vuid = alloca (strlen (uid)+9);
+	memcpy (vuid, hash, 8);
+	strcpy (vuid+8, uid);
 
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
+	vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid (folder->summary, vuid);
+	if (folder_unmatched != NULL)
+		uinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid (((CamelFolder *)folder_unmatched)->summary, vuid);
+	if (vinfo || uinfo) {
+		info = camel_folder_get_message_info (sub, uid);
+		if (info) {
+			if (vinfo) {
+				camel_folder_change_info_change_uid (vf->changes, vuid);
+				camel_message_info_free ((CamelMessageInfo *)vinfo);
+			}
 
-	/* for normal vfolders we want only unique ones, for unmatched we want them all recorded */
-	if (g_list_find(p->folders, sub) == NULL) {
-		camel_object_ref((CamelObject *)sub);
-		p->folders = g_list_append(p->folders, sub);
+			if (uinfo) {
+				camel_folder_change_info_change_uid (folder_unmatched->changes, vuid);
+				camel_message_info_free ((CamelMessageInfo *)uinfo);
+			}
 
-		CAMEL_FOLDER_LOCK(vf, change_lock);
+			camel_folder_free_message_info (sub, info);
+		} else {
+			if (vinfo) {
+				folder_changed_remove_uid (sub, uid, hash, FALSE, vf, use_db);
+				camel_message_info_free ((CamelMessageInfo *)vinfo);
+			}
+			if (uinfo)
+				camel_message_info_free ((CamelMessageInfo *)uinfo);
+		}
+	}
+}
 
-		/* update the freeze state of 'sub' to match our freeze state */
-		for (i = 0; i < ((CamelFolder *)vf)->priv->frozen; i++)
-			camel_folder_freeze(sub);
+static void
+folder_changed_change (CamelSession *session, CamelSessionThreadMsg *msg)
+{
+	struct _folder_changed_msg *m = (struct _folder_changed_msg *)msg;
+	CamelFolder *sub = m->sub;
+	CamelFolder *folder = (CamelFolder *)m->vee_folder;
+	CamelVeeFolder *vf = m->vee_folder;
+	CamelFolderChangeInfo *changes = m->changes;
+	gchar *vuid = NULL, hash[8];
+	const gchar *uid;
+	CamelVeeMessageInfo *vinfo;
+	gint i, vuidlen = 0;
+	CamelFolderChangeInfo *vf_changes = NULL, *unmatched_changes = NULL;
+	GPtrArray *matches_added = NULL, /* newly added, that match */
+		*matches_changed = NULL, /* newly changed, that now match */
+		*newchanged = NULL,
+		*changed;
+	GPtrArray *always_changed = NULL;
+	GHashTable *matches_hash;
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
+	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
+	GPtrArray *present = NULL;
 
-		CAMEL_FOLDER_UNLOCK(vf, change_lock);
+	/* See vee_folder_rebuild_folder. */
+	gboolean correlating = expression_is_correlating (vf->expression);
+
+	/* Check the folder hasn't beem removed while we weren't watching */
+	CAMEL_VEE_FOLDER_LOCK (vf, subfolder_lock);
+	if (g_list_find (CAMEL_VEE_FOLDER_GET_PRIVATE (vf)->folders, sub) == NULL) {
+		CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
+		return;
 	}
-	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER(sub) && folder_unmatched != NULL) {
-		struct _CamelVeeFolderPrivate *up = _PRIVATE(folder_unmatched);
-		camel_object_ref((CamelObject *)sub);
-		up->folders = g_list_append(up->folders, sub);
 
-		CAMEL_FOLDER_LOCK(folder_unmatched, change_lock);
+	camel_vee_folder_hash_folder (sub, hash);
 
-		/* update the freeze state of 'sub' to match Unmatched's freeze state */
-		for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
-			camel_folder_freeze(sub);
+	/* Lookup anything before we lock anything, to avoid deadlock with build_folder */
 
-		CAMEL_FOLDER_UNLOCK(folder_unmatched, change_lock);
+	/* Find newly added that match */
+	if (changes->uid_added->len > 0) {
+		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+		dd (printf (" Searching for added matches '%s'\n", vf->expression));
+		matches_added = camel_folder_search_by_uids (sub, vf->expression, changes->uid_added, &ex);
+		camel_exception_clear (&ex);
 	}
 
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
-
-	d(printf("camel_vee_folder_add_folder(%s, %s)\n", ((CamelFolder *)vf)->full_name, sub->full_name));
+	/* TODO:
+	   In this code around here, we can work out if the search will affect the changes
+	   we had, and only re-search against them if they might have */
 
-	camel_object_hook_event((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc)folder_changed, vf);
-	camel_object_hook_event((CamelObject *)sub, "deleted", (CamelObjectEventHookFunc)subfolder_deleted, vf);
-	camel_object_hook_event((CamelObject *)sub, "renamed", (CamelObjectEventHookFunc)folder_renamed, vf);
+	/* Search for changed items that newly match, but only if we dont have them */
+	changed = changes->uid_changed;
+	if (changed->len > 0) {
+		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+		dd (printf (" Searching for changed matches '%s'\n", vf->expression));
 
-	((CamelVeeFolderClass *)((CamelObject *)vf)->klass)->add_folder(vf, sub);
+		if ((vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO) == 0) {
+			newchanged = g_ptr_array_new ();
+			always_changed = g_ptr_array_new ();
+			for (i=0;i<changed->len;i++) {
+				uid = changed->pdata[i];
+				if (strlen (uid)+9 > vuidlen) {
+					vuidlen = strlen (uid)+64;
+					vuid = g_realloc (vuid, vuidlen);
+				}
+				memcpy (vuid, hash, 8);
+				strcpy (vuid+8, uid);
+				vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid (folder->summary, vuid);
+				if (vinfo == NULL) {
+					g_ptr_array_add (newchanged, (gchar *)uid);
+				} else {
+					g_ptr_array_add (always_changed, (gchar *)uid);
+					camel_message_info_free ((CamelMessageInfo *)vinfo);
+				}
+			}
+			changed = newchanged;
+		}
 
-}
+		if (changed->len)
+			matches_changed = camel_folder_search_by_uids (sub, vf->expression, changed, &ex);
+		camel_exception_clear (&ex);
+		if (always_changed && always_changed->len)
+			present = camel_folder_search_by_uids (sub, vf->expression, always_changed, &ex);
+		camel_exception_clear (&ex);
+	}
 
-/**
- * camel_vee_folder_remove_folder:
- * @vf: Virtual Folder object
- * @sub: source CamelFolder to remove from @vf
- *
- * Removed the source folder, @sub, from the virtual folder, @vf.
- **/
-void
+	CAMEL_VEE_FOLDER_LOCK (vf, summary_lock);
 
-camel_vee_folder_remove_folder(CamelVeeFolder *vf, CamelFolder *sub)
-{
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	gint i;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
+	if (folder_unmatched != NULL)
+		CAMEL_VEE_FOLDER_LOCK (folder_unmatched, summary_lock);
 
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
+	if (matches_changed || matches_added || changes->uid_removed->len||present)
+		camel_db_begin_transaction (folder->parent_store->cdb_w, NULL);
 
-	CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
-	p->folders_changed = g_list_remove(p->folders_changed, sub);
-	CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
+	dd (printf ("Vfolder '%s' subfolder changed '%s'\n", folder->full_name, sub->full_name));
+	dd (printf (" changed %u added %u removed %u\n", changes->uid_changed->len, changes->uid_added->len, changes->uid_removed->len));
 
-	if (g_list_find(p->folders, sub) == NULL) {
-		CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
-		return;
+	/* Always remove removed uid's, in any case */
+	for (i=0;i<changes->uid_removed->len;i++) {
+		dd (printf ("  removing uid '%s'\n", (gchar *)changes->uid_removed->pdata[i]));
+		folder_changed_remove_uid (sub, changes->uid_removed->pdata[i], hash, FALSE, vf, !correlating);
 	}
 
-	camel_object_unhook_event((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
-	camel_object_unhook_event((CamelObject *)sub, "deleted", (CamelObjectEventHookFunc) subfolder_deleted, vf);
-	camel_object_unhook_event((CamelObject *)sub, "renamed", (CamelObjectEventHookFunc) folder_renamed, vf);
+	/* Add any newly matched or to unmatched folder if they dont */
+	if (matches_added) {
+		matches_hash = g_hash_table_new (g_str_hash, g_str_equal);
+		for (i=0;i<matches_added->len;i++) {
+			dd (printf (" %s", (gchar *)matches_added->pdata[i]));
+			g_hash_table_insert (matches_hash, matches_added->pdata[i], matches_added->pdata[i]);
+		}
+		for (i=0;i<changes->uid_added->len;i++) {
+			uid = changes->uid_added->pdata[i];
+			if (g_hash_table_lookup (matches_hash, uid)) {
+				dd (printf ("  adding uid '%s' [newly matched]\n", (gchar *)uid));
+				folder_changed_add_uid (sub, uid, hash, vf, !correlating);
+			} else if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
+				if (strlen (uid)+9 > vuidlen) {
+					vuidlen = strlen (uid)+64;
+					vuid = g_realloc (vuid, vuidlen);
+				}
+				memcpy (vuid, hash, 8);
+				strcpy (vuid+8, uid);
 
-	p->folders = g_list_remove(p->folders, sub);
+				if (!CAMEL_IS_VEE_FOLDER (sub) && folder_unmatched != NULL && g_hash_table_lookup (unmatched_uids, vuid) == NULL) {
+					dd (printf ("  adding uid '%s' to Unmatched [newly unmatched]\n", (gchar *)uid));
+					vinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info ((CamelFolder *)folder_unmatched, vuid);
+					if (vinfo == NULL) {
+						if (vee_folder_add_uid (folder_unmatched, sub, uid, hash))
+							camel_folder_change_info_add_uid (folder_unmatched->changes, vuid);
+					} else {
+						camel_folder_free_message_info ((CamelFolder *)folder_unmatched, (CamelMessageInfo *)vinfo);
+					}
+				}
+			}
+		}
+		g_hash_table_destroy (matches_hash);
+	}
 
-	/* undo the freeze state that we have imposed on this source folder */
-	CAMEL_FOLDER_LOCK(vf, change_lock);
-	for (i = 0; i < ((CamelFolder *)vf)->priv->frozen; i++)
-		camel_folder_thaw(sub);
-	CAMEL_FOLDER_UNLOCK(vf, change_lock);
+	/* Change any newly changed */
+	if (always_changed) {
+		if (correlating) {
+			/* Messages may be pulled in by the correlation even if
+			 * they do not match the expression individually, so it
+			 * would be wrong to preemptively remove anything here.
+			 * vee_folder_rebuild_folder will make any necessary removals
+			 * when it re-queries the entire source folder. */
+			for (i=0;i<always_changed->len;i++)
+				folder_changed_change_uid (sub, always_changed->pdata[i], hash, vf, !correlating);
+		} else {
+			GHashTable *ht_present = g_hash_table_new (g_str_hash, g_str_equal);
 
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
+			for (i=0;present && i<present->len;i++) {
+				folder_changed_change_uid (sub, present->pdata[i], hash, vf, !correlating);
+				g_hash_table_insert (ht_present, present->pdata[i], present->pdata[i]);
+			}
 
-	if (folder_unmatched != NULL) {
-		struct _CamelVeeFolderPrivate *up = _PRIVATE(folder_unmatched);
+			for (i=0; i<always_changed->len; i++) {
+				if (!present || !g_hash_table_lookup (ht_present, always_changed->pdata[i]))
+					/* XXX: IIUC, these messages haven't been deleted from the
+					 * source folder, so shouldn't "keep" be set to TRUE? */
+					folder_changed_remove_uid (sub, always_changed->pdata[i], hash, TRUE, vf, !correlating);
+			}
 
-		CAMEL_VEE_FOLDER_LOCK(folder_unmatched, subfolder_lock);
-		/* if folder deleted, then blow it away from unmatched always, and remove all refs to it */
-		if (sub->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED) {
-			while (g_list_find(up->folders, sub)) {
-				up->folders = g_list_remove(up->folders, sub);
-				camel_object_unref((CamelObject *)sub);
+			g_hash_table_destroy (ht_present);
+		}
+		g_ptr_array_free (always_changed, TRUE);
+	}
 
-				/* undo the freeze state that Unmatched has imposed on this source folder */
-				CAMEL_FOLDER_LOCK(folder_unmatched, change_lock);
-				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
-					camel_folder_thaw(sub);
-				CAMEL_FOLDER_UNLOCK(folder_unmatched, change_lock);
-			}
-		} else if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
-			if (g_list_find(up->folders, sub) != NULL) {
-				up->folders = g_list_remove(up->folders, sub);
-				camel_object_unref((CamelObject *)sub);
+	/* Change/add/remove any changed */
+	if (changes->uid_changed->len) {
+		/* If we are auto-updating, then re-check changed uids still match */
+		dd (printf (" Vfolder %supdate\nuids match:", (vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO)?"auto-":""));
+		matches_hash = g_hash_table_new (g_str_hash, g_str_equal);
+		for (i=0;matches_changed && i<matches_changed->len;i++) {
+			dd (printf (" %s", (gchar *)matches_changed->pdata[i]));
+			g_hash_table_insert (matches_hash, matches_changed->pdata[i], matches_changed->pdata[i]);
+		}
+		dd (printf ("\n"));
 
-				/* undo the freeze state that Unmatched has imposed on this source folder */
-				CAMEL_FOLDER_LOCK(folder_unmatched, change_lock);
-				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
-					camel_folder_thaw(sub);
-				CAMEL_FOLDER_UNLOCK(folder_unmatched, change_lock);
+		for (i=0;i<changed->len;i++) {
+			uid = changed->pdata[i];
+			if (strlen (uid)+9 > vuidlen) {
+				vuidlen = strlen (uid)+64;
+				vuid = g_realloc (vuid, vuidlen);
+			}
+			memcpy (vuid, hash, 8);
+			strcpy (vuid+8, uid);
+			vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid (folder->summary, vuid);
+			if (vinfo == NULL) {
+				if (g_hash_table_lookup (matches_hash, uid)) {
+					/* A uid we dont have, but now it matches, add it */
+					dd (printf ("  adding uid '%s' [newly matched]\n", uid));
+					folder_changed_add_uid (sub, uid, hash, vf, !correlating);
+				} else {
+					/* A uid we still don't have, just change it (for unmatched) */
+					folder_changed_change_uid (sub, uid, hash, vf, !correlating);
+				}
+			} else {
+				if ((vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO) == 0
+				    || g_hash_table_lookup (matches_hash, uid)) {
+					/* still match, or we're not auto-updating, change event, (if it changed) */
+					dd (printf ("  changing uid '%s' [still matches]\n", uid));
+					folder_changed_change_uid (sub, uid, hash, vf, !correlating);
+				} else {
+					/* No longer matches, remove it, but keep it in unmatched (potentially) */
+					dd (printf ("  removing uid '%s' [did match]\n", uid));
+					folder_changed_remove_uid (sub, uid, hash, TRUE, vf, !correlating);
+				}
+				camel_message_info_free ((CamelMessageInfo *)vinfo);
 			}
 		}
-		CAMEL_VEE_FOLDER_UNLOCK(folder_unmatched, subfolder_lock);
+		g_hash_table_destroy (matches_hash);
+	} else {
+		/* stuff didn't match but it changed - check unmatched folder for changes */
+		for (i=0;i<changed->len;i++)
+			folder_changed_change_uid (sub, changed->pdata[i], hash, vf, !correlating);
 	}
 
-	((CamelVeeFolderClass *)((CamelObject *)vf)->klass)->remove_folder(vf, sub);
+	if (folder_unmatched != NULL) {
+		if (camel_folder_change_info_changed (folder_unmatched->changes)) {
+			unmatched_changes = folder_unmatched->changes;
+			folder_unmatched->changes = camel_folder_change_info_new ();
+		}
 
-	if (CAMEL_IS_VEE_FOLDER(sub))
-		return;
+		CAMEL_VEE_FOLDER_UNLOCK (folder_unmatched, summary_lock);
+	}
 
-	camel_object_unref((CamelObject *)sub);
-}
+	if (camel_folder_change_info_changed (vf->changes)) {
+		vf_changes = vf->changes;
+		vf->changes = camel_folder_change_info_new ();
+	}
 
-/**
- * camel_vee_folder_rebuild_folder:
- * @vf: Virtual Folder object
- * @sub: source CamelFolder to add to @vf
- * @ex: Exception.
- *
- * Rebuild the folder @sub, if it should be.
- **/
-gint
-camel_vee_folder_rebuild_folder(CamelVeeFolder *vf, CamelFolder *sub, CamelException *ex)
-{
-	return ((CamelVeeFolderClass *)((CamelObject *)vf)->klass)->rebuild_folder(vf, sub, ex);
-}
+	if (matches_changed || matches_added || changes->uid_removed->len || present)
+		camel_db_end_transaction (folder->parent_store->cdb_w, NULL);
+	CAMEL_VEE_FOLDER_UNLOCK (vf, summary_lock);
 
-static void
-remove_folders(CamelFolder *folder, CamelFolder *foldercopy, CamelVeeFolder *vf)
-{
-	camel_vee_folder_remove_folder(vf, folder);
-	camel_object_unref((CamelObject *)folder);
-}
+	/* Cleanup stuff on our folder */
+	if (matches_added)
+		camel_folder_search_free (sub, matches_added);
+	if (present)
+		camel_folder_search_free (sub, present);
 
-/**
- * camel_vee_folder_set_folders:
- * @vf:
- * @folders:
- *
- * Set the whole list of folder sources on a vee folder.
- **/
-void
-camel_vee_folder_set_folders(CamelVeeFolder *vf, GList *folders)
-{
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	GHashTable *remove = g_hash_table_new(NULL, NULL);
-	GList *l;
-	CamelFolder *folder;
+	if (matches_changed)
+		camel_folder_search_free (sub, matches_changed);
 
-	/* setup a table of all folders we have currently */
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
-	l = p->folders;
-	while (l) {
-		g_hash_table_insert(remove, l->data, l->data);
-		camel_object_ref((CamelObject *)l->data);
-		l = l->next;
+	CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
+
+	/* cleanup the rest */
+	if (newchanged)
+		g_ptr_array_free (newchanged, TRUE);
+
+	g_free (vuid);
+
+	if (unmatched_changes) {
+		camel_object_trigger_event ((CamelObject *)folder_unmatched, "folder_changed", unmatched_changes);
+		camel_folder_change_info_free (unmatched_changes);
 	}
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
 
-	/* if we already have the folder, ignore it, otherwise add it */
-	l = folders;
-	while (l) {
-		if ((folder = g_hash_table_lookup(remove, l->data))) {
-			g_hash_table_remove(remove, folder);
-			camel_object_unref((CamelObject *)folder);
-		} else {
-			camel_vee_folder_add_folder(vf, l->data);
-		}
-		l = l->next;
+	/* Add to folders_changed if we need to call vee_folder_rebuild_folder, which
+	 * could be the case for two reasons:
+	 * - We changed the vfolder and it is not auto-updating.  Need to re-sync.
+	 * - Vfolder is correlating.  Changes to non-matching source messages
+	 *   won't be processed here and won't show up in vf_changes but may
+	 *   still affect the vfolder contents (e.g., non-matching messages
+	 *   added to a matching thread), so we re-run the query on the whole
+	 *   source folder.  (For match-threads, it may be enough to do this if
+	 *   changes->uid_added->len > 0, but I'm not completely sure and I'd
+	 *   rather be safe than sorry.)
+	 */
+	if ((vf_changes && (vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO) == 0) || correlating) {
+		CAMEL_VEE_FOLDER_LOCK (vf, changed_lock);
+		if (g_list_find (vf->priv->folders_changed, sub) == NULL)
+			vf->priv->folders_changed = g_list_prepend (vf->priv->folders_changed, sub);
+		CAMEL_VEE_FOLDER_UNLOCK (vf, changed_lock);
 	}
 
-	/* then remove any we still have */
-	g_hash_table_foreach(remove, (GHFunc)remove_folders, vf);
-	g_hash_table_destroy(remove);
+	if (vf_changes) {
+		camel_object_trigger_event ((CamelObject *)vf, "folder_changed", vf_changes);
+		camel_folder_change_info_free (vf_changes);
+	}
 }
 
-/**
- * camel_vee_folder_hash_folder:
- * @folder:
- * @:
- *
- * Create a hash string representing the folder name, which should be
- * unique, and remain static for a given folder.
- **/
-void
-camel_vee_folder_hash_folder(CamelFolder *folder, gchar buffer[8])
+static void
+subfolder_renamed_update (CamelVeeFolder *vf, CamelFolder *sub, gchar hash[8])
 {
-	GChecksum *checksum;
-	guint8 *digest;
-	gsize length;
-	gint state = 0, save = 0;
-	gchar *tmp;
-	gint i;
+	gint count, i;
+	CamelFolderChangeInfo *changes = NULL;
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
+	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
+	CamelFolderSummary *ssummary = sub->summary;
 
-	length = g_checksum_type_get_length (G_CHECKSUM_MD5);
-	digest = g_alloca (length);
+	CAMEL_VEE_FOLDER_LOCK (vf, summary_lock);
 
-	checksum = g_checksum_new (G_CHECKSUM_MD5);
-	tmp = camel_service_get_url((CamelService *)folder->parent_store);
-	g_checksum_update (checksum, (guchar *) tmp, -1);
-	g_free (tmp);
-	tmp = folder->full_name;
-	g_checksum_update (checksum, (guchar *) tmp, -1);
-	g_checksum_get_digest (checksum, digest, &length);
-	g_checksum_free (checksum);
+	count = camel_folder_summary_count (((CamelFolder *)vf)->summary);
+	for (i=0;i<count;i++) {
+		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index (((CamelFolder *)vf)->summary, i);
+		CamelVeeMessageInfo *vinfo;
 
-	g_base64_encode_step (digest, 6, FALSE, buffer, &state, &save);
-	g_base64_encode_close (FALSE, buffer, &state, &save);
+		if (mi == NULL)
+			continue;
 
-	for (i=0;i<8;i++) {
-		if (buffer[i] == '+')
-			buffer[i] = '.';
-		if (buffer[i] == '/')
-			buffer[i] = '_';
-	}
-}
+		if (mi->summary == ssummary) {
+			gchar *uid = (gchar *)camel_message_info_uid (mi);
+			gchar *oldkey;
+			gpointer oldval;
 
-/**
- * camel_vee_folder_get_location:
- * @vf:
- * @vinfo:
- * @realuid: if not NULL, set to the uid of the real message, must be
- * g_free'd by caller.
- *
- * Find the real folder (and uid)
- *
- * Return value:
- **/
-CamelFolder *
-camel_vee_folder_get_location(CamelVeeFolder *vf, const CamelVeeMessageInfo *vinfo, gchar **realuid)
-{
-	CamelFolder *folder;
+			camel_folder_change_info_remove_uid (vf->changes, uid);
+			camel_folder_summary_remove (((CamelFolder *)vf)->summary, (CamelMessageInfo *)mi);
 
-	folder = vinfo->summary->folder;
+			/* works since we always append on the end */
+			i--;
+			count--;
 
-	/* locking?  yes?  no?  although the vfolderinfo is valid when obtained
-	   the folder in it might not necessarily be so ...? */
-	if (CAMEL_IS_VEE_FOLDER(folder)) {
-		CamelFolder *res;
-		const CamelVeeMessageInfo *vfinfo;
+			vinfo = vee_folder_add_uid (vf, sub, uid+8, hash);
+			if (vinfo) {
+				camel_folder_change_info_add_uid (vf->changes, camel_message_info_uid (vinfo));
 
-		vfinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info(folder, camel_message_info_uid(vinfo)+8);
-		res = camel_vee_folder_get_location((CamelVeeFolder *)folder, vfinfo, realuid);
-		camel_folder_free_message_info(folder, (CamelMessageInfo *)vfinfo);
-		return res;
-	} else {
-		if (realuid)
-			*realuid = g_strdup(camel_message_info_uid(vinfo)+8);
+				/* check unmatched uid's table for any matches */
+				if (vf == folder_unmatched
+				    && g_hash_table_lookup_extended (unmatched_uids, uid, (gpointer *)&oldkey, &oldval)) {
+					g_hash_table_remove (unmatched_uids, oldkey);
+					g_hash_table_insert (unmatched_uids, g_strdup (camel_message_info_uid (vinfo)), oldval);
+					g_free (oldkey);
+				}
+			}
+		}
 
-		return folder;
+		camel_message_info_free ((CamelMessageInfo *)mi);
+	}
+
+	if (camel_folder_change_info_changed (vf->changes)) {
+		changes = vf->changes;
+		vf->changes = camel_folder_change_info_new ();
+	}
+
+	CAMEL_VEE_FOLDER_UNLOCK (vf, summary_lock);
+
+	if (changes) {
+		camel_object_trigger_event ((CamelObject *)vf, "folder_changed", changes);
+		camel_folder_change_info_free (changes);
 	}
 }
 
-static void vee_refresh_info(CamelFolder *folder, CamelException *ex)
+static void
+folder_changed_free (CamelSession *session, CamelSessionThreadMsg *msg)
 {
-	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	GList *node, *list;
+	struct _folder_changed_msg *m = (struct _folder_changed_msg *)msg;
 
-	CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
-	list = p->folders_changed;
-	p->folders_changed = NULL;
-	CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
+	camel_folder_change_info_free (m->changes);
+	g_object_unref (m->vee_folder);
+	g_object_unref (m->sub);
+}
 
-	node = list;
-	while (node) {
-		CamelFolder *f = node->data;
+static CamelSessionThreadOps folder_changed_ops = {
+	folder_changed_change,
+	folder_changed_free,
+};
 
-		if (camel_vee_folder_rebuild_folder(vf, f, ex) == -1)
-			break;
+static gint
+vee_folder_rebuild_folder (CamelVeeFolder *vee_folder,
+                           CamelFolder *source,
+                           CamelException *ex);
 
-		node = node->next;
-	}
+static void
+unmatched_check_uid (gchar *uidin, gpointer value, struct _update_data *u)
+{
+	gchar *uid;
+	gint n;
 
-	g_list_free(list);
+	uid = alloca (strlen (uidin)+9);
+	memcpy (uid, u->hash, 8);
+	strcpy (uid+8, uidin);
+	n = GPOINTER_TO_INT (g_hash_table_lookup (u->unmatched_uids, uid));
+	if (n == 0) {
+		if (vee_folder_add_uid (u->folder_unmatched, u->source, uidin, u->hash))
+			camel_folder_change_info_add_uid (u->folder_unmatched->changes, uid);
+	} else {
+		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_uid (((CamelFolder *)u->folder_unmatched)->summary, uid);
+		if (mi) {
+			CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+			camel_db_delete_uid_from_vfolder_transaction (((CamelFolder *)u->folder_unmatched)->parent_store->cdb_w, ((CamelFolder *)u->folder_unmatched)->full_name, uid, &ex);
+			camel_folder_summary_remove_uid_fast (((CamelFolder *)u->folder_unmatched)->summary, uid);
+			camel_folder_change_info_remove_uid (u->folder_unmatched->changes, uid);
+			camel_message_info_free ((CamelMessageInfo *)mi);
+			camel_exception_clear (&ex);
+		}
+	}
 }
 
-static guint32
-count_folder (CamelFolder *f, gchar *expr, CamelException *ex)
+static void
+folder_added_uid (gchar *uidin, gpointer value, struct _update_data *u)
 {
-	return camel_folder_count_by_expression(f, expr, ex);
+	CamelVeeMessageInfo *mi;
+	gchar *oldkey;
+	gpointer oldval;
+	gint n;
+
+	if ((mi = vee_folder_add_uid (u->vee_folder, u->source, uidin, u->hash))) {
+		camel_folder_change_info_add_uid (u->vee_folder->changes, camel_message_info_uid (mi));
+		/* FIXME[disk-summary] Handle exceptions */
+		/* FIXME[disk-summary] Make all these as transactions, just
+		 * testing atm */
+		if (u->rebuilt && !u->correlating) {
+			CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+			camel_db_add_to_vfolder_transaction (((CamelFolder *) u->vee_folder)->parent_store->cdb_w, ((CamelFolder *) u->vee_folder)->full_name, (gchar *) camel_message_info_uid (mi), &ex);
+			camel_exception_clear (&ex);
+		}
+		if (!CAMEL_IS_VEE_FOLDER (u->source) && u->unmatched_uids != NULL) {
+			if (g_hash_table_lookup_extended (u->unmatched_uids, camel_message_info_uid (mi), (gpointer *)&oldkey, &oldval)) {
+				n = GPOINTER_TO_INT (oldval);
+				g_hash_table_insert (u->unmatched_uids, oldkey, GINT_TO_POINTER (n+1));
+			} else {
+				g_hash_table_insert (u->unmatched_uids, g_strdup (camel_message_info_uid (mi)), GINT_TO_POINTER (1));
+			}
+		}
+	}
 }
+
 static gint
-count_result (CamelFolderSummary *summary, const gchar *query, CamelException *ex)
+count_result (CamelFolderSummary *summary,
+              const gchar *query,
+              CamelException *ex)
 {
 	CamelFolder *folder = summary->folder;
 	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
 	guint32 count=0;
 	gchar *expr = g_strdup_printf ("(and %s %s)", vf->expression ? vf->expression : "", query);
 	GList *node;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
 
 	node = p->folders;
 	while (node) {
 		CamelFolder *f = node->data;
-		count += count_folder(f, expr, ex);
+		count += camel_folder_count_by_expression (f, expr, ex);
 		node = node->next;
 	}
 
-	g_free(expr);
+	g_free (expr);
 	return count;
 }
 
@@ -512,14 +700,14 @@ summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 	record->time = s->time;
 
 	record->saved_count = s->uids->len;
-	camel_object_get(s->folder, NULL,
+	camel_object_get (s->folder, NULL,
 				 CAMEL_FOLDER_DELETED, &deleted,
 				 CAMEL_FOLDER_VISIBLE, &visible,
 				 CAMEL_FOLDER_JUNKED, &junked,
 				 CAMEL_FOLDER_JUNKED_NOT_DELETED, &junked_not_deleted,
 				 CAMEL_FOLDER_UNREAD, &unread, NULL);
 	if (1) { /* We always would do this. Just refactor the code again. */
-		/*!(((CamelVeeSummary *) s)->force_counts) && !g_getenv("FORCE_VFOLDER_COUNT")) {*/
+		/*!(((CamelVeeSummary *) s)->force_counts) && !g_getenv ("FORCE_VFOLDER_COUNT")) {*/
 		/* We should be in sync always. so use the count. Don't search.*/
 		record->junk_count = s->junk_count;
 		record->deleted_count = s->deleted_count;
@@ -547,40 +735,466 @@ summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 		record->jnd_count = s->junk_not_deleted_count;
 	}
 
-	d(printf("%s %d %d %d %d %d\n", s->folder->full_name, record->junk_count, record->deleted_count, record->unread_count, record->visible_count, record->jnd_count));
+	d (printf ("%s %d %d %d %d %d\n", s->folder->full_name, record->junk_count, record->deleted_count, record->unread_count, record->visible_count, record->jnd_count));
 	return record;
 }
 
 static void
-vee_sync(CamelFolder *folder, gboolean expunge, CamelException *ex)
+folder_changed (CamelFolder *sub,
+                CamelFolderChangeInfo *changes,
+                CamelVeeFolder *vee_folder)
+{
+	CamelVeeFolderClass *class;
+
+	class = CAMEL_VEE_FOLDER_GET_CLASS (vee_folder);
+	class->folder_changed (vee_folder, sub, changes);
+}
+
+/* track vanishing folders */
+static void
+subfolder_deleted (CamelFolder *folder,
+                   gpointer event_data,
+                   CamelVeeFolder *vee_folder)
+{
+	camel_vee_folder_remove_folder (vee_folder, folder);
+}
+
+static void
+folder_renamed (CamelFolder *sub,
+                const gchar *old,
+                CamelVeeFolder *vee_folder)
+{
+	CamelVeeFolderClass *class;
+
+	class = CAMEL_VEE_FOLDER_GET_CLASS (vee_folder);
+	class->folder_renamed (vee_folder, sub, old);
+}
+
+static void
+vee_folder_stop_folder (CamelVeeFolder *vf, CamelFolder *sub)
+{
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	gint i;
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
+
+	CAMEL_VEE_FOLDER_LOCK (vf, subfolder_lock);
+
+	CAMEL_VEE_FOLDER_LOCK (vf, changed_lock);
+	p->folders_changed = g_list_remove (p->folders_changed, sub);
+	CAMEL_VEE_FOLDER_UNLOCK (vf, changed_lock);
+
+	if (g_list_find (p->folders, sub) == NULL) {
+		CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
+		return;
+	}
+
+	camel_object_unhook_event ((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
+	camel_object_unhook_event ((CamelObject *)sub, "deleted", (CamelObjectEventHookFunc) subfolder_deleted, vf);
+	camel_object_unhook_event ((CamelObject *)sub, "renamed", (CamelObjectEventHookFunc) folder_renamed, vf);
+
+	p->folders = g_list_remove (p->folders, sub);
+
+	/* undo the freeze state that we have imposed on this source folder */
+	CAMEL_FOLDER_LOCK (vf, change_lock);
+	for (i = 0; i < ((CamelFolder *)vf)->priv->frozen; i++)
+		camel_folder_thaw (sub);
+	CAMEL_FOLDER_UNLOCK (vf, change_lock);
+
+	CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
+
+	if (folder_unmatched != NULL) {
+		CamelVeeFolderPrivate *up = CAMEL_VEE_FOLDER_GET_PRIVATE (folder_unmatched);
+
+		CAMEL_VEE_FOLDER_LOCK (folder_unmatched, subfolder_lock);
+		/* if folder deleted, then blow it away from unmatched always, and remove all refs to it */
+		if (sub->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED) {
+			while (g_list_find (up->folders, sub)) {
+				up->folders = g_list_remove (up->folders, sub);
+				g_object_unref (sub);
+
+				/* undo the freeze state that Unmatched has imposed on this source folder */
+				CAMEL_FOLDER_LOCK (folder_unmatched, change_lock);
+				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
+					camel_folder_thaw (sub);
+				CAMEL_FOLDER_UNLOCK (folder_unmatched, change_lock);
+			}
+		} else if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
+			if (g_list_find (up->folders, sub) != NULL) {
+				up->folders = g_list_remove (up->folders, sub);
+				g_object_unref (sub);
+
+				/* undo the freeze state that Unmatched has imposed on this source folder */
+				CAMEL_FOLDER_LOCK (folder_unmatched, change_lock);
+				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
+					camel_folder_thaw (sub);
+				CAMEL_FOLDER_UNLOCK (folder_unmatched, change_lock);
+			}
+		}
+		CAMEL_VEE_FOLDER_UNLOCK (folder_unmatched, subfolder_lock);
+	}
+
+	if (CAMEL_IS_VEE_FOLDER (sub))
+		return;
+
+	g_object_unref (sub);
+}
+
+static void
+vee_folder_remove_folder_helper (CamelVeeFolder *vf, CamelFolder *source)
+{
+	gint i, count, n, still = FALSE, start, last;
+	gchar *oldkey;
+	CamelFolder *folder = (CamelFolder *)vf;
+	gchar hash[8];
+	CamelFolderChangeInfo *vf_changes = NULL, *unmatched_changes = NULL;
+	gpointer oldval;
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
+	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
+	CamelFolderSummary *ssummary = source->summary;
+	gint killun = FALSE;
+
+	if (vf == folder_unmatched)
+		return;
+
+	if ((source->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED))
+		killun = TRUE;
+
+	CAMEL_VEE_FOLDER_LOCK (vf, summary_lock);
+
+	if (folder_unmatched != NULL) {
+		/* check if this folder is still to be part of unmatched */
+		if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !killun) {
+			CAMEL_VEE_FOLDER_LOCK (folder_unmatched, subfolder_lock);
+			still = g_list_find (CAMEL_VEE_FOLDER_GET_PRIVATE (folder_unmatched)->folders, source) != NULL;
+			CAMEL_VEE_FOLDER_UNLOCK (folder_unmatched, subfolder_lock);
+			camel_vee_folder_hash_folder (source, hash);
+		}
+
+		CAMEL_VEE_FOLDER_LOCK (folder_unmatched, summary_lock);
+
+		/* See if we just blow all uid's from this folder away from unmatched, regardless */
+		if (killun) {
+			start = -1;
+			last = -1;
+			count = camel_folder_summary_count (((CamelFolder *)folder_unmatched)->summary);
+			for (i=0;i<count;i++) {
+				CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index (((CamelFolder *)folder_unmatched)->summary, i);
+
+				if (mi) {
+					if (mi->summary == ssummary) {
+						camel_folder_change_info_remove_uid (folder_unmatched->changes, camel_message_info_uid (mi));
+						if (last == -1) {
+							last = start = i;
+						} else if (last+1 == i) {
+							last = i;
+						} else {
+							camel_folder_summary_remove_range (((CamelFolder *)folder_unmatched)->summary, start, last);
+							i -= (last-start)+1;
+							start = last = i;
+						}
+					}
+					camel_message_info_free ((CamelMessageInfo *)mi);
+				}
+			}
+			if (last != -1)
+				camel_folder_summary_remove_range (((CamelFolder *)folder_unmatched)->summary, start, last);
+		}
+	}
+
+	/*FIXME: This can be optimized a lot like, searching for UID in the summary uids */
+	start = -1;
+	last = -1;
+	count = camel_folder_summary_count (folder->summary);
+	for (i=0;i<count;i++) {
+		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index (folder->summary, i);
+		if (mi) {
+			if (mi->summary == ssummary) {
+				const gchar *uid = camel_message_info_uid (mi);
+
+				camel_folder_change_info_remove_uid (vf->changes, uid);
+
+				if (last == -1) {
+					last = start = i;
+				} else if (last+1 == i) {
+					last = i;
+				} else {
+					camel_folder_summary_remove_range (folder->summary, start, last);
+					i -= (last-start)+1;
+					start = last = i;
+				}
+				if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && folder_unmatched != NULL) {
+					if (still) {
+						if (g_hash_table_lookup_extended (unmatched_uids, uid, (gpointer *)&oldkey, &oldval)) {
+							n = GPOINTER_TO_INT (oldval);
+							if (n == 1) {
+								CamelMessageInfo *tinfo;
+								g_hash_table_remove (unmatched_uids, oldkey);
+								if ((tinfo = (CamelMessageInfo *) vee_folder_add_uid (folder_unmatched, source, oldkey+8, hash)) != NULL) {
+									camel_message_info_free (tinfo);
+									camel_folder_change_info_add_uid (folder_unmatched->changes, oldkey);
+								}
+								g_free (oldkey);
+							} else {
+								g_hash_table_insert (unmatched_uids, oldkey, GINT_TO_POINTER (n-1));
+							}
+						}
+					} else {
+						if (g_hash_table_lookup_extended (unmatched_uids, camel_message_info_uid (mi), (gpointer *)&oldkey, &oldval)) {
+							g_hash_table_remove (unmatched_uids, oldkey);
+							g_free (oldkey);
+						}
+					}
+				}
+			}
+			camel_message_info_free ((CamelMessageInfo *)mi);
+		}
+	}
+
+	if (last != -1)
+		camel_folder_summary_remove_range (folder->summary, start, last);
+
+	if (folder_unmatched) {
+		if (camel_folder_change_info_changed (folder_unmatched->changes)) {
+			unmatched_changes = folder_unmatched->changes;
+			folder_unmatched->changes = camel_folder_change_info_new ();
+		}
+
+		CAMEL_VEE_FOLDER_UNLOCK (folder_unmatched, summary_lock);
+	}
+
+	if (camel_folder_change_info_changed (vf->changes)) {
+		vf_changes = vf->changes;
+		vf->changes = camel_folder_change_info_new ();
+	}
+
+	CAMEL_VEE_FOLDER_UNLOCK (vf, summary_lock);
+
+	if (unmatched_changes) {
+		camel_object_trigger_event ((CamelObject *)folder_unmatched, "folder_changed", unmatched_changes);
+		camel_folder_change_info_free (unmatched_changes);
+	}
+
+	if (vf_changes) {
+		camel_object_trigger_event ((CamelObject *)vf, "folder_changed", vf_changes);
+		camel_folder_change_info_free (vf_changes);
+	}
+}
+
+static void
+vee_folder_finalize (GObject *object)
+{
+	CamelVeeFolder *vf;
+	CamelVeeFolder *folder_unmatched;
+	GList *node;
+	CamelFIRecord * record;
+
+	vf = CAMEL_VEE_FOLDER (object);
+	vf->priv->destroyed = TRUE;
+
+	if (vf->parent_vee_store != NULL)
+		folder_unmatched = vf->parent_vee_store->folder_unmatched;
+	else
+		folder_unmatched = NULL;
+
+	/* Save the counts to DB */
+	if (!vf->deleted) {
+		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+		record = summary_header_to_db (((CamelFolder *)vf)->summary, NULL);
+		camel_db_write_folder_info_record (((CamelFolder *) vf)->parent_store->cdb_w, record, &ex);
+		g_free (record);
+		camel_exception_clear (&ex);
+	}
+
+	/* This may invoke sub-classes with partially destroyed state, they must deal with this */
+	if (vf == folder_unmatched) {
+		for (node = vf->priv->folders;node;node = g_list_next (node))
+			g_object_unref (node->data);
+	} else {
+		/* FIXME[disk-summary] See if it is really reqd */
+		camel_folder_freeze ((CamelFolder *)vf);
+		while (vf->priv->folders) {
+			CamelFolder *f = vf->priv->folders->data;
+			vee_folder_stop_folder (vf, f);
+		}
+		camel_folder_thaw ((CamelFolder *)vf);
+	}
+
+	g_free (vf->expression);
+
+	g_list_free (vf->priv->folders);
+	g_list_free (vf->priv->folders_changed);
+
+	camel_folder_change_info_free (vf->changes);
+	g_object_unref (vf->search);
+
+	g_mutex_free (vf->priv->summary_lock);
+	g_mutex_free (vf->priv->subfolder_lock);
+	g_mutex_free (vf->priv->changed_lock);
+	g_hash_table_destroy (vf->hashes);
+
+	/* Chain up to parent's finalize () method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+/* This entire code will be useless, since we sync the counts always. */
+static gint
+vee_folder_getv (CamelObject *object,
+                 CamelException *ex,
+                 CamelArgGetV *args)
+{
+	CamelFolder *folder = (CamelFolder *)object;
+	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
+	gint i;
+	guint32 tag;
+	gint unread = -1, deleted = 0, junked = 0, visible = 0, count = -1, junked_not_deleted = -1;
+
+	for (i=0;i<args->argc;i++) {
+		CamelArgGet *arg = &args->argv[i];
+
+		tag = arg->tag;
+
+		/* NB: this is a copy of camel-folder.c with the unread count logic altered.
+		   makes sure its still atomically calculated */
+		switch (tag & CAMEL_ARG_TAG) {
+		case CAMEL_FOLDER_ARG_UNREAD:
+		case CAMEL_FOLDER_ARG_DELETED:
+		case CAMEL_FOLDER_ARG_JUNKED:
+		case CAMEL_FOLDER_ARG_JUNKED_NOT_DELETED:
+		case CAMEL_FOLDER_ARG_VISIBLE:
+
+			if (vf->expression && vf->priv->unread_vfolder == -1)
+				camel_vee_summary_load_check_unread_vfolder ((CamelVeeSummary *)folder->summary);
+
+			/* This is so we can get the values atomically, and also so we can calculate them only once */
+			if (unread == -1) {
+				gint j;
+				CamelMessageInfoBase *info;
+				CamelVeeMessageInfo *vinfo;
+
+				unread = deleted = visible = junked = junked_not_deleted = 0;
+				count = camel_folder_summary_count (folder->summary);
+				for (j=0; j<count; j++) {
+					if ((info = (CamelMessageInfoBase *) camel_folder_summary_index (folder->summary, j))) {
+						guint32 flags;
+
+						vinfo = (CamelVeeMessageInfo *) info;
+						flags = vinfo->old_flags; /* ? vinfo->old_flags : camel_message_info_flags (info); */
+
+						if ((flags & (CAMEL_MESSAGE_SEEN)) == 0)
+							unread++;
+						if (flags & CAMEL_MESSAGE_DELETED)
+							deleted++;
+						if (flags & CAMEL_MESSAGE_JUNK) {
+							junked++;
+								if (! (flags & CAMEL_MESSAGE_DELETED))
+									junked_not_deleted++;
+						}
+						if ((flags & (CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK)) == 0)
+							visible++;
+						camel_message_info_free (info);
+					}
+				}
+			}
+
+			switch (tag & CAMEL_ARG_TAG) {
+			case CAMEL_FOLDER_ARG_UNREAD:
+				if (vf->priv->unread_vfolder == 1)
+					count = unread == -1 ? 0 : unread - junked_not_deleted;
+				else
+					count = unread == -1 ? 0 : unread;
+				break;
+			case CAMEL_FOLDER_ARG_DELETED:
+				count = deleted == -1 ? 0 : deleted;
+				break;
+			case CAMEL_FOLDER_ARG_JUNKED:
+				count = junked == -1 ? 0 : junked;
+				break;
+			case CAMEL_FOLDER_ARG_JUNKED_NOT_DELETED:
+				count = junked_not_deleted == -1 ? 0 : junked_not_deleted;
+				break;
+			case CAMEL_FOLDER_ARG_VISIBLE:
+				if (vf->priv->unread_vfolder == 1)
+					count = unread == -1 ? 0 : unread - junked_not_deleted;
+				else
+					count = visible == -1 ? 0 : visible;
+
+				break;
+			}
+			folder->summary->unread_count = unread == -1 ? 0 : unread;
+			folder->summary->deleted_count = deleted == -1 ? 0 : deleted;
+			junked = folder->summary->junk_count = junked == -1 ? 0 : junked;
+			folder->summary->junk_not_deleted_count = junked_not_deleted == -1 ? 0 : junked_not_deleted;
+			folder->summary->visible_count = visible == -1 ? 0 : visible;
+			*arg->ca_int = count;
+			break;
+		default:
+			continue;
+		}
+
+		arg->tag = (tag & CAMEL_ARG_TYPE) | CAMEL_ARG_IGNORE;
+	}
+
+	return ((CamelObjectClass *)parent_class)->getv (object, ex, args);
+}
+
+static void
+vee_folder_refresh_info (CamelFolder *folder,
+                         CamelException *ex)
 {
 	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	GList *node, *list;
+
+	CAMEL_VEE_FOLDER_LOCK (vf, changed_lock);
+	list = p->folders_changed;
+	p->folders_changed = NULL;
+	CAMEL_VEE_FOLDER_UNLOCK (vf, changed_lock);
+
+	node = list;
+	while (node) {
+		CamelFolder *f = node->data;
+
+		if (camel_vee_folder_rebuild_folder (vf, f, ex) == -1)
+			break;
+
+		node = node->next;
+	}
+
+	g_list_free (list);
+}
+
+static void
+vee_folder_sync (CamelFolder *folder,
+                 gboolean expunge,
+                 CamelException *ex)
+{
+	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
 	GList *node;
 
 	if (((CamelVeeSummary *)folder->summary)->fake_visible_count)
 		folder->summary->visible_count = ((CamelVeeSummary *)folder->summary)->fake_visible_count;
 	((CamelVeeSummary *)folder->summary)->fake_visible_count = 0;
 
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
+	CAMEL_VEE_FOLDER_LOCK (vf, subfolder_lock);
 
 	node = p->folders;
 	while (node) {
 		CamelFolder *f = node->data;
 
-		camel_folder_sync(f, expunge, ex);
-		if (camel_exception_is_set(ex) && strncmp(camel_exception_get_description(ex), "no such table", 13)) {
+		camel_folder_sync (f, expunge, ex);
+		if (camel_exception_is_set (ex) && strncmp (camel_exception_get_description (ex), "no such table", 13)) {
 			const gchar *desc;
 
-			camel_object_get(f, NULL, CAMEL_OBJECT_DESCRIPTION, &desc, NULL);
-			camel_exception_setv(ex, ex->id, _("Error storing '%s': %s"), desc, ex->desc);
-			g_warning ("%s", camel_exception_get_description(ex));
+			camel_object_get (f, NULL, CAMEL_OBJECT_DESCRIPTION, &desc, NULL);
+			camel_exception_setv (ex, ex->id, _("Error storing '%s': %s"), desc, ex->desc);
+			g_warning ("%s", camel_exception_get_description (ex));
 		} else
 			camel_exception_clear (ex);
 
 		/* auto update vfolders shouldn't need a rebuild */
 /*		if ((vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO) == 0 */
-/*		    && camel_vee_folder_rebuild_folder(vf, f, ex) == -1) */
+/*		    && camel_vee_folder_rebuild_folder (vf, f, ex) == -1) */
 /*			break; */
 
 		node = node->next;
@@ -598,10 +1212,10 @@ vee_sync(CamelFolder *folder, gboolean expunge, CamelException *ex)
 	 * actually rebuilding. */
 #if 0
 	if (node == NULL) {
-		CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
-		g_list_free(p->folders_changed);
+		CAMEL_VEE_FOLDER_LOCK (vf, changed_lock);
+		g_list_free (p->folders_changed);
 		p->folders_changed = NULL;
-		CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
+		CAMEL_VEE_FOLDER_UNLOCK (vf, changed_lock);
 	}
 #endif
 	if (vf->priv->unread_vfolder == 1) {
@@ -613,7 +1227,7 @@ vee_sync(CamelFolder *folder, gboolean expunge, CamelException *ex)
 		for (i=0; i < count; i++) {
 			CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index (folder->summary, i);
 			if (mi->old_flags & CAMEL_MESSAGE_DELETED) {
-				del = g_slist_prepend (del, (gpointer) camel_pstring_strdup(((CamelMessageInfo *)mi)->uid));
+				del = g_slist_prepend (del, (gpointer) camel_pstring_strdup (((CamelMessageInfo *)mi)->uid));
 				camel_folder_summary_remove_index_fast (folder->summary, i);
 				count--;
 				i--;
@@ -625,31 +1239,34 @@ vee_sync(CamelFolder *folder, gboolean expunge, CamelException *ex)
 		g_slist_foreach (del, (GFunc) camel_pstring_free, NULL);
 		g_slist_free (del);
 	}
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
+	CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
 
-	camel_object_state_write(vf);
+	camel_object_state_write (vf);
 }
 
 static void
-vee_expunge (CamelFolder *folder, CamelException *ex)
+vee_folder_expunge (CamelFolder *folder,
+                    CamelException *ex)
 {
 	/* Force it to rebuild the counts, when some folders were expunged. */
 	((CamelVeeSummary *) folder->summary)->force_counts = TRUE;
-	((CamelFolderClass *)((CamelObject *)folder)->klass)->sync(folder, TRUE, ex);
+	CAMEL_FOLDER_GET_CLASS (folder)->sync (folder, TRUE, ex);
 }
 
 static CamelMimeMessage *
-vee_get_message(CamelFolder *folder, const gchar *uid, CamelException *ex)
+vee_folder_get_message (CamelFolder *folder,
+                        const gchar *uid,
+                        CamelException *ex)
 {
 	CamelVeeMessageInfo *mi;
 	CamelMimeMessage *msg = NULL;
 
-	mi = (CamelVeeMessageInfo *)camel_folder_summary_uid(folder->summary, uid);
+	mi = (CamelVeeMessageInfo *)camel_folder_summary_uid (folder->summary, uid);
 	if (mi) {
-		msg =  camel_folder_get_message(mi->summary->folder, camel_message_info_uid(mi)+8, ex);
-		camel_message_info_free((CamelMessageInfo *)mi);
+		msg =  camel_folder_get_message (mi->summary->folder, camel_message_info_uid (mi)+8, ex);
+		camel_message_info_free ((CamelMessageInfo *)mi);
 	} else {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
+		camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
 				     _("No such message %s in %s"), uid,
 				     folder->name);
 	}
@@ -657,48 +1274,42 @@ vee_get_message(CamelFolder *folder, const gchar *uid, CamelException *ex)
 	return msg;
 }
 
-static guint32
-vee_count_by_expression(CamelFolder *folder, const gchar *expression, CamelException *ex)
+static void
+vee_folder_append_message (CamelFolder *folder,
+                           CamelMimeMessage *message,
+                           const CamelMessageInfo *info,
+                           gchar **appended_uid,
+                           CamelException *ex)
 {
-	GList *node;
-	gchar *expr;
-	guint32 count = 0;
-	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	GHashTable *searched = g_hash_table_new(NULL, NULL);
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-
-	if (vf != folder_unmatched)
-		expr = g_strdup_printf ("(and %s %s)", vf->expression ? vf->expression : "", expression);
-	else
-		expr = g_strdup (expression);
-
-	node = p->folders;
-	while (node) {
-		CamelFolder *f = node->data;
-
-		/* make sure we only search each folder once - for unmatched folder to work right */
-		if (g_hash_table_lookup(searched, f) == NULL) {
-			count += camel_folder_count_by_expression(f, expr, ex);
-			g_hash_table_insert(searched, f, f);
-		}
-		node = g_list_next(node);
-	}
-
-	g_free(expr);
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Cannot copy or move messages into a Virtual Folder"));
+}
 
-	g_hash_table_destroy(searched);
-	return count;
+static void
+vee_folder_transfer_messages_to (CamelFolder *folder,
+                                 GPtrArray *uids,
+                                 CamelFolder *dest,
+                                 GPtrArray **transferred_uids,
+                                 gboolean delete_originals,
+                                 CamelException *ex)
+{
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Cannot copy or move messages into a Virtual Folder"));
 }
+
 static GPtrArray *
-vee_search_by_expression(CamelFolder *folder, const gchar *expression, CamelException *ex)
+vee_folder_search_by_expression (CamelFolder *folder,
+                                 const gchar *expression,
+                                 CamelException *ex)
 {
 	GList *node;
 	GPtrArray *matches, *result = g_ptr_array_new ();
 	gchar *expr;
 	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	GHashTable *searched = g_hash_table_new(NULL, NULL);
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	GHashTable *searched = g_hash_table_new (NULL, NULL);
 	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
 
 	if (vf != folder_unmatched)
@@ -713,50 +1324,53 @@ vee_search_by_expression(CamelFolder *folder, const gchar *expression, CamelExce
 		gchar hash[8];
 
 		/* make sure we only search each folder once - for unmatched folder to work right */
-		if (g_hash_table_lookup(searched, f) == NULL) {
-			camel_vee_folder_hash_folder(f, hash);
-			matches = camel_folder_search_by_expression(f, expr, ex);
-			if (camel_exception_is_set(ex) && strncmp(camel_exception_get_description(ex), "no such table", 13)) {
-				camel_exception_clear(ex);
+		if (g_hash_table_lookup (searched, f) == NULL) {
+			camel_vee_folder_hash_folder (f, hash);
+			matches = camel_folder_search_by_expression (f, expr, ex);
+			if (camel_exception_is_set (ex) && strncmp (camel_exception_get_description (ex), "no such table", 13)) {
+				camel_exception_clear (ex);
 			}
 			if (matches) {
 				for (i = 0; i < matches->len; i++) {
 					gchar *uid = matches->pdata[i], *vuid;
 
-					vuid = g_malloc(strlen(uid)+9);
-					memcpy(vuid, hash, 8);
-					strcpy(vuid+8, uid);
-					g_ptr_array_add(result, (gpointer) camel_pstring_strdup(vuid));
+					vuid = g_malloc (strlen (uid)+9);
+					memcpy (vuid, hash, 8);
+					strcpy (vuid+8, uid);
+					g_ptr_array_add (result, (gpointer) camel_pstring_strdup (vuid));
 					g_free (vuid);
 				}
-				camel_folder_search_free(f, matches);
+				camel_folder_search_free (f, matches);
 			}
-			g_hash_table_insert(searched, f, f);
+			g_hash_table_insert (searched, f, f);
 		}
-		node = g_list_next(node);
+		node = g_list_next (node);
 	}
 
-	g_free(expr);
+	g_free (expr);
 
-	g_hash_table_destroy(searched);
-	d(printf("returning %d\n", result->len));
+	g_hash_table_destroy (searched);
+	d (printf ("returning %d\n", result->len));
 	return result;
 }
 
 static GPtrArray *
-vee_search_by_uids(CamelFolder *folder, const gchar *expression, GPtrArray *uids, CamelException *ex)
+vee_folder_search_by_uids (CamelFolder *folder,
+                           const gchar *expression,
+                           GPtrArray *uids,
+                           CamelException *ex)
 {
 	GList *node;
 	GPtrArray *matches, *result = g_ptr_array_new ();
-	GPtrArray *folder_uids = g_ptr_array_new();
+	GPtrArray *folder_uids = g_ptr_array_new ();
 	gchar *expr;
 	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	GHashTable *searched = g_hash_table_new(NULL, NULL);
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	GHashTable *searched = g_hash_table_new (NULL, NULL);
 
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
+	CAMEL_VEE_FOLDER_LOCK (vf, subfolder_lock);
 
-	expr = g_strdup_printf("(and %s %s)", vf->expression ? vf->expression : "", expression);
+	expr = g_strdup_printf ("(and %s %s)", vf->expression ? vf->expression : "", expression);
 	node = p->folders;
 	while (node) {
 		CamelFolder *f = node->data;
@@ -764,357 +1378,272 @@ vee_search_by_uids(CamelFolder *folder, const gchar *expression, GPtrArray *uids
 		gchar hash[8];
 
 		/* make sure we only search each folder once - for unmatched folder to work right */
-		if (g_hash_table_lookup(searched, f) == NULL) {
-			camel_vee_folder_hash_folder(f, hash);
+		if (g_hash_table_lookup (searched, f) == NULL) {
+			camel_vee_folder_hash_folder (f, hash);
 
 			/* map the vfolder uid's to the source folder uid's first */
-			g_ptr_array_set_size(folder_uids, 0);
+			g_ptr_array_set_size (folder_uids, 0);
 			for (i=0;i<uids->len;i++) {
 				gchar *uid = uids->pdata[i];
 
-				if (strlen(uid) >= 8 && strncmp(uid, hash, 8) == 0)
-					g_ptr_array_add(folder_uids, uid+8);
+				if (strlen (uid) >= 8 && strncmp (uid, hash, 8) == 0)
+					g_ptr_array_add (folder_uids, uid+8);
 			}
 			if (folder_uids->len > 0) {
-				matches = camel_folder_search_by_uids(f, expr, folder_uids, ex);
+				matches = camel_folder_search_by_uids (f, expr, folder_uids, ex);
 				if (matches) {
 					for (i = 0; i < matches->len; i++) {
 						gchar *uid = matches->pdata[i], *vuid;
 
-						vuid = g_malloc(strlen(uid)+9);
-						memcpy(vuid, hash, 8);
-						strcpy(vuid+8, uid);
-						g_ptr_array_add(result, (gpointer) camel_pstring_strdup(vuid));
-						g_free(vuid);
+						vuid = g_malloc (strlen (uid)+9);
+						memcpy (vuid, hash, 8);
+						strcpy (vuid+8, uid);
+						g_ptr_array_add (result, (gpointer) camel_pstring_strdup (vuid));
+						g_free (vuid);
 					}
-					camel_folder_search_free(f, matches);
+					camel_folder_search_free (f, matches);
 				} else {
-					g_warning("Search failed: %s", camel_exception_get_description(ex));
+					g_warning ("Search failed: %s", camel_exception_get_description (ex));
 				}
 			}
-			g_hash_table_insert(searched, f, f);
+			g_hash_table_insert (searched, f, f);
 		}
-		node = g_list_next(node);
+		node = g_list_next (node);
 	}
 
-	g_free(expr);
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
+	g_free (expr);
+	CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
 
-	g_hash_table_destroy(searched);
-	g_ptr_array_free(folder_uids, TRUE);
+	g_hash_table_destroy (searched);
+	g_ptr_array_free (folder_uids, TRUE);
 
 	return result;
 }
 
-static void
-vee_append_message(CamelFolder *folder, CamelMimeMessage *message, const CamelMessageInfo *info, gchar **appended_uid, CamelException *ex)
+static guint32
+vee_folder_count_by_expression (CamelFolder *folder,
+                                const gchar *expression,
+                                CamelException *ex)
 {
-	camel_exception_set(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot copy or move messages into a Virtual Folder"));
-}
+	GList *node;
+	gchar *expr;
+	guint32 count = 0;
+	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	GHashTable *searched = g_hash_table_new (NULL, NULL);
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
 
-static void
-vee_transfer_messages_to (CamelFolder *folder, GPtrArray *uids, CamelFolder *dest, GPtrArray **transferred_uids, gboolean delete_originals, CamelException *ex)
-{
-	camel_exception_set(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot copy or move messages into a Virtual Folder"));
-}
+	if (vf != folder_unmatched)
+		expr = g_strdup_printf ("(and %s %s)", vf->expression ? vf->expression : "", expression);
+	else
+		expr = g_strdup (expression);
 
-static void vee_rename(CamelFolder *folder, const gchar *new)
-{
-	/*CamelVeeFolder *vf = (CamelVeeFolder *)folder;*/
+	node = p->folders;
+	while (node) {
+		CamelFolder *f = node->data;
+
+		/* make sure we only search each folder once - for unmatched folder to work right */
+		if (g_hash_table_lookup (searched, f) == NULL) {
+			count += camel_folder_count_by_expression (f, expr, ex);
+			g_hash_table_insert (searched, f, f);
+		}
+		node = g_list_next (node);
+	}
 
-	((CamelFolderClass *)camel_vee_folder_parent)->rename(folder, new);
+	g_free (expr);
+
+	g_hash_table_destroy (searched);
+	return count;
 }
 
-static void vee_delete(CamelFolder *folder)
+static void
+vee_folder_delete (CamelFolder *folder)
 {
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(folder);
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (folder);
 
 	/* NB: this is never called on UNMTACHED */
 
-	CAMEL_VEE_FOLDER_LOCK(folder, subfolder_lock);
+	CAMEL_VEE_FOLDER_LOCK (folder, subfolder_lock);
 	while (p->folders) {
 		CamelFolder *f = p->folders->data;
 
-		camel_object_ref(f);
-		CAMEL_VEE_FOLDER_UNLOCK(folder, subfolder_lock);
+		g_object_ref (f);
+		CAMEL_VEE_FOLDER_UNLOCK (folder, subfolder_lock);
 
-		camel_vee_folder_remove_folder((CamelVeeFolder *)folder, f);
-		camel_object_unref(f);
-		CAMEL_VEE_FOLDER_LOCK(folder, subfolder_lock);
+		camel_vee_folder_remove_folder ((CamelVeeFolder *)folder, f);
+		g_object_unref (f);
+		CAMEL_VEE_FOLDER_LOCK (folder, subfolder_lock);
 	}
-	CAMEL_VEE_FOLDER_UNLOCK(folder, subfolder_lock);
+	CAMEL_VEE_FOLDER_UNLOCK (folder, subfolder_lock);
 
-	((CamelFolderClass *)camel_vee_folder_parent)->delete(folder);
+	((CamelFolderClass *)parent_class)->delete (folder);
 	((CamelVeeFolder *)folder)->deleted = TRUE;
 }
 
-/* ********************************************************************** *
-   utility functions */
-
-/* A "correlating" expression has the property that whether a message matches
- * depends on the other messages being searched.  folder_changed_change on a
- * vfolder with a correlating expression may not make all the necessary updates,
- * so the query is redone on the entire changed source folder the next time
- * the vfolder is opened.
- *
- * The only current example of a correlating expression is one that uses
- * "match-threads". */
-static gboolean
-expression_is_correlating(const gchar *expr)
+static void
+vee_folder_freeze (CamelFolder *folder)
 {
-	/* XXX: Actually parse the expression to avoid triggering on
-	 * "match-threads" in the text the user is searching for! */
-	return (strstr(expr, "match-threads") != NULL);
-}
+	CamelVeeFolder *vfolder = (CamelVeeFolder *)folder;
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vfolder);
+	GList *node;
 
-/* must be called with summary_lock held */
-static CamelVeeMessageInfo *
-vee_folder_add_uid(CamelVeeFolder *vf, CamelFolder *f, const gchar *inuid, const gchar hash[8])
-{
-	CamelVeeMessageInfo *mi = NULL;
+	CAMEL_VEE_FOLDER_LOCK (vfolder, subfolder_lock);
 
-	mi = camel_vee_summary_add((CamelVeeSummary *)((CamelFolder *)vf)->summary, f->summary, (gchar *)inuid, hash);
-	return mi;
+	node = p->folders;
+	while (node) {
+		CamelFolder *f = node->data;
+
+		camel_folder_freeze (f);
+		node = node->next;
+	}
+
+	CAMEL_VEE_FOLDER_UNLOCK (vfolder, subfolder_lock);
+
+	/* call parent implementation */
+	CAMEL_FOLDER_CLASS (parent_class)->freeze (folder);
 }
 
 static void
-vee_folder_remove_folder(CamelVeeFolder *vf, CamelFolder *source)
+vee_folder_thaw (CamelFolder *folder)
 {
-	gint i, count, n, still = FALSE, start, last;
-	gchar *oldkey;
-	CamelFolder *folder = (CamelFolder *)vf;
-	gchar hash[8];
-	CamelFolderChangeInfo *vf_changes = NULL, *unmatched_changes = NULL;
-	gpointer oldval;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
-	CamelFolderSummary *ssummary = source->summary;
-	gint killun = FALSE;
+	CamelVeeFolder *vfolder = (CamelVeeFolder *)folder;
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vfolder);
+	GList *node;
 
-	if (vf == folder_unmatched)
-		return;
+	CAMEL_VEE_FOLDER_LOCK (vfolder, subfolder_lock);
 
-	if ((source->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED))
-		killun = TRUE;
+	node = p->folders;
+	while (node) {
+		CamelFolder *f = node->data;
 
-	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
+		camel_folder_thaw (f);
+		node = node->next;
+	}
 
-	if (folder_unmatched != NULL) {
-		/* check if this folder is still to be part of unmatched */
-		if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !killun) {
-			CAMEL_VEE_FOLDER_LOCK(folder_unmatched, subfolder_lock);
-			still = g_list_find(_PRIVATE(folder_unmatched)->folders, source) != NULL;
-			CAMEL_VEE_FOLDER_UNLOCK(folder_unmatched, subfolder_lock);
-			camel_vee_folder_hash_folder(source, hash);
-		}
+	CAMEL_VEE_FOLDER_UNLOCK (vfolder, subfolder_lock);
 
-		CAMEL_VEE_FOLDER_LOCK(folder_unmatched, summary_lock);
+	/* call parent implementation */
+	CAMEL_FOLDER_CLASS (parent_class)->thaw (folder);
+}
 
-		/* See if we just blow all uid's from this folder away from unmatched, regardless */
-		if (killun) {
-			start = -1;
-			last = -1;
-			count = camel_folder_summary_count(((CamelFolder *)folder_unmatched)->summary);
-			for (i=0;i<count;i++) {
-				CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index(((CamelFolder *)folder_unmatched)->summary, i);
+static void
+vee_folder_set_expression (CamelVeeFolder *vee_folder,
+                           const gchar *query)
+{
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vee_folder);
+	GList *node;
+	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
 
-				if (mi) {
-					if (mi->summary == ssummary) {
-						camel_folder_change_info_remove_uid(folder_unmatched->changes, camel_message_info_uid(mi));
-						if (last == -1) {
-							last = start = i;
-						} else if (last+1 == i) {
-							last = i;
-						} else {
-							camel_folder_summary_remove_range(((CamelFolder *)folder_unmatched)->summary, start, last);
-							i -= (last-start)+1;
-							start = last = i;
-						}
-					}
-					camel_message_info_free((CamelMessageInfo *)mi);
-				}
-			}
-			if (last != -1)
-				camel_folder_summary_remove_range(((CamelFolder *)folder_unmatched)->summary, start, last);
-		}
-	}
+	CAMEL_VEE_FOLDER_LOCK (vee_folder, subfolder_lock);
 
-	/*FIXME: This can be optimized a lot like, searching for UID in the summary uids */
-	start = -1;
-	last = -1;
-	count = camel_folder_summary_count(folder->summary);
-	for (i=0;i<count;i++) {
-		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index(folder->summary, i);
-		if (mi) {
-			if (mi->summary == ssummary) {
-				const gchar *uid = camel_message_info_uid(mi);
-
-				camel_folder_change_info_remove_uid(vf->changes, uid);
+	/* no change, do nothing */
+	if ((vee_folder->expression && query && strcmp (vee_folder->expression, query) == 0)
+	    || (vee_folder->expression == NULL && query == NULL)) {
+		CAMEL_VEE_FOLDER_UNLOCK (vee_folder, subfolder_lock);
+		return;
+	}
 
-				if (last == -1) {
-					last = start = i;
-				} else if (last+1 == i) {
-					last = i;
-				} else {
-					camel_folder_summary_remove_range(folder->summary, start, last);
-					i -= (last-start)+1;
-					start = last = i;
-				}
-				if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && folder_unmatched != NULL) {
-					if (still) {
-						if (g_hash_table_lookup_extended(unmatched_uids, uid, (gpointer *)&oldkey, &oldval)) {
-							n = GPOINTER_TO_INT (oldval);
-							if (n == 1) {
-								CamelMessageInfo *tinfo;
-								g_hash_table_remove(unmatched_uids, oldkey);
-								if ((tinfo = (CamelMessageInfo *) vee_folder_add_uid(folder_unmatched, source, oldkey+8, hash)) != NULL) {
-									camel_message_info_free (tinfo);
-									camel_folder_change_info_add_uid(folder_unmatched->changes, oldkey);
-								}
-								g_free(oldkey);
-							} else {
-								g_hash_table_insert(unmatched_uids, oldkey, GINT_TO_POINTER(n-1));
-							}
-						}
-					} else {
-						if (g_hash_table_lookup_extended(unmatched_uids, camel_message_info_uid(mi), (gpointer *)&oldkey, &oldval)) {
-							g_hash_table_remove(unmatched_uids, oldkey);
-							g_free(oldkey);
-						}
-					}
-				}
-			}
-			camel_message_info_free((CamelMessageInfo *)mi);
-		}
+	/* Recreate the table when the query changes, only if we are not setting it first */
+	if (vee_folder->expression) {
+		CamelFolderSummary *s = ((CamelFolder *)vee_folder)->summary;
+		camel_folder_summary_clear (s);
+		camel_db_recreate_vfolder (((CamelFolder *) vee_folder)->parent_store->cdb_w, ((CamelFolder *) vee_folder)->full_name, &ex);
+		camel_exception_clear (&ex);
+		s->junk_count = 0;
+		s->deleted_count = 0;
+		s->unread_count = 0;
+		s->visible_count = 0;
+		s->junk_not_deleted_count = 0;
 	}
 
-	if (last != -1)
-		camel_folder_summary_remove_range(folder->summary, start, last);
+	g_free (vee_folder->expression);
+	if (query)
+		vee_folder->expression = g_strdup (query);
 
-	if (folder_unmatched) {
-		if (camel_folder_change_info_changed(folder_unmatched->changes)) {
-			unmatched_changes = folder_unmatched->changes;
-			folder_unmatched->changes = camel_folder_change_info_new();
-		}
+	node = p->folders;
+	while (node) {
+		CamelFolder *f = node->data;
 
-		CAMEL_VEE_FOLDER_UNLOCK(folder_unmatched, summary_lock);
-	}
+		if (camel_vee_folder_rebuild_folder (vee_folder, f, &ex) == -1)
+			break;
 
-	if (camel_folder_change_info_changed(vf->changes)) {
-		vf_changes = vf->changes;
-		vf->changes = camel_folder_change_info_new();
+		camel_exception_clear (&ex);
+
+		node = node->next;
 	}
 
-	CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
+	camel_exception_clear (&ex);
 
-	if (unmatched_changes) {
-		camel_object_trigger_event((CamelObject *)folder_unmatched, "folder_changed", unmatched_changes);
-		camel_folder_change_info_free(unmatched_changes);
-	}
+	CAMEL_VEE_FOLDER_LOCK (vee_folder, changed_lock);
+	g_list_free (p->folders_changed);
+	p->folders_changed = NULL;
+	CAMEL_VEE_FOLDER_UNLOCK (vee_folder, changed_lock);
 
-	if (vf_changes) {
-		camel_object_trigger_event((CamelObject *)vf, "folder_changed", vf_changes);
-		camel_folder_change_info_free(vf_changes);
-	}
+	CAMEL_VEE_FOLDER_UNLOCK (vee_folder, subfolder_lock);
 }
 
-struct _update_data {
-	CamelFolder *source;
-	CamelVeeFolder *vf;
-	gchar hash[8];
-	CamelVeeFolder *folder_unmatched;
-	GHashTable *unmatched_uids;
-	gboolean rebuilt, correlating;
-};
-
 static void
-unmatched_check_uid(gchar *uidin, gpointer value, struct _update_data *u)
+vee_folder_add_folder (CamelVeeFolder *vee_folder,
+                       CamelFolder *sub)
 {
-	gchar *uid;
-	gint n;
+	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
 
-	uid = alloca(strlen(uidin)+9);
-	memcpy(uid, u->hash, 8);
-	strcpy(uid+8, uidin);
-	n = GPOINTER_TO_INT(g_hash_table_lookup(u->unmatched_uids, uid));
-	if (n == 0) {
-		if (vee_folder_add_uid(u->folder_unmatched, u->source, uidin, u->hash))
-			camel_folder_change_info_add_uid(u->folder_unmatched->changes, uid);
-	} else {
-		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_uid(((CamelFolder *)u->folder_unmatched)->summary, uid);
-		if (mi) {
-			CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-			camel_db_delete_uid_from_vfolder_transaction (((CamelFolder *)u->folder_unmatched)->parent_store->cdb_w, ((CamelFolder *)u->folder_unmatched)->full_name, uid, &ex);
-			camel_folder_summary_remove_uid_fast (((CamelFolder *)u->folder_unmatched)->summary, uid);
-			camel_folder_change_info_remove_uid(u->folder_unmatched->changes, uid);
-			camel_message_info_free((CamelMessageInfo *)mi);
-			camel_exception_clear (&ex);
-		}
-	}
+	vee_folder_rebuild_folder (vee_folder, sub, &ex);
+
+	camel_exception_clear (&ex);
 }
 
 static void
-folder_added_uid(gchar *uidin, gpointer value, struct _update_data *u)
+vee_folder_remove_folder (CamelVeeFolder *vee_folder,
+                          CamelFolder *sub)
 {
-	CamelVeeMessageInfo *mi;
-	gchar *oldkey;
-	gpointer oldval;
-	gint n;
+	gchar *shash, hash[8];
 
-	if ( (mi = vee_folder_add_uid(u->vf, u->source, uidin, u->hash)) ) {
-		camel_folder_change_info_add_uid(u->vf->changes, camel_message_info_uid(mi));
-		/* FIXME[disk-summary] Handle exceptions */
-		/* FIXME[disk-summary] Make all these as transactions, just
-		 * testing atm */
-		if (u->rebuilt && !u->correlating) {
-			CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-			camel_db_add_to_vfolder_transaction (((CamelFolder *) u->vf)->parent_store->cdb_w, ((CamelFolder *) u->vf)->full_name, (gchar *) camel_message_info_uid(mi), &ex);
-			camel_exception_clear (&ex);
-		}
-		if (!CAMEL_IS_VEE_FOLDER(u->source) && u->unmatched_uids != NULL) {
-			if (g_hash_table_lookup_extended(u->unmatched_uids, camel_message_info_uid(mi), (gpointer *)&oldkey, &oldval)) {
-				n = GPOINTER_TO_INT (oldval);
-				g_hash_table_insert(u->unmatched_uids, oldkey, GINT_TO_POINTER(n+1));
-			} else {
-				g_hash_table_insert(u->unmatched_uids, g_strdup(camel_message_info_uid(mi)), GINT_TO_POINTER(1));
-			}
-		}
-	}
+	camel_vee_folder_hash_folder (sub, hash);
+	vee_folder_remove_folder_helper (vee_folder, sub);
+	shash = g_strdup_printf (
+		"%c%c%c%c%c%c%c%c",
+		hash[0], hash[1], hash[2], hash[3],
+		hash[4], hash[5], hash[6], hash[7]);
+	if (g_hash_table_lookup (vee_folder->hashes, shash))
+		g_hash_table_remove (vee_folder->hashes, shash);
+	g_free (shash);
 }
 
-/* build query contents for a single folder */
 static gint
-vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex)
+vee_folder_rebuild_folder (CamelVeeFolder *vee_folder,
+                           CamelFolder *source,
+                           CamelException *ex)
 {
 	GPtrArray *match, *all;
 	GHashTable *allhash, *matchhash, *fullhash;
 	GSList *del_list = NULL;
-	CamelFolder *folder = (CamelFolder *)vf;
+	CamelFolder *folder = (CamelFolder *)vee_folder;
 	gint i, n, count, start, last;
 	struct _update_data u;
-	CamelFolderChangeInfo *vf_changes = NULL, *unmatched_changes = NULL;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
+	CamelFolderChangeInfo *vee_folder_changes = NULL, *unmatched_changes = NULL;
+	CamelVeeFolder *folder_unmatched = vee_folder->parent_vee_store ? vee_folder->parent_vee_store->folder_unmatched : NULL;
+	GHashTable *unmatched_uids = vee_folder->parent_vee_store ? vee_folder->parent_vee_store->unmatched_uids : NULL;
 	CamelFolderSummary *ssummary = source->summary;
 	gboolean rebuilded = FALSE;
 	gchar *shash;
 
-	/* Since the source of a correlating vfolder has to be requeried in
+	/* Since the source of a correlating vee_folderolder has to be requeried in
 	 * full every time it changes, caching the results in the db is not
 	 * worth the effort.  Thus, DB use is conditioned on !correlating. */
-	gboolean correlating = expression_is_correlating(vf->expression);
+	gboolean correlating = expression_is_correlating (vee_folder->expression);
 
-	if (vf == folder_unmatched)
+	if (vee_folder == folder_unmatched)
 		return 0;
 
-	camel_vee_folder_hash_folder(source, u.hash);
-	shash = g_strdup_printf("%c%c%c%c%c%c%c%c", u.hash[0], u.hash[1], u.hash[2], u.hash[3], u.hash[4], u.hash[5], u.hash[6], u.hash[7]);
-	if (!g_hash_table_lookup (vf->hashes, shash))
-		g_hash_table_insert (vf->hashes, g_strdup(shash), source->summary);
+	camel_vee_folder_hash_folder (source, u.hash);
+	shash = g_strdup_printf ("%c%c%c%c%c%c%c%c", u.hash[0], u.hash[1], u.hash[2], u.hash[3], u.hash[4], u.hash[5], u.hash[6], u.hash[7]);
+	if (!g_hash_table_lookup (vee_folder->hashes, shash))
+		g_hash_table_insert (vee_folder->hashes, g_strdup (shash), source->summary);
 
 	/* if we have no expression, or its been cleared, then act as if no matches */
-	if (vf->expression == NULL) {
-		match = g_ptr_array_new();
+	if (vee_folder->expression == NULL) {
+		match = g_ptr_array_new ();
 	} else {
 		if (!correlating) {
 			/* Load the folder results from the DB. */
@@ -1124,44 +1653,44 @@ vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex)
 			/* We take this to mean the results have not been cached.
 			 * XXX: It will also trigger if the result set is empty. */
 			match == NULL) {
-			match = camel_folder_search_by_expression(source, vf->expression, ex);
+			match = camel_folder_search_by_expression (source, vee_folder->expression, ex);
 			if (match == NULL) /* Search failed */
 				return 0;
 			rebuilded = TRUE;
 		}
 
 	}
-	dd(printf("vee_rebuild_folder(%s <- %s %s): match %d, correlating %d, rebuilded %d\n",
+	dd (printf ("vee_folder_rebuild_folder (%s <- %s %s): match %d, correlating %d, rebuilded %d\n",
 		folder->full_name, source->full_name, shash, match->len, correlating, rebuilded));
 
 	u.source = source;
-	u.vf = vf;
+	u.vee_folder = vee_folder;
 	u.folder_unmatched = folder_unmatched;
 	u.unmatched_uids = unmatched_uids;
 	u.rebuilt = rebuilded;
 	u.correlating = correlating;
 
-	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
+	CAMEL_VEE_FOLDER_LOCK (vee_folder, summary_lock);
 
 	/* we build 2 hash tables, one for all uid's not matched, the
 	   other for all matched uid's, we just ref the real memory */
-	matchhash = g_hash_table_new(g_str_hash, g_str_equal);
+	matchhash = g_hash_table_new (g_str_hash, g_str_equal);
 	for (i=0;i<match->len;i++)
-		g_hash_table_insert(matchhash, match->pdata[i], GINT_TO_POINTER (1));
+		g_hash_table_insert (matchhash, match->pdata[i], GINT_TO_POINTER (1));
 
-	allhash = g_hash_table_new(g_str_hash, g_str_equal);
-	fullhash = g_hash_table_new(g_str_hash, g_str_equal);
-	all = camel_folder_summary_array(source->summary);
+	allhash = g_hash_table_new (g_str_hash, g_str_equal);
+	fullhash = g_hash_table_new (g_str_hash, g_str_equal);
+	all = camel_folder_summary_array (source->summary);
 	for (i=0;i<all->len;i++) {
-		if (g_hash_table_lookup(matchhash, all->pdata[i]) == NULL)
-			g_hash_table_insert(allhash, all->pdata[i], GINT_TO_POINTER (1));
-		g_hash_table_insert(fullhash, all->pdata[i], GINT_TO_POINTER (1));
+		if (g_hash_table_lookup (matchhash, all->pdata[i]) == NULL)
+			g_hash_table_insert (allhash, all->pdata[i], GINT_TO_POINTER (1));
+		g_hash_table_insert (fullhash, all->pdata[i], GINT_TO_POINTER (1));
 
 	}
 	/* remove uids that can't be found in the source folder */
 	count = match->len;
 	for (i=0; i<count; i++) {
-		if (!g_hash_table_lookup(fullhash, match->pdata[i])) {
+		if (!g_hash_table_lookup (fullhash, match->pdata[i])) {
 			g_hash_table_remove (matchhash, match->pdata[i]);
 			del_list = g_slist_prepend (del_list, match->pdata[i]); /* Free the original */
 			g_ptr_array_remove_index_fast (match, i);
@@ -1172,79 +1701,79 @@ vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex)
 	}
 
 	if (folder_unmatched != NULL)
-		CAMEL_VEE_FOLDER_LOCK(folder_unmatched, summary_lock);
+		CAMEL_VEE_FOLDER_LOCK (folder_unmatched, summary_lock);
 
 	/* scan, looking for "old" uid's to be removed. "old" uid's
 	   are those that are from previous added sources (not in
 	   current source) */
 	start = -1;
 	last = -1;
-	count = camel_folder_summary_count(folder->summary);
+	count = camel_folder_summary_count (folder->summary);
 	for (i=0;i<count;i++) {
-		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index(folder->summary, i);
+		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index (folder->summary, i);
 
 		if (mi) {
 			if (mi->summary == ssummary) {
-				gchar *uid = (gchar *)camel_message_info_uid(mi), *oldkey;
+				gchar *uid = (gchar *)camel_message_info_uid (mi), *oldkey;
 				gpointer oldval;
 
-				if (g_hash_table_lookup(matchhash, uid+8) == NULL) {
+				if (g_hash_table_lookup (matchhash, uid+8) == NULL) {
 					if (last == -1) {
 						last = start = i;
 					} else if (last+1 == i) {
 						last = i;
 					} else {
-						camel_folder_summary_remove_range(folder->summary, start, last);
+						camel_folder_summary_remove_range (folder->summary, start, last);
 						i -= (last-start)+1;
 						start = last = i;
 					}
-					camel_folder_change_info_remove_uid(vf->changes, camel_message_info_uid(mi));
-					if (!CAMEL_IS_VEE_FOLDER(source)
+					camel_folder_change_info_remove_uid (vee_folder->changes, camel_message_info_uid (mi));
+					if (!CAMEL_IS_VEE_FOLDER (source)
 					    && unmatched_uids != NULL
-					    && g_hash_table_lookup_extended(unmatched_uids, uid, (gpointer *)&oldkey, &oldval)) {
+					    && g_hash_table_lookup_extended (unmatched_uids, uid, (gpointer *)&oldkey, &oldval)) {
 						n = GPOINTER_TO_INT (oldval);
 						if (n == 1) {
-							g_hash_table_remove(unmatched_uids, oldkey);
-							g_free(oldkey);
+							g_hash_table_remove (unmatched_uids, oldkey);
+							g_free (oldkey);
 						} else {
-							g_hash_table_insert(unmatched_uids, oldkey, GINT_TO_POINTER(n-1));
+							g_hash_table_insert (unmatched_uids, oldkey, GINT_TO_POINTER (n-1));
 						}
 					}
 				} else {
-					g_hash_table_remove(matchhash, uid+8);
+					g_hash_table_remove (matchhash, uid+8);
 				}
 			}
-			camel_message_info_free((CamelMessageInfo *)mi);
+			camel_message_info_free ((CamelMessageInfo *)mi);
 		}
 	}
 	if (last != -1)
-		camel_folder_summary_remove_range(folder->summary, start, last);
+		camel_folder_summary_remove_range (folder->summary, start, last);
 
 	/* now matchhash contains any new uid's, add them, etc */
 	if (rebuilded && !correlating) {
 		camel_db_begin_transaction (folder->parent_store->cdb_w, NULL);
 
 	}
-	g_hash_table_foreach(matchhash, (GHFunc)folder_added_uid, &u);
+	g_hash_table_foreach (matchhash, (GHFunc)folder_added_uid, &u);
 
 	if (rebuilded && !correlating)
 		camel_db_end_transaction (folder->parent_store->cdb_w, NULL);
 
 	if (folder_unmatched != NULL) {
 		/* scan unmatched, remove any that have vanished, etc */
-		count = camel_folder_summary_count(((CamelFolder *)folder_unmatched)->summary);
+		count = camel_folder_summary_count (((CamelFolder *)folder_unmatched)->summary);
 		for (i=0;i<count;i++) {
 			gchar *uid = camel_folder_summary_uid_from_index (((CamelFolder *)folder_unmatched)->summary, i);
 
 			if (uid) {
 				if (strncmp (uid, u.hash, 8) == 0) {
-					if (g_hash_table_lookup(allhash, uid+8) == NULL) {
+					if (g_hash_table_lookup (allhash, uid+8) == NULL) {
 						/* no longer exists at all, just remove it entirely */
-						camel_folder_summary_remove_index_fast(((CamelFolder *)folder_unmatched)->summary, i);
-						camel_folder_change_info_remove_uid(folder_unmatched->changes, uid);
+						camel_folder_summary_remove_index_fast (((CamelFolder *)folder_unmatched)->summary, i);
+						camel_folder_change_info_remove_uid (folder_unmatched->changes, uid);
 						i--;
 					} else {
-						g_hash_table_remove(allhash, uid+8);
+						g_hash_table_remove (allhash, uid+8);
 					}
 				}
 				g_free (uid);
@@ -1252,30 +1781,30 @@ vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex)
 		}
 
 		/* now allhash contains all potentially new uid's for the unmatched folder, process */
-		if (!CAMEL_IS_VEE_FOLDER(source))
-			g_hash_table_foreach(allhash, (GHFunc)unmatched_check_uid, &u);
+		if (!CAMEL_IS_VEE_FOLDER (source))
+			g_hash_table_foreach (allhash, (GHFunc)unmatched_check_uid, &u);
 
 		/* copy any changes so we can raise them outside the lock */
-		if (camel_folder_change_info_changed(folder_unmatched->changes)) {
+		if (camel_folder_change_info_changed (folder_unmatched->changes)) {
 			unmatched_changes = folder_unmatched->changes;
-			folder_unmatched->changes = camel_folder_change_info_new();
+			folder_unmatched->changes = camel_folder_change_info_new ();
 		}
 
-		CAMEL_VEE_FOLDER_UNLOCK(folder_unmatched, summary_lock);
+		CAMEL_VEE_FOLDER_UNLOCK (folder_unmatched, summary_lock);
 	}
 
-	if (camel_folder_change_info_changed(vf->changes)) {
-		vf_changes = vf->changes;
-		vf->changes = camel_folder_change_info_new();
+	if (camel_folder_change_info_changed (vee_folder->changes)) {
+		vee_folder_changes = vee_folder->changes;
+		vee_folder->changes = camel_folder_change_info_new ();
 	}
 
-	CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
+	CAMEL_VEE_FOLDER_UNLOCK (vee_folder, summary_lock);
 
 	/* Del the unwanted things from the summary, we don't hold any locks now. */
 	if (del_list) {
 		if (!correlating) {
 			CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-			camel_db_delete_vuids(folder->parent_store->cdb_w, folder->full_name, shash, del_list, &ex);
+			camel_db_delete_vuids (folder->parent_store->cdb_w, folder->full_name, shash, del_list, &ex);
 			camel_exception_clear (&ex);
 		}
 		((CamelVeeSummary *)folder->summary)->force_counts = TRUE;
@@ -1283,967 +1812,513 @@ vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex)
 		g_slist_free (del_list);
 	};
 
-	g_hash_table_destroy(matchhash);
-	g_hash_table_destroy(allhash);
-	g_hash_table_destroy(fullhash);
+	g_hash_table_destroy (matchhash);
+	g_hash_table_destroy (allhash);
+	g_hash_table_destroy (fullhash);
 
-	g_free(shash);
+	g_free (shash);
 	/* if expression not set, we only had a null list */
-	if (vf->expression == NULL || !rebuilded) {
+	if (vee_folder->expression == NULL || !rebuilded) {
 		g_ptr_array_foreach (match, (GFunc) camel_pstring_free, NULL);
-		g_ptr_array_free(match, TRUE);
+		g_ptr_array_free (match, TRUE);
 	} else
-		camel_folder_search_free(source, match);
+		camel_folder_search_free (source, match);
 	camel_folder_free_summary (source, all);
 
 	if (unmatched_changes) {
-		camel_object_trigger_event((CamelObject *)folder_unmatched, "folder_changed", unmatched_changes);
-		camel_folder_change_info_free(unmatched_changes);
+		camel_object_trigger_event ((CamelObject *)folder_unmatched, "folder_changed", unmatched_changes);
+		camel_folder_change_info_free (unmatched_changes);
 	}
 
-	if (vf_changes) {
-		camel_object_trigger_event((CamelObject *)vf, "folder_changed", vf_changes);
-		camel_folder_change_info_free(vf_changes);
+	if (vee_folder_changes) {
+		camel_object_trigger_event ((CamelObject *)vee_folder, "folder_changed", vee_folder_changes);
+		camel_folder_change_info_free (vee_folder_changes);
 	}
 
 	return 0;
 }
 
-/* Hold all these with summary lock and unmatched summary lock held */
 static void
-folder_changed_add_uid(CamelFolder *sub, const gchar *uid, const gchar hash[8], CamelVeeFolder *vf, gboolean use_db)
+vee_folder_folder_changed (CamelVeeFolder *vee_folder,
+                           CamelFolder *sub,
+                           CamelFolderChangeInfo *changes)
 {
-	CamelFolder *folder = (CamelFolder *)vf;
-	CamelVeeMessageInfo *vinfo;
-	const gchar *vuid;
-	gchar *oldkey;
-	gpointer oldval;
-	gint n;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vee_folder);
+	struct _folder_changed_msg *m;
+	CamelSession *session = ((CamelService *)((CamelFolder *)vee_folder)->parent_store)->session;
 
-	vinfo = vee_folder_add_uid(vf, sub, uid, hash);
-	if (vinfo == NULL)
+	if (p->destroyed)
 		return;
 
-	vuid = camel_message_info_uid(vinfo);
-	if (use_db) {
-		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-		camel_db_add_to_vfolder_transaction (folder->parent_store->cdb_w, folder->full_name, (gchar *)vuid, &ex);
-		camel_exception_clear (&ex);
-	}
-	camel_folder_change_info_add_uid(vf->changes,  vuid);
-	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER(sub) && folder_unmatched != NULL) {
-		if (g_hash_table_lookup_extended(unmatched_uids, vuid, (gpointer *)&oldkey, &oldval)) {
-			n = GPOINTER_TO_INT (oldval);
-			g_hash_table_insert(unmatched_uids, oldkey, GINT_TO_POINTER(n+1));
-		} else {
-			g_hash_table_insert(unmatched_uids, g_strdup(vuid), GINT_TO_POINTER (1));
-		}
-		vinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info((CamelFolder *)folder_unmatched, vuid);
-		if (vinfo) {
-			CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-			camel_folder_change_info_remove_uid(folder_unmatched->changes, vuid);
-			camel_db_delete_uid_from_vfolder_transaction (folder->parent_store->cdb_w, ((CamelFolder *)folder_unmatched)->full_name, vuid, &ex);
-			camel_folder_summary_remove_uid_fast(((CamelFolder *)folder_unmatched)->summary, vuid);
-			camel_folder_free_message_info((CamelFolder *)folder_unmatched, (CamelMessageInfo *)vinfo);
-			camel_exception_clear (&ex);
-		}
-	}
+	m = camel_session_thread_msg_new (session, &folder_changed_ops, sizeof (*m));
+	m->changes = camel_folder_change_info_new ();
+	camel_folder_change_info_cat (m->changes, changes);
+	m->sub = sub;
+	g_object_ref (sub);
+	m->vee_folder = vee_folder;
+	g_object_ref (vee_folder);
+	camel_session_thread_queue (session, &m->msg, 0);
 }
 
 static void
-folder_changed_remove_uid(CamelFolder *sub, const gchar *uid, const gchar hash[8], gint keep, CamelVeeFolder *vf, gboolean use_db)
+vee_folder_folder_renamed (CamelVeeFolder *vee_folder,
+                           CamelFolder *f,
+                           const gchar *old)
 {
-	CamelFolder *folder = (CamelFolder *)vf;
-	gchar *vuid, *oldkey;
-	gpointer oldval;
-	gint n;
-	CamelVeeMessageInfo *vinfo;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
+	gchar hash[8];
+	CamelVeeFolder *folder_unmatched = vee_folder->parent_vee_store ? vee_folder->parent_vee_store->folder_unmatched : NULL;
 
-	vuid = alloca(strlen(uid)+9);
-	memcpy(vuid, hash, 8);
-	strcpy(vuid+8, uid);
+	/* TODO: This could probably be done in another thread, tho it is pretty quick/memory bound */
 
-	camel_folder_change_info_remove_uid(vf->changes, vuid);
-	if (use_db) {
-		/* FIXME[disk-summary] Handle exception */
-		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-		camel_db_delete_uid_from_vfolder_transaction (folder->parent_store->cdb_w, folder->full_name, vuid, &ex);
-		camel_exception_clear (&ex);
-	}
-	camel_folder_summary_remove_uid_fast(folder->summary, vuid);
+	/* Life just got that little bit harder, if the folder is renamed, it means it breaks all of our uid's.
+	   We need to remove the old uid's, fix them up, then release the new uid's, for the uid's that match this folder */
 
-	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER(sub) && folder_unmatched != NULL) {
-		if (keep) {
-			if (g_hash_table_lookup_extended(unmatched_uids, vuid, (gpointer *)&oldkey, &oldval)) {
-				n = GPOINTER_TO_INT (oldval);
-				if (n == 1) {
-					g_hash_table_remove(unmatched_uids, oldkey);
-					if (vee_folder_add_uid(folder_unmatched, sub, uid, hash))
-						camel_folder_change_info_add_uid(folder_unmatched->changes, oldkey);
-					g_free(oldkey);
-				} else {
-					g_hash_table_insert(unmatched_uids, oldkey, GINT_TO_POINTER(n-1));
-				}
-			} else {
-				if (vee_folder_add_uid(folder_unmatched, sub, uid, hash))
-					camel_folder_change_info_add_uid(folder_unmatched->changes, oldkey);
-			}
-		} else {
-			if (g_hash_table_lookup_extended(unmatched_uids, vuid, (gpointer *)&oldkey, &oldval)) {
-				g_hash_table_remove(unmatched_uids, oldkey);
-				g_free(oldkey);
-			}
+	camel_vee_folder_hash_folder (f, hash);
 
-			vinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info((CamelFolder *)folder_unmatched, vuid);
-			if (vinfo) {
-				CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-				camel_folder_change_info_remove_uid(folder_unmatched->changes, vuid);
-				camel_db_delete_uid_from_vfolder_transaction (folder->parent_store->cdb_w, ((CamelFolder *)folder_unmatched)->full_name, vuid, &ex);
-				camel_folder_summary_remove_uid_fast(((CamelFolder *)folder_unmatched)->summary, vuid);
-				camel_folder_free_message_info((CamelFolder *)folder_unmatched, (CamelMessageInfo *)vinfo);
-				camel_exception_clear (&ex);
-			}
-		}
-	}
+	subfolder_renamed_update (vee_folder, f, hash);
+	if (folder_unmatched != NULL)
+		subfolder_renamed_update (folder_unmatched, f, hash);
 }
 
 static void
-folder_changed_change_uid(CamelFolder *sub, const gchar *uid, const gchar hash[8], CamelVeeFolder *vf, gboolean use_db)
+vee_folder_class_init (CamelVeeFolderClass *class)
 {
-	gchar *vuid;
-	CamelVeeMessageInfo *vinfo, *uinfo = NULL;
-	CamelMessageInfo *info;
-	CamelFolder *folder = (CamelFolder *)vf;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-
-	vuid = alloca(strlen(uid)+9);
-	memcpy(vuid, hash, 8);
-	strcpy(vuid+8, uid);
-
-	vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid(folder->summary, vuid);
-	if (folder_unmatched != NULL)
-		uinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid(((CamelFolder *)folder_unmatched)->summary, vuid);
-	if (vinfo || uinfo) {
-		info = camel_folder_get_message_info(sub, uid);
-		if (info) {
-			if (vinfo) {
-				camel_folder_change_info_change_uid(vf->changes, vuid);
-				camel_message_info_free((CamelMessageInfo *)vinfo);
-			}
-
-			if (uinfo) {
-				camel_folder_change_info_change_uid(folder_unmatched->changes, vuid);
-				camel_message_info_free((CamelMessageInfo *)uinfo);
-			}
-
-			camel_folder_free_message_info(sub, info);
-		} else {
-			if (vinfo) {
-				folder_changed_remove_uid(sub, uid, hash, FALSE, vf, use_db);
-				camel_message_info_free((CamelMessageInfo *)vinfo);
-			}
-			if (uinfo)
-				camel_message_info_free((CamelMessageInfo *)uinfo);
-		}
-	}
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+	CamelFolderClass *folder_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelVeeFolderPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = vee_folder_finalize;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = vee_folder_getv;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->refresh_info = vee_folder_refresh_info;
+	folder_class->sync = vee_folder_sync;
+	folder_class->expunge = vee_folder_expunge;
+	folder_class->get_message = vee_folder_get_message;
+	folder_class->append_message = vee_folder_append_message;
+	folder_class->transfer_messages_to = vee_folder_transfer_messages_to;
+	folder_class->search_by_expression = vee_folder_search_by_expression;
+	folder_class->search_by_uids = vee_folder_search_by_uids;
+	folder_class->count_by_expression = vee_folder_count_by_expression;
+	folder_class->delete = vee_folder_delete;
+	folder_class->freeze = vee_folder_freeze;
+	folder_class->thaw = vee_folder_thaw;
+
+	class->set_expression = vee_folder_set_expression;
+	class->add_folder = vee_folder_add_folder;
+	class->remove_folder = vee_folder_remove_folder;
+	class->rebuild_folder = vee_folder_rebuild_folder;
+	class->folder_changed = vee_folder_folder_changed;
+	class->folder_renamed = vee_folder_folder_renamed;
 }
 
-struct _folder_changed_msg {
-	CamelSessionThreadMsg msg;
-	CamelFolderChangeInfo *changes;
-	CamelFolder *sub;
-	CamelVeeFolder *vf;
-};
-
 static void
-folder_changed_change(CamelSession *session, CamelSessionThreadMsg *msg)
+vee_folder_init (CamelVeeFolder *vee_folder)
 {
-	struct _folder_changed_msg *m = (struct _folder_changed_msg *)msg;
-	CamelFolder *sub = m->sub;
-	CamelFolder *folder = (CamelFolder *)m->vf;
-	CamelVeeFolder *vf = m->vf;
-	CamelFolderChangeInfo *changes = m->changes;
-	gchar *vuid = NULL, hash[8];
-	const gchar *uid;
-	CamelVeeMessageInfo *vinfo;
-	gint i, vuidlen = 0;
-	CamelFolderChangeInfo *vf_changes = NULL, *unmatched_changes = NULL;
-	GPtrArray *matches_added = NULL, /* newly added, that match */
-		*matches_changed = NULL, /* newly changed, that now match */
-		*newchanged = NULL,
-		*changed;
-	GPtrArray *always_changed = NULL;
-	GHashTable *matches_hash;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
-	GPtrArray *present = NULL;
-
-	/* See vee_rebuild_folder. */
-	gboolean correlating = expression_is_correlating(vf->expression);
+	CamelFolder *folder = CAMEL_FOLDER (vee_folder);
 
-	/* Check the folder hasn't beem removed while we weren't watching */
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
-	if (g_list_find(_PRIVATE(vf)->folders, sub) == NULL) {
-		CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
-		return;
-	}
-
-	camel_vee_folder_hash_folder(sub, hash);
+	vee_folder->priv = CAMEL_VEE_FOLDER_GET_PRIVATE (vee_folder);
 
-	/* Lookup anything before we lock anything, to avoid deadlock with build_folder */
-
-	/* Find newly added that match */
-	if (changes->uid_added->len > 0) {
-		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-		dd(printf(" Searching for added matches '%s'\n", vf->expression));
-		matches_added = camel_folder_search_by_uids(sub, vf->expression, changes->uid_added, &ex);
-		camel_exception_clear (&ex);
-	}
-
-	/* TODO:
-	   In this code around here, we can work out if the search will affect the changes
-	   we had, and only re-search against them if they might have */
-
-	/* Search for changed items that newly match, but only if we dont have them */
-	changed = changes->uid_changed;
-	if (changed->len > 0) {
-		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-		dd(printf(" Searching for changed matches '%s'\n", vf->expression));
-
-		if ((vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO) == 0) {
-			newchanged = g_ptr_array_new();
-			always_changed = g_ptr_array_new();
-			for (i=0;i<changed->len;i++) {
-				uid = changed->pdata[i];
-				if (strlen(uid)+9 > vuidlen) {
-					vuidlen = strlen(uid)+64;
-					vuid = g_realloc(vuid, vuidlen);
-				}
-				memcpy(vuid, hash, 8);
-				strcpy(vuid+8, uid);
-				vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid(folder->summary, vuid);
-				if (vinfo == NULL) {
-					g_ptr_array_add(newchanged, (gchar *)uid);
-				} else {
-					g_ptr_array_add(always_changed, (gchar *)uid);
-					camel_message_info_free((CamelMessageInfo *)vinfo);
-				}
-			}
-			changed = newchanged;
-		}
-
-		if (changed->len)
-			matches_changed = camel_folder_search_by_uids(sub, vf->expression, changed, &ex);
-		camel_exception_clear (&ex);
-		if (always_changed && always_changed->len)
-			present = camel_folder_search_by_uids(sub, vf->expression, always_changed, &ex);
-		camel_exception_clear (&ex);
-	}
-
-	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
-
-	if (folder_unmatched != NULL)
-		CAMEL_VEE_FOLDER_LOCK(folder_unmatched, summary_lock);
+	folder->folder_flags |= (CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY |
+				 CAMEL_FOLDER_HAS_SEARCH_CAPABILITY);
 
-	if (matches_changed || matches_added || changes->uid_removed->len||present)
-		camel_db_begin_transaction (folder->parent_store->cdb_w, NULL);
+	/* FIXME: what to do about user flags if the subfolder doesn't support them? */
+	folder->permanent_flags = CAMEL_MESSAGE_ANSWERED |
+		CAMEL_MESSAGE_DELETED |
+		CAMEL_MESSAGE_DRAFT |
+		CAMEL_MESSAGE_FLAGGED |
+		CAMEL_MESSAGE_SEEN;
 
-	dd(printf("Vfolder '%s' subfolder changed '%s'\n", folder->full_name, sub->full_name));
-	dd(printf(" changed %u added %u removed %u\n", changes->uid_changed->len, changes->uid_added->len, changes->uid_removed->len));
+	vee_folder->changes = camel_folder_change_info_new ();
+	vee_folder->search = camel_folder_search_new ();
+	vee_folder->hashes = g_hash_table_new_full (
+		g_str_hash, g_str_equal, g_free, NULL);
 
-	/* Always remove removed uid's, in any case */
-	for (i=0;i<changes->uid_removed->len;i++) {
-		dd(printf("  removing uid '%s'\n", (gchar *)changes->uid_removed->pdata[i]));
-		folder_changed_remove_uid(sub, changes->uid_removed->pdata[i], hash, FALSE, vf, !correlating);
-	}
+	/* Loaded is no longer used.*/
+	vee_folder->loaded = NULL;
+	vee_folder->deleted = FALSE;
+	vee_folder->priv->summary_lock = g_mutex_new ();
+	vee_folder->priv->subfolder_lock = g_mutex_new ();
+	vee_folder->priv->changed_lock = g_mutex_new ();
+	vee_folder->priv->unread_vfolder = -1;
+}
 
-	/* Add any newly matched or to unmatched folder if they dont */
-	if (matches_added) {
-		matches_hash = g_hash_table_new(g_str_hash, g_str_equal);
-		for (i=0;i<matches_added->len;i++) {
-			dd(printf(" %s", (gchar *)matches_added->pdata[i]));
-			g_hash_table_insert(matches_hash, matches_added->pdata[i], matches_added->pdata[i]);
-		}
-		for (i=0;i<changes->uid_added->len;i++) {
-			uid = changes->uid_added->pdata[i];
-			if (g_hash_table_lookup(matches_hash, uid)) {
-				dd(printf("  adding uid '%s' [newly matched]\n", (gchar *)uid));
-				folder_changed_add_uid(sub, uid, hash, vf, !correlating);
-			} else if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
-				if (strlen(uid)+9 > vuidlen) {
-					vuidlen = strlen(uid)+64;
-					vuid = g_realloc(vuid, vuidlen);
-				}
-				memcpy(vuid, hash, 8);
-				strcpy(vuid+8, uid);
+GType
+camel_vee_folder_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER,
+			"CamelVeeFolder",
+			sizeof (CamelVeeFolderClass),
+			(GClassInitFunc) vee_folder_class_init,
+			sizeof (CamelVeeFolder),
+			(GInstanceInitFunc) vee_folder_init,
+			0);
 
-				if (!CAMEL_IS_VEE_FOLDER(sub) && folder_unmatched != NULL && g_hash_table_lookup(unmatched_uids, vuid) == NULL) {
-					dd(printf("  adding uid '%s' to Unmatched [newly unmatched]\n", (gchar *)uid));
-					vinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info((CamelFolder *)folder_unmatched, vuid);
-					if (vinfo == NULL) {
-						if (vee_folder_add_uid(folder_unmatched, sub, uid, hash))
-							camel_folder_change_info_add_uid(folder_unmatched->changes, vuid);
-					} else {
-						camel_folder_free_message_info((CamelFolder *)folder_unmatched, (CamelMessageInfo *)vinfo);
-					}
-				}
-			}
-		}
-		g_hash_table_destroy(matches_hash);
-	}
+	return type;
+}
 
-	/* Change any newly changed */
-	if (always_changed) {
-		if (correlating) {
-			/* Messages may be pulled in by the correlation even if
-			 * they do not match the expression individually, so it
-			 * would be wrong to preemptively remove anything here.
-			 * vee_rebuild_folder will make any necessary removals
-			 * when it re-queries the entire source folder. */
-			for (i=0;i<always_changed->len;i++)
-				folder_changed_change_uid(sub, always_changed->pdata[i], hash, vf, !correlating);
-		} else {
-			GHashTable *ht_present = g_hash_table_new (g_str_hash, g_str_equal);
+void
+camel_vee_folder_construct (CamelVeeFolder *vf, CamelStore *parent_store, const gchar *full, const gchar *name, guint32 flags)
+{
+	CamelFolder *folder = (CamelFolder *)vf;
 
-			for (i=0;present && i<present->len;i++) {
-				folder_changed_change_uid(sub, present->pdata[i], hash, vf, !correlating);
-				g_hash_table_insert (ht_present, present->pdata[i], present->pdata[i]);
-			}
+	vf->flags = flags;
+	camel_folder_construct (folder, parent_store, full, name);
 
-			for (i=0; i<always_changed->len; i++) {
-				if (!present || !g_hash_table_lookup(ht_present, always_changed->pdata[i]))
-					/* XXX: IIUC, these messages haven't been deleted from the
-					 * source folder, so shouldn't "keep" be set to TRUE? */
-					folder_changed_remove_uid(sub, always_changed->pdata[i], hash, TRUE, vf, !correlating);
-			}
+	folder->summary = camel_vee_summary_new (folder);
 
-			g_hash_table_destroy (ht_present);
-		}
-		g_ptr_array_free(always_changed, TRUE);
-	}
+	if (CAMEL_IS_VEE_STORE (parent_store))
+		vf->parent_vee_store = (CamelVeeStore *)parent_store;
+}
 
-	/* Change/add/remove any changed */
-	if (changes->uid_changed->len) {
-		/* If we are auto-updating, then re-check changed uids still match */
-		dd(printf(" Vfolder %supdate\nuids match:", (vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO)?"auto-":""));
-		matches_hash = g_hash_table_new(g_str_hash, g_str_equal);
-		for (i=0;matches_changed && i<matches_changed->len;i++) {
-			dd(printf(" %s", (gchar *)matches_changed->pdata[i]));
-			g_hash_table_insert(matches_hash, matches_changed->pdata[i], matches_changed->pdata[i]);
-		}
-		dd(printf("\n"));
+/**
+ * camel_vee_folder_new:
+ * @parent_store: the parent CamelVeeStore
+ * @full: the full path to the vfolder.
+ * @flags: flags of some kind
+ *
+ * Create a new CamelVeeFolder object.
+ *
+ * Return value: A new CamelVeeFolder widget.
+ **/
+CamelFolder *
+camel_vee_folder_new (CamelStore *parent_store, const gchar *full, guint32 flags)
+{
+	CamelVeeFolder *vf;
+	gchar *tmp;
 
-		for (i=0;i<changed->len;i++) {
-			uid = changed->pdata[i];
-			if (strlen(uid)+9 > vuidlen) {
-				vuidlen = strlen(uid)+64;
-				vuid = g_realloc(vuid, vuidlen);
-			}
-			memcpy(vuid, hash, 8);
-			strcpy(vuid+8, uid);
-			vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid(folder->summary, vuid);
-			if (vinfo == NULL) {
-				if (g_hash_table_lookup(matches_hash, uid)) {
-					/* A uid we dont have, but now it matches, add it */
-					dd(printf("  adding uid '%s' [newly matched]\n", uid));
-					folder_changed_add_uid(sub, uid, hash, vf, !correlating);
-				} else {
-					/* A uid we still don't have, just change it (for unmatched) */
-					folder_changed_change_uid(sub, uid, hash, vf, !correlating);
-				}
-			} else {
-				if ((vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO) == 0
-				    || g_hash_table_lookup(matches_hash, uid)) {
-					/* still match, or we're not auto-updating, change event, (if it changed) */
-					dd(printf("  changing uid '%s' [still matches]\n", uid));
-					folder_changed_change_uid(sub, uid, hash, vf, !correlating);
-				} else {
-					/* No longer matches, remove it, but keep it in unmatched (potentially) */
-					dd(printf("  removing uid '%s' [did match]\n", uid));
-					folder_changed_remove_uid(sub, uid, hash, TRUE, vf, !correlating);
-				}
-				camel_message_info_free((CamelMessageInfo *)vinfo);
-			}
-		}
-		g_hash_table_destroy(matches_hash);
+	if (CAMEL_IS_VEE_STORE (parent_store) && strcmp (full, CAMEL_UNMATCHED_NAME) == 0) {
+		vf = ((CamelVeeStore *)parent_store)->folder_unmatched;
+		g_object_ref (vf);
 	} else {
-		/* stuff didn't match but it changed - check unmatched folder for changes */
-		for (i=0;i<changed->len;i++)
-			folder_changed_change_uid(sub, changed->pdata[i], hash, vf, !correlating);
-	}
+		const gchar *name = strrchr (full, '/');
 
-	if (folder_unmatched != NULL) {
-		if (camel_folder_change_info_changed(folder_unmatched->changes)) {
-			unmatched_changes = folder_unmatched->changes;
-			folder_unmatched->changes = camel_folder_change_info_new();
-		}
-
-		CAMEL_VEE_FOLDER_UNLOCK(folder_unmatched, summary_lock);
-	}
-
-	if (camel_folder_change_info_changed(vf->changes)) {
-		vf_changes = vf->changes;
-		vf->changes = camel_folder_change_info_new();
+		if (name == NULL)
+			name = full;
+		else
+			name++;
+		vf = g_object_new (CAMEL_TYPE_VEE_FOLDER, NULL);
+		camel_vee_folder_construct (vf, parent_store, full, name, flags);
 	}
 
-	if (matches_changed || matches_added || changes->uid_removed->len || present)
-		camel_db_end_transaction (folder->parent_store->cdb_w, NULL);
-	CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
-
-	/* Cleanup stuff on our folder */
-	if (matches_added)
-		camel_folder_search_free(sub, matches_added);
-	if (present)
-		camel_folder_search_free (sub, present);
+	d (printf ("returning folder %s %p, count = %d\n", full, vf, camel_folder_get_message_count ((CamelFolder *)vf)));
 
-	if (matches_changed)
-		camel_folder_search_free(sub, matches_changed);
-
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
-
-	/* cleanup the rest */
-	if (newchanged)
-		g_ptr_array_free(newchanged, TRUE);
-
-	g_free(vuid);
-
-	if (unmatched_changes) {
-		camel_object_trigger_event((CamelObject *)folder_unmatched, "folder_changed", unmatched_changes);
-		camel_folder_change_info_free(unmatched_changes);
-	}
-
-	/* Add to folders_changed if we need to call vee_rebuild_folder, which
-	 * could be the case for two reasons:
-	 * - We changed the vfolder and it is not auto-updating.  Need to re-sync.
-	 * - Vfolder is correlating.  Changes to non-matching source messages
-	 *   won't be processed here and won't show up in vf_changes but may
-	 *   still affect the vfolder contents (e.g., non-matching messages
-	 *   added to a matching thread), so we re-run the query on the whole
-	 *   source folder.  (For match-threads, it may be enough to do this if
-	 *   changes->uid_added->len > 0, but I'm not completely sure and I'd
-	 *   rather be safe than sorry.)
-	 */
-	if ((vf_changes && (vf->flags & CAMEL_STORE_VEE_FOLDER_AUTO) == 0) || correlating) {
-		CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
-		if (g_list_find(vf->priv->folders_changed, sub) == NULL)
-			vf->priv->folders_changed = g_list_prepend(vf->priv->folders_changed, sub);
-		CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
-	}
-
-	if (vf_changes) {
-		camel_object_trigger_event((CamelObject *)vf, "folder_changed", vf_changes);
-		camel_folder_change_info_free(vf_changes);
+	if (vf) {
+		tmp = g_strdup_printf ("%s/%s.cmeta", ((CamelService *)parent_store)->url->path, full);
+		camel_object_set (vf, NULL, CAMEL_OBJECT_STATE_FILE, tmp, NULL);
+		g_free (tmp);
+		if (camel_object_state_read (vf) == -1) {
+			/* setup defaults: we have none currently */
+		}
 	}
+	return (CamelFolder *)vf;
 }
 
-static void
-folder_changed_free(CamelSession *session, CamelSessionThreadMsg *msg)
-{
-	struct _folder_changed_msg *m = (struct _folder_changed_msg *)msg;
-
-	camel_folder_change_info_free(m->changes);
-	camel_object_unref((CamelObject *)m->vf);
-	camel_object_unref((CamelObject *)m->sub);
-}
-
-static CamelSessionThreadOps folder_changed_ops = {
-	folder_changed_change,
-	folder_changed_free,
-};
-
-static void
-folder_changed_base(CamelVeeFolder *vf, CamelFolder *sub, CamelFolderChangeInfo *changes)
-{
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	struct _folder_changed_msg *m;
-	CamelSession *session = ((CamelService *)((CamelFolder *)vf)->parent_store)->session;
-
-	if (p->destroyed)
-		return;
-
-	m = camel_session_thread_msg_new(session, &folder_changed_ops, sizeof(*m));
-	m->changes = camel_folder_change_info_new();
-	camel_folder_change_info_cat(m->changes, changes);
-	m->sub = sub;
-	camel_object_ref((CamelObject *)sub);
-	m->vf = vf;
-	camel_object_ref((CamelObject *)vf);
-	camel_session_thread_queue(session, &m->msg, 0);
-}
-
-static void
-folder_changed(CamelFolder *sub, CamelFolderChangeInfo *changes, CamelVeeFolder *vf)
-{
-	((CamelVeeFolderClass *)((CamelObject *)vf)->klass)->folder_changed(vf, sub, changes);
-}
-
-/* track vanishing folders */
-static void
-subfolder_deleted(CamelFolder *f, gpointer event_data, CamelVeeFolder *vf)
+void
+camel_vee_folder_set_expression (CamelVeeFolder *vf, const gchar *query)
 {
-	camel_vee_folder_remove_folder(vf, f);
+	CAMEL_VEE_FOLDER_GET_CLASS (vf)->set_expression (vf, query);
 }
 
-static void
-subfolder_renamed_update(CamelVeeFolder *vf, CamelFolder *sub, gchar hash[8])
+/**
+ * camel_vee_folder_add_folder:
+ * @vf: Virtual Folder object
+ * @sub: source CamelFolder to add to @vf
+ *
+ * Adds @sub as a source folder to @vf.
+ **/
+void
+camel_vee_folder_add_folder (CamelVeeFolder *vf, CamelFolder *sub)
 {
-	gint count, i;
-	CamelFolderChangeInfo *changes = NULL;
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	gint i;
 	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
-	CamelFolderSummary *ssummary = sub->summary;
 
-	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
-
-	count = camel_folder_summary_count(((CamelFolder *)vf)->summary);
-	for (i=0;i<count;i++) {
-		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)camel_folder_summary_index(((CamelFolder *)vf)->summary, i);
-		CamelVeeMessageInfo *vinfo;
-
-		if (mi == NULL)
-			continue;
-
-		if (mi->summary == ssummary) {
-			gchar *uid = (gchar *)camel_message_info_uid(mi);
-			gchar *oldkey;
-			gpointer oldval;
+	if (vf == (CamelVeeFolder *)sub) {
+		g_warning ("Adding a virtual folder to itself as source, ignored");
+		return;
+	}
 
-			camel_folder_change_info_remove_uid(vf->changes, uid);
-			camel_folder_summary_remove(((CamelFolder *)vf)->summary, (CamelMessageInfo *)mi);
+	CAMEL_VEE_FOLDER_LOCK (vf, subfolder_lock);
 
-			/* works since we always append on the end */
-			i--;
-			count--;
+	/* for normal vfolders we want only unique ones, for unmatched we want them all recorded */
+	if (g_list_find (p->folders, sub) == NULL) {
+		g_object_ref (sub);
+		p->folders = g_list_append (p->folders, sub);
 
-			vinfo = vee_folder_add_uid(vf, sub, uid+8, hash);
-			if (vinfo) {
-				camel_folder_change_info_add_uid(vf->changes, camel_message_info_uid(vinfo));
+		CAMEL_FOLDER_LOCK (vf, change_lock);
 
-				/* check unmatched uid's table for any matches */
-				if (vf == folder_unmatched
-				    && g_hash_table_lookup_extended(unmatched_uids, uid, (gpointer *)&oldkey, &oldval)) {
-					g_hash_table_remove(unmatched_uids, oldkey);
-					g_hash_table_insert(unmatched_uids, g_strdup(camel_message_info_uid(vinfo)), oldval);
-					g_free(oldkey);
-				}
-			}
-		}
+		/* update the freeze state of 'sub' to match our freeze state */
+		for (i = 0; i < ((CamelFolder *)vf)->priv->frozen; i++)
+			camel_folder_freeze (sub);
 
-		camel_message_info_free((CamelMessageInfo *)mi);
+		CAMEL_FOLDER_UNLOCK (vf, change_lock);
 	}
+	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER (sub) && folder_unmatched != NULL) {
+		CamelVeeFolderPrivate *up = CAMEL_VEE_FOLDER_GET_PRIVATE (folder_unmatched);
+		g_object_ref (sub);
+		up->folders = g_list_append (up->folders, sub);
 
-	if (camel_folder_change_info_changed(vf->changes)) {
-		changes = vf->changes;
-		vf->changes = camel_folder_change_info_new();
-	}
+		CAMEL_FOLDER_LOCK (folder_unmatched, change_lock);
 
-	CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
+		/* update the freeze state of 'sub' to match Unmatched's freeze state */
+		for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
+			camel_folder_freeze (sub);
 
-	if (changes) {
-		camel_object_trigger_event((CamelObject *)vf, "folder_changed", changes);
-		camel_folder_change_info_free(changes);
+		CAMEL_FOLDER_UNLOCK (folder_unmatched, change_lock);
 	}
-}
-
-static void
-folder_renamed_base(CamelVeeFolder *vf, CamelFolder *f, const gchar *old)
-{
-	gchar hash[8];
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
 
-	/* TODO: This could probably be done in another thread, tho it is pretty quick/memory bound */
+	CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
 
-	/* Life just got that little bit harder, if the folder is renamed, it means it breaks all of our uid's.
-	   We need to remove the old uid's, fix them up, then release the new uid's, for the uid's that match this folder */
+	d (printf ("camel_vee_folder_add_folder (%s, %s)\n", ((CamelFolder *)vf)->full_name, sub->full_name));
 
-	camel_vee_folder_hash_folder(f, hash);
+	camel_object_hook_event ((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc)folder_changed, vf);
+	camel_object_hook_event ((CamelObject *)sub, "deleted", (CamelObjectEventHookFunc)subfolder_deleted, vf);
+	camel_object_hook_event ((CamelObject *)sub, "renamed", (CamelObjectEventHookFunc)folder_renamed, vf);
 
-	subfolder_renamed_update(vf, f, hash);
-	if (folder_unmatched != NULL)
-		subfolder_renamed_update(folder_unmatched, f, hash);
+	CAMEL_VEE_FOLDER_GET_CLASS (vf)->add_folder (vf, sub);
 }
 
-static void
-folder_renamed(CamelFolder *sub, const gchar *old, CamelVeeFolder *vf)
-{
-	((CamelVeeFolderClass *)((CamelObject *)vf)->klass)->folder_renamed(vf, sub, old);
-}
+/**
+ * camel_vee_folder_remove_folder:
+ * @vf: Virtual Folder object
+ * @sub: source CamelFolder to remove from @vf
+ *
+ * Removed the source folder, @sub, from the virtual folder, @vf.
+ **/
+void
 
-static void
-vee_freeze (CamelFolder *folder)
+camel_vee_folder_remove_folder (CamelVeeFolder *vf, CamelFolder *sub)
 {
-	CamelVeeFolder *vfolder = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vfolder);
-	GList *node;
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	gint i;
+	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
 
-	CAMEL_VEE_FOLDER_LOCK(vfolder, subfolder_lock);
+	CAMEL_VEE_FOLDER_LOCK (vf, subfolder_lock);
 
-	node = p->folders;
-	while (node) {
-		CamelFolder *f = node->data;
+	CAMEL_VEE_FOLDER_LOCK (vf, changed_lock);
+	p->folders_changed = g_list_remove (p->folders_changed, sub);
+	CAMEL_VEE_FOLDER_UNLOCK (vf, changed_lock);
 
-		camel_folder_freeze(f);
-		node = node->next;
+	if (g_list_find (p->folders, sub) == NULL) {
+		CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
+		return;
 	}
 
-	CAMEL_VEE_FOLDER_UNLOCK(vfolder, subfolder_lock);
+	camel_object_unhook_event ((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
+	camel_object_unhook_event ((CamelObject *)sub, "deleted", (CamelObjectEventHookFunc) subfolder_deleted, vf);
+	camel_object_unhook_event ((CamelObject *)sub, "renamed", (CamelObjectEventHookFunc) folder_renamed, vf);
 
-	/* call parent implementation */
-	CAMEL_FOLDER_CLASS (camel_vee_folder_parent)->freeze(folder);
-}
+	p->folders = g_list_remove (p->folders, sub);
 
-static void
-vee_thaw(CamelFolder *folder)
-{
-	CamelVeeFolder *vfolder = (CamelVeeFolder *)folder;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vfolder);
-	GList *node;
+	/* undo the freeze state that we have imposed on this source folder */
+	CAMEL_FOLDER_LOCK (vf, change_lock);
+	for (i = 0; i < ((CamelFolder *)vf)->priv->frozen; i++)
+		camel_folder_thaw (sub);
+	CAMEL_FOLDER_UNLOCK (vf, change_lock);
 
-	CAMEL_VEE_FOLDER_LOCK(vfolder, subfolder_lock);
+	CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
 
-	node = p->folders;
-	while (node) {
-		CamelFolder *f = node->data;
+	if (folder_unmatched != NULL) {
+		CamelVeeFolderPrivate *up = CAMEL_VEE_FOLDER_GET_PRIVATE (folder_unmatched);
 
-		camel_folder_thaw(f);
-		node = node->next;
-	}
+		CAMEL_VEE_FOLDER_LOCK (folder_unmatched, subfolder_lock);
+		/* if folder deleted, then blow it away from unmatched always, and remove all refs to it */
+		if (sub->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED) {
+			while (g_list_find (up->folders, sub)) {
+				up->folders = g_list_remove (up->folders, sub);
+				g_object_unref (sub);
 
-	CAMEL_VEE_FOLDER_UNLOCK(vfolder, subfolder_lock);
+				/* undo the freeze state that Unmatched has imposed on this source folder */
+				CAMEL_FOLDER_LOCK (folder_unmatched, change_lock);
+				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
+					camel_folder_thaw (sub);
+				CAMEL_FOLDER_UNLOCK (folder_unmatched, change_lock);
+			}
+		} else if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
+			if (g_list_find (up->folders, sub) != NULL) {
+				up->folders = g_list_remove (up->folders, sub);
+				g_object_unref (sub);
 
-	/* call parent implementation */
-	CAMEL_FOLDER_CLASS (camel_vee_folder_parent)->thaw(folder);
-}
+				/* undo the freeze state that Unmatched has imposed on this source folder */
+				CAMEL_FOLDER_LOCK (folder_unmatched, change_lock);
+				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
+					camel_folder_thaw (sub);
+				CAMEL_FOLDER_UNLOCK (folder_unmatched, change_lock);
+			}
+		}
+		CAMEL_VEE_FOLDER_UNLOCK (folder_unmatched, subfolder_lock);
+	}
 
-/* vfolder base implementaitons */
-static void
-vee_add_folder(CamelVeeFolder *vf, CamelFolder *sub)
-{
-	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+	CAMEL_VEE_FOLDER_GET_CLASS (vf)->remove_folder (vf, sub);
 
-	vee_rebuild_folder (vf, sub, &ex);
+	if (CAMEL_IS_VEE_FOLDER (sub))
+		return;
 
-	camel_exception_clear (&ex);
+	g_object_unref (sub);
 }
 
-static void
-vee_remove_folder(CamelVeeFolder *vf, CamelFolder *sub)
+/**
+ * camel_vee_folder_rebuild_folder:
+ * @vf: Virtual Folder object
+ * @sub: source CamelFolder to add to @vf
+ * @ex: Exception.
+ *
+ * Rebuild the folder @sub, if it should be.
+ **/
+gint
+camel_vee_folder_rebuild_folder (CamelVeeFolder *vf, CamelFolder *sub, CamelException *ex)
 {
-	gchar *shash, hash[8];
-
-	camel_vee_folder_hash_folder(sub, hash);
-	vee_folder_remove_folder(vf, sub);
-	shash = g_strdup_printf("%c%c%c%c%c%c%c%c", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7]);
-	if (g_hash_table_lookup (vf->hashes, shash))
-		g_hash_table_remove (vf->hashes, shash);
-
-	g_free(shash);
-
+	return CAMEL_VEE_FOLDER_GET_CLASS (vf)->rebuild_folder (vf, sub, ex);
 }
 
 static void
-vee_set_expression(CamelVeeFolder *vf, const gchar *query)
+remove_folders (CamelFolder *folder, CamelFolder *foldercopy, CamelVeeFolder *vf)
 {
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	GList *node;
-	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
-
-	/* no change, do nothing */
-	if ((vf->expression && query && strcmp(vf->expression, query) == 0)
-	    || (vf->expression == NULL && query == NULL)) {
-		CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
-		return;
-	}
-
-	/* Recreate the table when the query changes, only if we are not setting it first */
-	if (vf->expression) {
-		CamelFolderSummary *s = ((CamelFolder *)vf)->summary;
-		camel_folder_summary_clear (s);
-		camel_db_recreate_vfolder (((CamelFolder *) vf)->parent_store->cdb_w, ((CamelFolder *) vf)->full_name, &ex);
-		camel_exception_clear (&ex);
-		s->junk_count = 0;
-		s->deleted_count = 0;
-		s->unread_count = 0;
-		s->visible_count = 0;
-		s->junk_not_deleted_count = 0;
-	}
-
-	g_free(vf->expression);
-	if (query)
-		vf->expression = g_strdup(query);
-
-	node = p->folders;
-	while (node) {
-		CamelFolder *f = node->data;
-
-		if (camel_vee_folder_rebuild_folder (vf, f, &ex) == -1)
-			break;
-
-		camel_exception_clear (&ex);
-
-		node = node->next;
-	}
-
-	camel_exception_clear (&ex);
-
-	CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
-	g_list_free(p->folders_changed);
-	p->folders_changed = NULL;
-	CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
-
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
+	camel_vee_folder_remove_folder (vf, folder);
+	g_object_unref (folder);
 }
 
-/* This entire code will be useless, since we sync the counts always. */
-static gint
-vf_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
+/**
+ * camel_vee_folder_set_folders:
+ * @vf:
+ * @folders:
+ *
+ * Set the whole list of folder sources on a vee folder.
+ **/
+void
+camel_vee_folder_set_folders (CamelVeeFolder *vf, GList *folders)
 {
-	CamelFolder *folder = (CamelFolder *)object;
-	CamelVeeFolder *vf = (CamelVeeFolder *)folder;
-	gint i;
-	guint32 tag;
-	gint unread = -1, deleted = 0, junked = 0, visible = 0, count = -1, junked_not_deleted = -1;
-
-	for (i=0;i<args->argc;i++) {
-		CamelArgGet *arg = &args->argv[i];
-
-		tag = arg->tag;
-
-		/* NB: this is a copy of camel-folder.c with the unread count logic altered.
-		   makes sure its still atomically calculated */
-		switch (tag & CAMEL_ARG_TAG) {
-		case CAMEL_FOLDER_ARG_UNREAD:
-		case CAMEL_FOLDER_ARG_DELETED:
-		case CAMEL_FOLDER_ARG_JUNKED:
-		case CAMEL_FOLDER_ARG_JUNKED_NOT_DELETED:
-		case CAMEL_FOLDER_ARG_VISIBLE:
-
-			if (vf->expression && vf->priv->unread_vfolder == -1)
-				camel_vee_summary_load_check_unread_vfolder ((CamelVeeSummary *)folder->summary);
-
-			/* This is so we can get the values atomically, and also so we can calculate them only once */
-			if (unread == -1) {
-				gint j;
-				CamelMessageInfoBase *info;
-				CamelVeeMessageInfo *vinfo;
-
-				unread = deleted = visible = junked = junked_not_deleted = 0;
-				count = camel_folder_summary_count(folder->summary);
-				for (j=0; j<count; j++) {
-					if ((info = (CamelMessageInfoBase *) camel_folder_summary_index(folder->summary, j))) {
-						guint32 flags;
-
-						vinfo = (CamelVeeMessageInfo *) info;
-						flags = vinfo->old_flags; /* ? vinfo->old_flags : camel_message_info_flags(info); */
-
-						if ((flags & (CAMEL_MESSAGE_SEEN)) == 0)
-							unread++;
-						if (flags & CAMEL_MESSAGE_DELETED)
-							deleted++;
-						if (flags & CAMEL_MESSAGE_JUNK) {
-							junked++;
-								if (! (flags & CAMEL_MESSAGE_DELETED))
-									junked_not_deleted++;
-						}
-						if ((flags & (CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK)) == 0)
-							visible++;
-						camel_message_info_free(info);
-					}
-				}
-			}
+	CamelVeeFolderPrivate *p = CAMEL_VEE_FOLDER_GET_PRIVATE (vf);
+	GHashTable *remove = g_hash_table_new (NULL, NULL);
+	GList *l;
+	CamelFolder *folder;
 
-			switch (tag & CAMEL_ARG_TAG) {
-			case CAMEL_FOLDER_ARG_UNREAD:
-				if (vf->priv->unread_vfolder == 1)
-					count = unread == -1 ? 0 : unread - junked_not_deleted;
-				else
-					count = unread == -1 ? 0 : unread;
-				break;
-			case CAMEL_FOLDER_ARG_DELETED:
-				count = deleted == -1 ? 0 : deleted;
-				break;
-			case CAMEL_FOLDER_ARG_JUNKED:
-				count = junked == -1 ? 0 : junked;
-				break;
-			case CAMEL_FOLDER_ARG_JUNKED_NOT_DELETED:
-				count = junked_not_deleted == -1 ? 0 : junked_not_deleted;
-				break;
-			case CAMEL_FOLDER_ARG_VISIBLE:
-				if (vf->priv->unread_vfolder == 1)
-					count = unread == -1 ? 0 : unread - junked_not_deleted;
-				else
-					count = visible == -1 ? 0 : visible;
+	/* setup a table of all folders we have currently */
+	CAMEL_VEE_FOLDER_LOCK (vf, subfolder_lock);
+	l = p->folders;
+	while (l) {
+		g_hash_table_insert (remove, l->data, l->data);
+		g_object_ref (l->data);
+		l = l->next;
+	}
+	CAMEL_VEE_FOLDER_UNLOCK (vf, subfolder_lock);
 
-				break;
-			}
-			folder->summary->unread_count = unread == -1 ? 0 : unread;
-			folder->summary->deleted_count = deleted == -1 ? 0 : deleted;
-			junked = folder->summary->junk_count = junked == -1 ? 0 : junked;
-			folder->summary->junk_not_deleted_count = junked_not_deleted == -1 ? 0 : junked_not_deleted;
-			folder->summary->visible_count = visible == -1 ? 0 : visible;
-			*arg->ca_int = count;
-			break;
-		default:
-			continue;
+	/* if we already have the folder, ignore it, otherwise add it */
+	l = folders;
+	while (l) {
+		if ((folder = g_hash_table_lookup (remove, l->data))) {
+			g_hash_table_remove (remove, folder);
+			g_object_unref (folder);
+		} else {
+			camel_vee_folder_add_folder (vf, l->data);
 		}
-
-		arg->tag = (tag & CAMEL_ARG_TYPE) | CAMEL_ARG_IGNORE;
+		l = l->next;
 	}
 
-	return ((CamelObjectClass *)camel_vee_folder_parent)->getv(object, ex, args);
+	/* then remove any we still have */
+	g_hash_table_foreach (remove, (GHFunc)remove_folders, vf);
+	g_hash_table_destroy (remove);
 }
 
-static void
-camel_vee_folder_class_init (CamelVeeFolderClass *klass)
+/**
+ * camel_vee_folder_hash_folder:
+ * @folder:
+ * @:
+ *
+ * Create a hash string representing the folder name, which should be
+ * unique, and remain static for a given folder.
+ **/
+void
+camel_vee_folder_hash_folder (CamelFolder *folder, gchar buffer[8])
 {
-	CamelFolderClass *folder_class = (CamelFolderClass *) klass;
-
-	camel_vee_folder_parent = CAMEL_FOLDER_CLASS(camel_type_get_global_classfuncs (camel_folder_get_type ()));
-
-	((CamelObjectClass *)klass)->getv = vf_getv;
-
-	folder_class->refresh_info = vee_refresh_info;
-	folder_class->sync = vee_sync;
-	folder_class->expunge = vee_expunge;
-
-	folder_class->get_message = vee_get_message;
-	folder_class->append_message = vee_append_message;
-	folder_class->transfer_messages_to = vee_transfer_messages_to;
+	GChecksum *checksum;
+	guint8 *digest;
+	gsize length;
+	gint state = 0, save = 0;
+	gchar *tmp;
+	gint i;
 
-	folder_class->search_by_expression = vee_search_by_expression;
-	folder_class->search_by_uids = vee_search_by_uids;
-	folder_class->count_by_expression = vee_count_by_expression;
+	length = g_checksum_type_get_length (G_CHECKSUM_MD5);
+	digest = g_alloca (length);
 
-	folder_class->rename = vee_rename;
-	folder_class->delete = vee_delete;
+	checksum = g_checksum_new (G_CHECKSUM_MD5);
+	tmp = camel_service_get_url ((CamelService *)folder->parent_store);
+	g_checksum_update (checksum, (guchar *) tmp, -1);
+	g_free (tmp);
+	tmp = folder->full_name;
+	g_checksum_update (checksum, (guchar *) tmp, -1);
+	g_checksum_get_digest (checksum, digest, &length);
+	g_checksum_free (checksum);
 
-	folder_class->freeze = vee_freeze;
-	folder_class->thaw = vee_thaw;
+	g_base64_encode_step (digest, 6, FALSE, buffer, &state, &save);
+	g_base64_encode_close (FALSE, buffer, &state, &save);
 
-	klass->set_expression = vee_set_expression;
-	klass->add_folder = vee_add_folder;
-	klass->remove_folder = vee_remove_folder;
-	klass->rebuild_folder = vee_rebuild_folder;
-	klass->folder_changed = folder_changed_base;
-	klass->folder_renamed = folder_renamed_base;
+	for (i=0;i<8;i++) {
+		if (buffer[i] == '+')
+			buffer[i] = '.';
+		if (buffer[i] == '/')
+			buffer[i] = '_';
+	}
 }
 
-static void
-camel_vee_folder_init (CamelVeeFolder *obj)
+/**
+ * camel_vee_folder_get_location:
+ * @vf:
+ * @vinfo:
+ * @realuid: if not NULL, set to the uid of the real message, must be
+ * g_free'd by caller.
+ *
+ * Find the real folder (and uid)
+ *
+ * Return value:
+ **/
+CamelFolder *
+camel_vee_folder_get_location (CamelVeeFolder *vf, const CamelVeeMessageInfo *vinfo, gchar **realuid)
 {
-	struct _CamelVeeFolderPrivate *p;
-	CamelFolder *folder = (CamelFolder *)obj;
+	CamelFolder *folder;
 
-	p = _PRIVATE(obj) = g_malloc0(sizeof(*p));
+	folder = vinfo->summary->folder;
 
-	folder->folder_flags |= (CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY |
-				 CAMEL_FOLDER_HAS_SEARCH_CAPABILITY);
+	/* locking?  yes?  no?  although the vfolderinfo is valid when obtained
+	   the folder in it might not necessarily be so ...? */
+	if (CAMEL_IS_VEE_FOLDER (folder)) {
+		CamelFolder *res;
+		const CamelVeeMessageInfo *vfinfo;
 
-	/* FIXME: what to do about user flags if the subfolder doesn't support them? */
-	folder->permanent_flags = CAMEL_MESSAGE_ANSWERED |
-		CAMEL_MESSAGE_DELETED |
-		CAMEL_MESSAGE_DRAFT |
-		CAMEL_MESSAGE_FLAGGED |
-		CAMEL_MESSAGE_SEEN;
+		vfinfo = (CamelVeeMessageInfo *)camel_folder_get_message_info (folder, camel_message_info_uid (vinfo)+8);
+		res = camel_vee_folder_get_location ((CamelVeeFolder *)folder, vfinfo, realuid);
+		camel_folder_free_message_info (folder, (CamelMessageInfo *)vfinfo);
+		return res;
+	} else {
+		if (realuid)
+			*realuid = g_strdup (camel_message_info_uid (vinfo)+8);
 
-	obj->changes = camel_folder_change_info_new();
-	obj->search = camel_folder_search_new();
-	obj->hashes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-	/* Loaded is no longer used.*/
-	obj->loaded = NULL;
-	obj->deleted = FALSE;
-	p->summary_lock = g_mutex_new();
-	p->subfolder_lock = g_mutex_new();
-	p->changed_lock = g_mutex_new();
-	p->unread_vfolder = -1;
+		return folder;
+	}
 }
 
 void
 camel_vee_folder_mask_event_folder_changed (CamelVeeFolder *vf, CamelFolder *sub)
 {
-	camel_object_unhook_event((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
+	camel_object_unhook_event ((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
 
 }
 
 void
 camel_vee_folder_unmask_event_folder_changed (CamelVeeFolder *vf, CamelFolder *sub)
 {
-	camel_object_hook_event((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
-}
-
-static void
-vee_folder_stop_folder(CamelVeeFolder *vf, CamelFolder *sub)
-{
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	gint i;
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-
-	CAMEL_VEE_FOLDER_LOCK(vf, subfolder_lock);
-
-	CAMEL_VEE_FOLDER_LOCK(vf, changed_lock);
-	p->folders_changed = g_list_remove(p->folders_changed, sub);
-	CAMEL_VEE_FOLDER_UNLOCK(vf, changed_lock);
-
-	if (g_list_find(p->folders, sub) == NULL) {
-		CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
-		return;
-	}
-
-	camel_object_unhook_event((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
-	camel_object_unhook_event((CamelObject *)sub, "deleted", (CamelObjectEventHookFunc) subfolder_deleted, vf);
-	camel_object_unhook_event((CamelObject *)sub, "renamed", (CamelObjectEventHookFunc) folder_renamed, vf);
-
-	p->folders = g_list_remove(p->folders, sub);
-
-	/* undo the freeze state that we have imposed on this source folder */
-	CAMEL_FOLDER_LOCK(vf, change_lock);
-	for (i = 0; i < ((CamelFolder *)vf)->priv->frozen; i++)
-		camel_folder_thaw(sub);
-	CAMEL_FOLDER_UNLOCK(vf, change_lock);
-
-	CAMEL_VEE_FOLDER_UNLOCK(vf, subfolder_lock);
-
-	if (folder_unmatched != NULL) {
-		struct _CamelVeeFolderPrivate *up = _PRIVATE(folder_unmatched);
-
-		CAMEL_VEE_FOLDER_LOCK(folder_unmatched, subfolder_lock);
-		/* if folder deleted, then blow it away from unmatched always, and remove all refs to it */
-		if (sub->folder_flags & CAMEL_FOLDER_HAS_BEEN_DELETED) {
-			while (g_list_find(up->folders, sub)) {
-				up->folders = g_list_remove(up->folders, sub);
-				camel_object_unref((CamelObject *)sub);
-
-				/* undo the freeze state that Unmatched has imposed on this source folder */
-				CAMEL_FOLDER_LOCK(folder_unmatched, change_lock);
-				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
-					camel_folder_thaw(sub);
-				CAMEL_FOLDER_UNLOCK(folder_unmatched, change_lock);
-			}
-		} else if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
-			if (g_list_find(up->folders, sub) != NULL) {
-				up->folders = g_list_remove(up->folders, sub);
-				camel_object_unref((CamelObject *)sub);
-
-				/* undo the freeze state that Unmatched has imposed on this source folder */
-				CAMEL_FOLDER_LOCK(folder_unmatched, change_lock);
-				for (i = 0; i < ((CamelFolder *)folder_unmatched)->priv->frozen; i++)
-					camel_folder_thaw(sub);
-				CAMEL_FOLDER_UNLOCK(folder_unmatched, change_lock);
-			}
-		}
-		CAMEL_VEE_FOLDER_UNLOCK(folder_unmatched, subfolder_lock);
-	}
-
-	if (CAMEL_IS_VEE_FOLDER(sub))
-		return;
-
-	camel_object_unref((CamelObject *)sub);
+	camel_object_hook_event ((CamelObject *)sub, "folder_changed", (CamelObjectEventHookFunc) folder_changed, vf);
 }
 
 void
@@ -2253,60 +2328,11 @@ camel_vee_folder_sync_headers (CamelFolder *vf, CamelException *ex)
 	time_t start, end;
 
 	/* Save the counts to DB */
-	start = time(NULL);
+	start = time (NULL);
 	record = summary_header_to_db (vf->summary, ex);
 	camel_db_write_folder_info_record (vf->parent_store->cdb_w, record, ex);
-	end = time(NULL);
-	dd(printf("Sync for vfolder '%s': %ld secs\n", vf->full_name, end-start));
+	end = time (NULL);
+	dd (printf ("Sync for vfolder '%s': %ld secs\n", vf->full_name, end-start));
 
 	g_free (record);
 }
-
-static void
-camel_vee_folder_finalise (CamelObject *obj)
-{
-	CamelVeeFolder *vf = (CamelVeeFolder *)obj;
-	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
-	CamelVeeFolder *folder_unmatched = vf->parent_vee_store ? vf->parent_vee_store->folder_unmatched : NULL;
-	GList *node;
-	CamelFIRecord * record;
-
-	p->destroyed = TRUE;
-
-	/* Save the counts to DB */
-	if (!vf->deleted) {
-		CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-		record = summary_header_to_db (((CamelFolder *)vf)->summary, NULL);
-		camel_db_write_folder_info_record (((CamelFolder *) vf)->parent_store->cdb_w, record, &ex);
-		g_free (record);
-		camel_exception_clear (&ex);
-	}
-
-	/* This may invoke sub-classes with partially destroyed state, they must deal with this */
-	if (vf == folder_unmatched) {
-		for (node = p->folders;node;node = g_list_next(node))
-			camel_object_unref(node->data);
-	} else {
-		/* FIXME[disk-summary] See if it is really reqd */
-		camel_folder_freeze ((CamelFolder *)vf);
-		while (p->folders) {
-			CamelFolder *f = p->folders->data;
-			vee_folder_stop_folder(vf, f);
-		}
-		camel_folder_thaw ((CamelFolder *)vf);
-	}
-
-	g_free(vf->expression);
-
-	g_list_free(p->folders);
-	g_list_free(p->folders_changed);
-
-	camel_folder_change_info_free(vf->changes);
-	camel_object_unref((CamelObject *)vf->search);
-
-	g_mutex_free(p->summary_lock);
-	g_mutex_free(p->subfolder_lock);
-	g_mutex_free(p->changed_lock);
-	g_hash_table_destroy (vf->hashes);
-	g_free(p);
-}
diff --git a/camel/camel-vee-folder.h b/camel/camel-vee-folder.h
index 7a38428..84b1054 100644
--- a/camel/camel-vee-folder.h
+++ b/camel/camel-vee-folder.h
@@ -19,26 +19,47 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_VEE_FOLDER_H
-#define _CAMEL_VEE_FOLDER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_VEE_FOLDER_H
+#define CAMEL_VEE_FOLDER_H
 
-#include <glib.h>
 #include <camel/camel-folder.h>
+#include <camel/camel-folder-search.h>
+#include <camel/camel-store.h>
 #include <camel/camel-vee-summary.h>
 
-#define CAMEL_VEE_FOLDER(obj)         CAMEL_CHECK_CAST (obj, camel_vee_folder_get_type (), CamelVeeFolder)
-#define CAMEL_VEE_FOLDER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_vee_folder_get_type (), CamelVeeFolderClass)
-#define CAMEL_IS_VEE_FOLDER(obj)      CAMEL_CHECK_TYPE (obj, camel_vee_folder_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_VEE_FOLDER \
+	(camel_vee_folder_get_type ())
+#define CAMEL_VEE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_VEE_FOLDER, CamelVeeFolder))
+#define CAMEL_VEE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_VEE_FOLDER, CamelVeeFolderClass))
+#define CAMEL_IS_VEE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_VEE_FOLDER))
+#define CAMEL_IS_VEE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_VEE_FOLDER))
+#define CAMEL_VEE_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_VEE_FOLDER, CamelVeeFolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelVeeFolder      CamelVeeFolder;
+typedef struct _CamelVeeFolder CamelVeeFolder;
 typedef struct _CamelVeeFolderClass CamelVeeFolderClass;
+typedef struct _CamelVeeFolderPrivate CamelVeeFolderPrivate;
 
 struct _CamelVeeFolder {
 	CamelFolder parent;
 
-	struct _CamelVeeFolderPrivate *priv;
+	CamelVeeFolderPrivate *priv;
 
 	gchar *expression;	/* query expression */
 
@@ -74,7 +95,7 @@ struct _CamelVeeFolderClass {
 
 #define CAMEL_UNMATCHED_NAME "UNMATCHED"
 
-CamelType	      camel_vee_folder_get_type		(void);
+GType	      camel_vee_folder_get_type		(void);
 CamelFolder  *camel_vee_folder_new		(CamelStore *parent_store, const gchar *full, guint32 flags);
 void         camel_vee_folder_construct		(CamelVeeFolder *vf, CamelStore *parent_store, const gchar *full, const gchar *name, guint32 flags);
 
@@ -94,4 +115,4 @@ void	     camel_vee_folder_sync_headers (CamelFolder *vf, CamelException *ex);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_VEE_FOLDER_H */
+#endif /* CAMEL_VEE_FOLDER_H */
diff --git a/camel/camel-vee-store.c b/camel/camel-vee-store.c
index 5e34075..42b1d9e 100644
--- a/camel/camel-vee-store.c
+++ b/camel/camel-vee-store.c
@@ -24,221 +24,242 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
 #include "camel-db.h"
 #include "camel-exception.h"
 #include "camel-private.h"
+#include "camel-session.h"
 #include "camel-vee-folder.h"
 #include "camel-vee-store.h"
 
 #define d(x)
 
-static CamelFolder *vee_get_folder (CamelStore *store, const gchar *folder_name, guint32 flags, CamelException *ex);
-static void vee_delete_folder(CamelStore *store, const gchar *folder_name, CamelException *ex);
-static void vee_rename_folder(CamelStore *store, const gchar *old, const gchar *new, CamelException *ex);
-
-static CamelFolder *vee_get_trash  (CamelStore *store, CamelException *ex);
-static CamelFolder *vee_get_junk  (CamelStore *store, CamelException *ex);
-
-static CamelFolderInfo *vee_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelException *ex);
-
-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 construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex);
+/* flags
+   1 = delete (0 = add)
+   2 = noselect
+*/
+#define CHANGE_ADD (0)
+#define CHANGE_DELETE (1)
+#define CHANGE_NOSELECT (2)
 
-static CamelStoreClass *camel_vee_store_parent;
+static gpointer parent_class;
 
-CamelType
-camel_vee_store_get_type (void)
+static gint
+vee_folder_cmp (gconstpointer ap,
+                gconstpointer bp)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_store_get_type (), "CamelVeeStore",
-					    sizeof (CamelVeeStore),
-					    sizeof (CamelVeeStoreClass),
-					    (CamelObjectClassInitFunc) camel_vee_store_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_vee_store_init,
-					    (CamelObjectFinalizeFunc) camel_vee_store_finalise);
-	}
-
-	return type;
+	return strcmp (((CamelFolder **)ap)[0]->full_name, ((CamelFolder **)bp)[0]->full_name);
 }
 
 static void
-camel_vee_store_class_init (CamelVeeStoreClass *klass)
+change_folder (CamelStore *store,
+               const gchar *name,
+               guint32 flags,
+               gint count)
 {
-	CamelStoreClass *store_class = (CamelStoreClass *) klass;
-
-	camel_vee_store_parent = (CamelStoreClass *)camel_store_get_type();
-
-	/* virtual method overload */
-	store_class->get_folder = vee_get_folder;
-	store_class->rename_folder = vee_rename_folder;
-	store_class->delete_folder = vee_delete_folder;
-	store_class->get_folder_info = vee_get_folder_info;
-	store_class->free_folder_info = camel_store_free_folder_info_full;
-	((CamelServiceClass *)store_class)->construct = construct;
+	CamelFolderInfo *fi;
+	const gchar *tmp;
+	CamelURL *url;
 
-	store_class->get_trash = vee_get_trash;
-	store_class->get_junk = vee_get_junk;
+	fi = camel_folder_info_new ();
+	fi->full_name = g_strdup (name);
+	tmp = strrchr (name, '/');
+	if (tmp == NULL)
+		tmp = name;
+	else
+		tmp++;
+	fi->name = g_strdup (tmp);
+	url = camel_url_new ("vfolder:", NULL);
+	camel_url_set_path (url, ((CamelService *)store)->url->path);
+	if (flags & CHANGE_NOSELECT)
+		camel_url_set_param (url, "noselect", "yes");
+	camel_url_set_fragment (url, name);
+	fi->uri = camel_url_to_string (url, 0);
+	camel_url_free (url);
+	/*fi->url = g_strdup_printf ("vfolder:%s%s#%s", ((CamelService *)store)->url->path, (flags&CHANGE_NOSELECT)?";noselect=yes":"", name);*/
+	fi->unread = count;
+	fi->flags = CAMEL_FOLDER_VIRTUAL;
+	if (!(flags & CHANGE_DELETE))
+		fi->flags |= CAMEL_FOLDER_NOCHILDREN;
+	camel_object_trigger_event (store, (flags&CHANGE_DELETE)?"folder_deleted":"folder_created", fi);
+	camel_folder_info_free (fi);
 }
 
 static void
-camel_vee_store_init (CamelVeeStore *obj)
+cvs_free_unmatched (gpointer key, gpointer value, gpointer data)
 {
-	CamelStore *store = (CamelStore *)obj;
-
-	/* we dont want a vtrash/vjunk on this one */
-	store->flags &= ~(CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK);
+	g_free (key);
 }
 
 static void
-construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex)
+vee_store_finalize (GObject *object)
 {
-	 CamelStore *store = (CamelStore *)service;
-	 CamelVeeStore *obj = (CamelVeeStore *)service;
+	CamelVeeStore *vee_store = CAMEL_VEE_STORE (object);
 
-	 ((CamelServiceClass *) camel_vee_store_parent)->construct(service, session, provider, url, ex);
+	g_hash_table_foreach (vee_store->unmatched_uids, cvs_free_unmatched, NULL);
+	g_hash_table_destroy (vee_store->unmatched_uids);
+	g_object_unref (vee_store->folder_unmatched);
 
-	/* Set up unmatched folder */
-#ifndef VEE_UNMATCHED_ENABLE
-	obj->unmatched_uids = g_hash_table_new (g_str_hash, g_str_equal);
-	obj->folder_unmatched = (CamelVeeFolder *)camel_object_new (camel_vee_folder_get_type ());
-	camel_vee_folder_construct (obj->folder_unmatched, store, CAMEL_UNMATCHED_NAME, _("Unmatched"), CAMEL_STORE_FOLDER_PRIVATE);
-	camel_db_create_vfolder (store->cdb_r, _("Unmatched"), NULL);
-#endif
-
-}
-static void
-cvs_free_unmatched(gpointer key, gpointer value, gpointer data)
-{
-	g_free(key);
+	/* Chain up to parent's finalize () method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_vee_store_finalise (CamelObject *obj)
-{
-	CamelVeeStore *vstore = (CamelVeeStore *)obj;
-
-	g_hash_table_foreach(vstore->unmatched_uids, cvs_free_unmatched, NULL);
-	g_hash_table_destroy(vstore->unmatched_uids);
-	camel_object_unref(vstore->folder_unmatched);
-}
-
-/**
- * camel_vee_store_new:
- *
- * Create a new #CamelVeeStore object.
- *
- * Returns: new #CamelVeeStore object
- **/
-CamelVeeStore *
-camel_vee_store_new (void)
+vee_store_construct (CamelService *service,
+                     CamelSession *session,
+                     CamelProvider *provider,
+                     CamelURL *url,
+                     CamelException *ex)
 {
-	CamelVeeStore *new = CAMEL_VEE_STORE(camel_object_new(camel_vee_store_get_type ()));
-	return new;
-}
+	CamelServiceClass *service_class;
+	CamelStore *store;
+	CamelVeeStore *vee_store;
 
-/* flags
-   1 = delete (0 = add)
-   2 = noselect
-*/
-#define CHANGE_ADD (0)
-#define CHANGE_DELETE (1)
-#define CHANGE_NOSELECT (2)
+	store = CAMEL_STORE (service);
+	vee_store = CAMEL_VEE_STORE (service);
 
-static void
-change_folder(CamelStore *store, const gchar *name, guint32 flags, gint count)
-{
-	CamelFolderInfo *fi;
-	const gchar *tmp;
-	CamelURL *url;
+	/* Chain up to parent's construct() method. */
+	service_class = CAMEL_SERVICE_CLASS (parent_class);
+	service_class->construct (service, session, provider, url, ex);
 
-	fi = camel_folder_info_new ();
-	fi->full_name = g_strdup(name);
-	tmp = strrchr(name, '/');
-	if (tmp == NULL)
-		tmp = name;
-	else
-		tmp++;
-	fi->name = g_strdup(tmp);
-	url = camel_url_new("vfolder:", NULL);
-	camel_url_set_path(url, ((CamelService *)store)->url->path);
-	if (flags & CHANGE_NOSELECT)
-		camel_url_set_param(url, "noselect", "yes");
-	camel_url_set_fragment(url, name);
-	fi->uri = camel_url_to_string(url, 0);
-	camel_url_free(url);
-	/*fi->url = g_strdup_printf("vfolder:%s%s#%s", ((CamelService *)store)->url->path, (flags&CHANGE_NOSELECT)?";noselect=yes":"", name);*/
-	fi->unread = count;
-	fi->flags = CAMEL_FOLDER_VIRTUAL;
-	if (!(flags & CHANGE_DELETE))
-		fi->flags |= CAMEL_FOLDER_NOCHILDREN;
-	camel_object_trigger_event(store, (flags&CHANGE_DELETE)?"folder_deleted":"folder_created", fi);
-	camel_folder_info_free(fi);
+	/* Set up unmatched folder */
+#ifndef VEE_UNMATCHED_ENABLE
+	vee_store->unmatched_uids = g_hash_table_new (g_str_hash, g_str_equal);
+	vee_store->folder_unmatched = g_object_new (CAMEL_TYPE_VEE_FOLDER, NULL);
+	camel_vee_folder_construct (vee_store->folder_unmatched, store, CAMEL_UNMATCHED_NAME, _("Unmatched"), CAMEL_STORE_FOLDER_PRIVATE);
+	camel_db_create_vfolder (store->cdb_r, _("Unmatched"), NULL);
+#endif
 }
 
 static CamelFolder *
-vee_get_folder (CamelStore *store, const gchar *folder_name, guint32 flags, CamelException *ex)
+vee_store_get_folder (CamelStore *store,
+                      const gchar *folder_name,
+                      guint32 flags,
+                      CamelException *ex)
 {
 	CamelVeeFolder *vf;
 	CamelFolder *folder;
 	gchar *name, *p;
 
-	vf = (CamelVeeFolder *)camel_vee_folder_new(store, folder_name, flags);
+	vf = (CamelVeeFolder *)camel_vee_folder_new (store, folder_name, flags);
 	if (vf && ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0)) {
 		/* Check that parents exist, if not, create dummy ones */
-		name = alloca(strlen(((CamelFolder *)vf)->full_name)+1);
-		strcpy(name, ((CamelFolder *)vf)->full_name);
+		name = alloca (strlen (((CamelFolder *)vf)->full_name)+1);
+		strcpy (name, ((CamelFolder *)vf)->full_name);
 		p = name;
-		while ( (p = strchr(p, '/'))) {
+		while ( (p = strchr (p, '/'))) {
 			*p = 0;
 
-			folder = camel_object_bag_reserve(store->folders, name);
+			folder = camel_object_bag_reserve (store->folders, name);
 			if (folder == NULL) {
 				/* create a dummy vFolder for this, makes get_folder_info simpler */
-				folder = camel_vee_folder_new(store, name, flags);
-				camel_object_bag_add(store->folders, name, folder);
-				change_folder(store, name, CHANGE_ADD|CHANGE_NOSELECT, 0);
+				folder = camel_vee_folder_new (store, name, flags);
+				camel_object_bag_add (store->folders, name, folder);
+				change_folder (store, name, CHANGE_ADD|CHANGE_NOSELECT, 0);
 				/* FIXME: this sort of leaks folder, nobody owns a ref to it but us */
 			} else {
-				camel_object_unref(folder);
+				g_object_unref (folder);
 			}
 			*p++='/';
 		}
 
-		change_folder(store, ((CamelFolder *)vf)->full_name, CHANGE_ADD, camel_folder_get_message_count((CamelFolder *)vf));
+		change_folder (store, ((CamelFolder *)vf)->full_name, CHANGE_ADD, camel_folder_get_message_count ((CamelFolder *)vf));
 	}
 
 	return (CamelFolder *)vf;
 }
 
-static CamelFolder *
-vee_get_trash (CamelStore *store, CamelException *ex)
+static void
+vee_store_rename_folder (CamelStore *store,
+                         const gchar *old,
+                         const gchar *new,
+                         CamelException *ex)
 {
-	return NULL;
-}
+	CamelFolder *folder, *oldfolder;
+	gchar *p, *name;
 
-static CamelFolder *
-vee_get_junk (CamelStore *store, CamelException *ex)
-{
-	return NULL;
+	d (printf ("vee rename folder '%s' '%s'\n", old, new));
+
+	if (strcmp (old, CAMEL_UNMATCHED_NAME) == 0) {
+		camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+				     _("Cannot rename folder: %s: Invalid operation"), old);
+		return;
+	}
+
+	/* See if it exists, for vfolders, all folders are in the folders hash */
+	oldfolder = camel_object_bag_get (store->folders, old);
+	if (oldfolder == NULL) {
+		camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+				     _("Cannot rename folder: %s: No such folder"), old);
+		return;
+	}
+
+	/* Check that new parents exist, if not, create dummy ones */
+	name = alloca (strlen (new)+1);
+	strcpy (name, new);
+	p = name;
+	while ( (p = strchr (p, '/'))) {
+		*p = 0;
+
+		folder = camel_object_bag_reserve (store->folders, name);
+		if (folder == NULL) {
+			/* create a dummy vFolder for this, makes get_folder_info simpler */
+			folder = camel_vee_folder_new (store, name, ((CamelVeeFolder *)oldfolder)->flags);
+			camel_object_bag_add (store->folders, name, folder);
+			change_folder (store, name, CHANGE_ADD|CHANGE_NOSELECT, 0);
+			/* FIXME: this sort of leaks folder, nobody owns a ref to it but us */
+		} else {
+			g_object_unref (folder);
+		}
+		*p++='/';
+	}
+
+	g_object_unref (oldfolder);
 }
 
-static gint
-vee_folder_cmp(gconstpointer ap, gconstpointer bp)
+static void
+vee_store_delete_folder (CamelStore *store,
+                         const gchar *folder_name,
+                         CamelException *ex)
 {
-	return strcmp(((CamelFolder **)ap)[0]->full_name, ((CamelFolder **)bp)[0]->full_name);
+	CamelFolder *folder;
+
+	if (strcmp (folder_name, CAMEL_UNMATCHED_NAME) == 0) {
+		camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+				     _("Cannot delete folder: %s: Invalid operation"), folder_name);
+		return;
+	}
+
+	folder = camel_object_bag_get (store->folders, folder_name);
+	if (folder) {
+		gchar *statefile;
+
+		camel_object_get (folder, NULL, CAMEL_OBJECT_STATE_FILE, &statefile, NULL);
+		if (statefile) {
+			g_unlink (statefile);
+			camel_object_free (folder, CAMEL_OBJECT_STATE_FILE, statefile);
+			camel_object_set (folder, NULL, CAMEL_OBJECT_STATE_FILE, NULL, NULL);
+		}
+
+		if ((((CamelVeeFolder *)folder)->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
+			/* what about now-empty parents?  ignore? */
+			change_folder (store, folder_name, CHANGE_DELETE, -1);
+		}
+
+		g_object_unref (folder);
+	} else {
+		camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+				     _("Cannot delete folder: %s: No such folder"), folder_name);
+	}
 }
 
 static CamelFolderInfo *
-vee_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelException *ex)
+vee_store_get_folder_info (CamelStore *store,
+                           const gchar *top,
+                           guint32 flags,
+                           CamelException *ex)
 {
 	CamelFolderInfo *info, *res = NULL, *tail;
 	GPtrArray *folders;
@@ -246,57 +267,57 @@ vee_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelExc
 	CamelURL *url;
 	gint i;
 
-	d(printf("Get folder info '%s'\n", top?top:"<null>"));
+	d (printf ("Get folder info '%s'\n", top?top:"<null>"));
 
-	infos_hash = g_hash_table_new(g_str_hash, g_str_equal);
-	folders = camel_object_bag_list(store->folders);
-	qsort(folders->pdata, folders->len, sizeof(folders->pdata[0]), vee_folder_cmp);
+	infos_hash = g_hash_table_new (g_str_hash, g_str_equal);
+	folders = camel_object_bag_list (store->folders);
+	qsort (folders->pdata, folders->len, sizeof (folders->pdata[0]), vee_folder_cmp);
 	for (i=0;i<folders->len;i++) {
 		CamelVeeFolder *folder = folders->pdata[i];
 		gint add = FALSE;
 		gchar *name = ((CamelFolder *)folder)->full_name, *pname, *tmp;
 		CamelFolderInfo *pinfo;
 
-		d(printf("folder '%s'\n", name));
+		d (printf ("folder '%s'\n", name));
 
 		/* check we have to include this one */
 		if (top) {
-			gint namelen = strlen(name);
-			gint toplen = strlen(top);
+			gint namelen = strlen (name);
+			gint toplen = strlen (top);
 
 			add = ((namelen == toplen
-				&& strcmp(name, top) == 0)
+				&& strcmp (name, top) == 0)
 			       || ((namelen > toplen)
-				   && strncmp(name, top, toplen) == 0
+				   && strncmp (name, top, toplen) == 0
 				   && name[toplen] == '/'
 				   && ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE)
-				       || strchr(name+toplen+1, '/') == NULL)));
+				       || strchr (name+toplen+1, '/') == NULL)));
 		} else {
 			add = (flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE)
-				|| strchr(name, '/') == NULL;
+				|| strchr (name, '/') == NULL;
 		}
 
-		d(printf("%sadding '%s'\n", add?"":"not ", name));
+		d (printf ("%sadding '%s'\n", add?"":"not ", name));
 
 		if (add) {
 			/* ensures unread is correct */
 			if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
-				camel_folder_refresh_info((CamelFolder *)folder, NULL);
-
-			info = camel_folder_info_new();
-			url = camel_url_new("vfolder:", NULL);
-			camel_url_set_path(url, ((CamelService *)((CamelFolder *)folder)->parent_store)->url->path);
-			camel_url_set_fragment(url, ((CamelFolder *)folder)->full_name);
-			info->uri = camel_url_to_string(url, 0);
-			camel_url_free(url);
+				camel_folder_refresh_info ((CamelFolder *)folder, NULL);
+
+			info = camel_folder_info_new ();
+			url = camel_url_new ("vfolder:", NULL);
+			camel_url_set_path (url, ((CamelService *)((CamelFolder *)folder)->parent_store)->url->path);
+			camel_url_set_fragment (url, ((CamelFolder *)folder)->full_name);
+			info->uri = camel_url_to_string (url, 0);
+			camel_url_free (url);
 /*
-			info->url = g_strdup_printf("vfolder:%s#%s", ((CamelService *)((CamelFolder *)folder)->parent_store)->url->path,
+			info->url = g_strdup_printf ("vfolder:%s#%s", ((CamelService *)((CamelFolder *)folder)->parent_store)->url->path,
 			((CamelFolder *)folder)->full_name);*/
-			info->full_name = g_strdup(((CamelFolder *)folder)->full_name);
-			info->name = g_strdup(((CamelFolder *)folder)->name);
-			info->unread = camel_folder_get_unread_message_count((CamelFolder *)folder);
+			info->full_name = g_strdup (((CamelFolder *)folder)->full_name);
+			info->name = g_strdup (((CamelFolder *)folder)->name);
+			info->unread = camel_folder_get_unread_message_count ((CamelFolder *)folder);
 			info->flags = CAMEL_FOLDER_NOCHILDREN|CAMEL_FOLDER_VIRTUAL;
-			g_hash_table_insert(infos_hash, info->full_name, info);
+			g_hash_table_insert (infos_hash, info->full_name, info);
 
 			if (res == NULL)
 				res = info;
@@ -305,18 +326,18 @@ vee_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelExc
 		}
 
 		/* check for parent, if present, update flags and if adding, update parent linkage */
-		pname = g_strdup(((CamelFolder *)folder)->full_name);
-		d(printf("looking up parent of '%s'\n", pname));
-		tmp = strrchr(pname, '/');
+		pname = g_strdup (((CamelFolder *)folder)->full_name);
+		d (printf ("looking up parent of '%s'\n", pname));
+		tmp = strrchr (pname, '/');
 		if (tmp) {
 			*tmp = 0;
-			pinfo = g_hash_table_lookup(infos_hash, pname);
+			pinfo = g_hash_table_lookup (infos_hash, pname);
 		} else
 			pinfo = NULL;
 
 		if (pinfo) {
 			pinfo->flags = (pinfo->flags & ~(CAMEL_FOLDER_CHILDREN|CAMEL_FOLDER_NOCHILDREN))|CAMEL_FOLDER_CHILDREN;
-			d(printf("updating parent flags for children '%s' %08x\n", pinfo->full_name, pinfo->flags));
+			d (printf ("updating parent flags for children '%s' %08x\n", pinfo->full_name, pinfo->flags));
 			tail = pinfo->child;
 			if (tail == NULL)
 				pinfo->child = info;
@@ -333,24 +354,24 @@ vee_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelExc
 			info->parent = pinfo;
 		}
 
-		g_free(pname);
-		camel_object_unref(folder);
+		g_free (pname);
+		g_object_unref (folder);
 	}
-	g_ptr_array_free(folders, TRUE);
-	g_hash_table_destroy(infos_hash);
+	g_ptr_array_free (folders, TRUE);
+	g_hash_table_destroy (infos_hash);
 
 	/* and always add UNMATCHED, if scanning from top/etc */
 	/* FIXME[disk-summary] comment it out well */
-	if ((top == NULL || top[0] == 0 || strncmp(top, CAMEL_UNMATCHED_NAME, strlen(CAMEL_UNMATCHED_NAME)) == 0)) {
+	if ((top == NULL || top[0] == 0 || strncmp (top, CAMEL_UNMATCHED_NAME, strlen (CAMEL_UNMATCHED_NAME)) == 0)) {
 		info = camel_folder_info_new ();
-		url = camel_url_new("vfolder:", NULL);
-		camel_url_set_path(url, ((CamelService *)store)->url->path);
-		camel_url_set_fragment(url, CAMEL_UNMATCHED_NAME);
-		info->uri = camel_url_to_string(url, 0);
-		camel_url_free(url);
-		/*info->url = g_strdup_printf("vfolder:%s#%s", ((CamelService *)store)->url->path, CAMEL_UNMATCHED_NAME);*/
-		info->full_name = g_strdup(CAMEL_UNMATCHED_NAME);
-		info->name = g_strdup(_("Unmatched"));
+		url = camel_url_new ("vfolder:", NULL);
+		camel_url_set_path (url, ((CamelService *)store)->url->path);
+		camel_url_set_fragment (url, CAMEL_UNMATCHED_NAME);
+		info->uri = camel_url_to_string (url, 0);
+		camel_url_free (url);
+		/*info->url = g_strdup_printf ("vfolder:%s#%s", ((CamelService *)store)->url->path, CAMEL_UNMATCHED_NAME);*/
+		info->full_name = g_strdup (CAMEL_UNMATCHED_NAME);
+		info->name = g_strdup (_("Unmatched"));
 		info->unread = -1;
 		info->flags = CAMEL_FOLDER_NOCHILDREN|CAMEL_FOLDER_NOINFERIORS|CAMEL_FOLDER_SYSTEM|CAMEL_FOLDER_VIRTUAL;
 
@@ -367,81 +388,81 @@ vee_get_folder_info(CamelStore *store, const gchar *top, guint32 flags, CamelExc
 	return res;
 }
 
-static void
-vee_delete_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
+static CamelFolder *
+vee_store_get_trash (CamelStore *store,
+                     CamelException *ex)
 {
-	CamelFolder *folder;
+	return NULL;
+}
 
-	if (strcmp(folder_name, CAMEL_UNMATCHED_NAME) == 0) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
-				     _("Cannot delete folder: %s: Invalid operation"), folder_name);
-		return;
-	}
+static CamelFolder *
+vee_store_get_junk (CamelStore *store,
+                    CamelException *ex)
+{
+	return NULL;
+}
 
-	folder = camel_object_bag_get(store->folders, folder_name);
-	if (folder) {
-		gchar *statefile;
+static void
+vee_store_class_init (CamelVeeStoreClass *class)
+{
+	GObjectClass *object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
 
-		camel_object_get(folder, NULL, CAMEL_OBJECT_STATE_FILE, &statefile, NULL);
-		if (statefile) {
-			g_unlink(statefile);
-			camel_object_free(folder, CAMEL_OBJECT_STATE_FILE, statefile);
-			camel_object_set(folder, NULL, CAMEL_OBJECT_STATE_FILE, NULL, NULL);
-		}
+	parent_class = g_type_class_peek_parent (class);
 
-		if ((((CamelVeeFolder *)folder)->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
-			/* what about now-empty parents?  ignore? */
-			change_folder(store, folder_name, CHANGE_DELETE, -1);
-		}
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = vee_store_finalize;
 
-		camel_object_unref(folder);
-	} else {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
-				     _("Cannot delete folder: %s: No such folder"), folder_name);
-	}
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = vee_store_construct;
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_folder = vee_store_get_folder;
+	store_class->rename_folder = vee_store_rename_folder;
+	store_class->delete_folder = vee_store_delete_folder;
+	store_class->get_folder_info = vee_store_get_folder_info;
+	store_class->free_folder_info = camel_store_free_folder_info_full;
+	store_class->get_trash = vee_store_get_trash;
+	store_class->get_junk = vee_store_get_junk;
 }
 
 static void
-vee_rename_folder(CamelStore *store, const gchar *old, const gchar *new, CamelException *ex)
+vee_store_init (CamelVeeStore *vee_store)
 {
-	CamelFolder *folder, *oldfolder;
-	gchar *p, *name;
+	CamelStore *store = CAMEL_STORE (vee_store);
 
-	d(printf("vee rename folder '%s' '%s'\n", old, new));
-
-	if (strcmp(old, CAMEL_UNMATCHED_NAME) == 0) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
-				     _("Cannot rename folder: %s: Invalid operation"), old);
-		return;
-	}
-
-	/* See if it exists, for vfolders, all folders are in the folders hash */
-	oldfolder = camel_object_bag_get(store->folders, old);
-	if (oldfolder == NULL) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
-				     _("Cannot rename folder: %s: No such folder"), old);
-		return;
-	}
+	/* we dont want a vtrash/vjunk on this one */
+	store->flags &= ~(CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK);
+}
 
-	/* Check that new parents exist, if not, create dummy ones */
-	name = alloca(strlen(new)+1);
-	strcpy(name, new);
-	p = name;
-	while ( (p = strchr(p, '/'))) {
-		*p = 0;
+GType
+camel_vee_store_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE,
+			"CamelVeeStore",
+			sizeof (CamelVeeStoreClass),
+			(GClassInitFunc) vee_store_class_init,
+			sizeof (CamelVeeStore),
+			(GInstanceInitFunc) vee_store_init,
+			0);
 
-		folder = camel_object_bag_reserve(store->folders, name);
-		if (folder == NULL) {
-			/* create a dummy vFolder for this, makes get_folder_info simpler */
-			folder = camel_vee_folder_new(store, name, ((CamelVeeFolder *)oldfolder)->flags);
-			camel_object_bag_add(store->folders, name, folder);
-			change_folder(store, name, CHANGE_ADD|CHANGE_NOSELECT, 0);
-			/* FIXME: this sort of leaks folder, nobody owns a ref to it but us */
-		} else {
-			camel_object_unref(folder);
-		}
-		*p++='/';
-	}
+	return type;
+}
 
-	camel_object_unref(oldfolder);
+/**
+ * camel_vee_store_new:
+ *
+ * Create a new #CamelVeeStore object.
+ *
+ * Returns: new #CamelVeeStore object
+ **/
+CamelVeeStore *
+camel_vee_store_new (void)
+{
+	return g_object_new (CAMEL_TYPE_VEE_STORE, NULL);
 }
diff --git a/camel/camel-vee-store.h b/camel/camel-vee-store.h
index ecbd2a0..27576d5 100644
--- a/camel/camel-vee-store.h
+++ b/camel/camel-vee-store.h
@@ -19,19 +19,37 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_VEE_STORE_H
-#define _CAMEL_VEE_STORE_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_VEE_STORE_H
+#define CAMEL_VEE_STORE_H
 
-#include <glib.h>
 #include <camel/camel-store.h>
 
-#define CAMEL_VEE_STORE(obj)         CAMEL_CHECK_CAST (obj, camel_vee_store_get_type (), CamelVeeStore)
-#define CAMEL_VEE_STORE_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_vee_store_get_type (), CamelVeeStoreClass)
-#define CAMEL_IS_VEE_STORE(obj)      CAMEL_CHECK_TYPE (obj, camel_vee_store_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_VEE_STORE \
+	(camel_vee_store_get_type ())
+#define CAMEL_VEE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_VEE_STORE, CamelVeeStore))
+#define CAMEL_VEE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_VEE_STORE, CamelVeeStoreClass))
+#define CAMEL_IS_VEE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_VEE_STORE))
+#define CAMEL_IS_VEE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_VEE_STORE))
+#define CAMEL_VEE_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_VEE_STORE, CamelVeeStoreClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelVeeStore      CamelVeeStore;
+typedef struct _CamelVeeStore CamelVeeStore;
 typedef struct _CamelVeeStoreClass CamelVeeStoreClass;
 
 /* open mode for folder, vee folder auto-update */
@@ -50,9 +68,9 @@ struct _CamelVeeStoreClass {
 	CamelStoreClass parent_class;
 };
 
-CamelType		camel_vee_store_get_type	(void);
+GType		camel_vee_store_get_type	(void);
 CamelVeeStore      *camel_vee_store_new	(void);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_VEE_STORE_H */
+#endif /* CAMEL_VEE_STORE_H */
diff --git a/camel/camel-vee-summary.c b/camel/camel-vee-summary.c
index cf6c509..141d974 100644
--- a/camel/camel-vee-summary.c
+++ b/camel/camel-vee-summary.c
@@ -41,7 +41,8 @@
 
 #define d(x)
 
-static CamelFolderSummaryClass *camel_vee_summary_parent;
+static gpointer parent_class;
+
 static const gchar *unread_str = " (and\n  \n     (match-all (not (system-flag  \"Seen\")))\n    \n  )\n;  (or\n  \n     (match-all (not (system-flag  \"Seen\")))\n    \n  )\n; (match-threads \"all\"  (and\n  \n     (match-all (not (system-flag  \"Seen\")))\n    \n  )\n)\n;  (match-threads \"all\"  (or\n  \n     (match-all (not (system-flag  \"Seen\")))\n    \n  )\n)\n;";
 
 static void
@@ -50,7 +51,7 @@ vee_message_info_free(CamelFolderSummary *s, CamelMessageInfo *info)
 	CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *)info;
 
 	camel_pstring_free(info->uid);
-	camel_object_unref (mi->summary);
+	g_object_unref (mi->summary);
 }
 
 static CamelMessageInfo *
@@ -62,7 +63,7 @@ vee_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
 	to = (CamelVeeMessageInfo *)camel_message_info_new(s);
 
 	to->summary = from->summary;
-	camel_object_ref (to->summary);
+	g_object_ref (to->summary);
 	to->info.summary = s;
 	to->info.uid = camel_pstring_strdup(from->info.uid);
 
@@ -375,63 +376,56 @@ message_info_from_uid (CamelFolderSummary *s, const gchar *uid)
 		strncpy(tmphash, uid, 8);
 		tmphash[8] = 0;
 		vinfo->summary = g_hash_table_lookup(((CamelVeeFolder *) s->folder)->hashes, tmphash);
-		camel_object_ref (vinfo->summary);
+		g_object_ref (vinfo->summary);
 		camel_folder_summary_insert (s, info, FALSE);
 	}
 	return info;
 }
 
 static void
-camel_vee_summary_class_init (CamelVeeSummaryClass *klass)
+vee_summary_class_init (CamelVeeSummaryClass *class)
 {
-	((CamelFolderSummaryClass *)klass)->message_info_clone = vee_message_info_clone;
-	((CamelFolderSummaryClass *)klass)->message_info_free = vee_message_info_free;
-
-	((CamelFolderSummaryClass *)klass)->info_ptr = vee_info_ptr;
-	((CamelFolderSummaryClass *)klass)->info_uint32 = vee_info_uint32;
-	((CamelFolderSummaryClass *)klass)->info_time = vee_info_time;
-	((CamelFolderSummaryClass *)klass)->info_user_flag = vee_info_user_flag;
-	((CamelFolderSummaryClass *)klass)->info_user_tag = vee_info_user_tag;
-
-#if 0
-	((CamelFolderSummaryClass *)klass)->info_set_string = vee_info_set_string;
-	((CamelFolderSummaryClass *)klass)->info_set_uint32 = vee_info_set_uint32;
-	((CamelFolderSummaryClass *)klass)->info_set_time = vee_info_set_time;
-	((CamelFolderSummaryClass *)klass)->info_set_references = vee_info_set_references;
-#endif
-	((CamelFolderSummaryClass *)klass)->info_set_user_flag = vee_info_set_user_flag;
-	((CamelFolderSummaryClass *)klass)->info_set_user_tag = vee_info_set_user_tag;
-
-	((CamelFolderSummaryClass *)klass)->info_set_flags = vee_info_set_flags;
-	((CamelFolderSummaryClass *)klass)->message_info_from_uid = message_info_from_uid;
+	CamelFolderSummaryClass *folder_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->message_info_clone = vee_message_info_clone;
+	folder_summary_class->message_info_free = vee_message_info_free;
+	folder_summary_class->info_ptr = vee_info_ptr;
+	folder_summary_class->info_uint32 = vee_info_uint32;
+	folder_summary_class->info_time = vee_info_time;
+	folder_summary_class->info_user_flag = vee_info_user_flag;
+	folder_summary_class->info_user_tag = vee_info_user_tag;
+	folder_summary_class->info_set_user_flag = vee_info_set_user_flag;
+	folder_summary_class->info_set_user_tag = vee_info_set_user_tag;
+	folder_summary_class->info_set_flags = vee_info_set_flags;
+	folder_summary_class->message_info_from_uid = message_info_from_uid;
 }
 
 static void
-camel_vee_summary_init (CamelVeeSummary *obj)
+vee_summary_init (CamelVeeSummary *vee_summary)
 {
-	CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (vee_summary);
 
-	s->message_info_size = sizeof(CamelVeeMessageInfo);
-	s->content_info_size = 0;
+	summary->message_info_size = sizeof (CamelVeeMessageInfo);
+	summary->content_info_size = 0;
 }
 
-CamelType
+GType
 camel_vee_summary_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		camel_vee_summary_parent = (CamelFolderSummaryClass *)camel_folder_summary_get_type();
+	static GType type = G_TYPE_INVALID;
 
-		type = camel_type_register(
-			camel_folder_summary_get_type(), "CamelVeeSummary",
-			sizeof (CamelVeeSummary),
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER_SUMMARY,
+			"CamelVeeSummary",
 			sizeof (CamelVeeSummaryClass),
-			(CamelObjectClassInitFunc) camel_vee_summary_class_init,
-			NULL,
-			(CamelObjectInitFunc) camel_vee_summary_init,
-			NULL);
-	}
+			(GClassInitFunc) vee_summary_class_init,
+			sizeof (CamelVeeSummary),
+			(GInstanceInitFunc) vee_summary_init,
+			0);
 
 	return type;
 }
@@ -450,7 +444,7 @@ camel_vee_summary_new(CamelFolder *parent)
 {
 	CamelVeeSummary *s;
 
-	s = (CamelVeeSummary *)camel_object_new(camel_vee_summary_get_type());
+	s = g_object_new (CAMEL_TYPE_VEE_SUMMARY, NULL);
 	s->summary.folder = parent;
 	s->force_counts = FALSE;
 	s->fake_visible_count = 0;
@@ -500,7 +494,7 @@ camel_vee_summary_add(CamelVeeSummary *s, CamelFolderSummary *summary, const gch
 		g_free (vuid);
 		if (!mi->summary) {
 			mi->summary = summary;
-			camel_object_ref(summary);
+			g_object_ref (summary);
 		}
 
 		return mi;
@@ -511,7 +505,7 @@ camel_vee_summary_add(CamelVeeSummary *s, CamelFolderSummary *summary, const gch
 	fcache = camel_folder_summary_get_flag_cache(summary);
 	mi->old_flags = GPOINTER_TO_UINT(g_hash_table_lookup (fcache, uid));
 	/* We would do lazy loading of flags, when the folders are loaded to memory through folder_reloaded signal */
-	camel_object_ref (summary);
+	g_object_ref (summary);
 	mi->info.uid = (gchar *) camel_pstring_strdup (vuid);
 	g_free (vuid);
 	camel_message_info_ref (mi);
diff --git a/camel/camel-vee-summary.h b/camel/camel-vee-summary.h
index 4718727..d84cf29 100644
--- a/camel/camel-vee-summary.h
+++ b/camel/camel-vee-summary.h
@@ -20,15 +20,34 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_VEE_SUMMARY_H
-#define _CAMEL_VEE_SUMMARY_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_VEE_SUMMARY_H
+#define CAMEL_VEE_SUMMARY_H
 
 #include <camel/camel-folder-summary.h>
 #include <camel/camel-exception.h>
 
-#define CAMEL_VEE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_vee_summary_get_type (), CamelVeeSummary)
-#define CAMEL_VEE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_vee_summary_get_type (), CamelVeeSummaryClass)
-#define CAMEL_IS_VEE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_vee_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_VEE_SUMMARY \
+	(camel_vee_summary_get_type ())
+#define CAMEL_VEE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_VEE_SUMMARY, CamelVeeSummary))
+#define CAMEL_VEE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_VEE_SUMMARY, CamelVeeSummaryClass))
+#define CAMEL_IS_VEE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_VEE_SUMMARY))
+#define CAMEL_IS_VEE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_VEE_SUMMARY))
+#define CAMEL_VEE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_VEE_SUMMARY, CamelVeeSummaryClass))
 
 G_BEGIN_DECLS
 
@@ -57,7 +76,7 @@ struct _CamelVeeSummaryClass {
 
 };
 
-CamelType               camel_vee_summary_get_type     (void);
+GType               camel_vee_summary_get_type     (void);
 CamelFolderSummary *camel_vee_summary_new(struct _CamelFolder *parent);
 
 CamelVeeMessageInfo * camel_vee_summary_add(CamelVeeSummary *s, CamelFolderSummary *summary, const gchar *uid, const gchar hash[8]);
@@ -66,5 +85,5 @@ void camel_vee_summary_load_check_unread_vfolder  (CamelVeeSummary *vs);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_VEE_SUMMARY_H */
+#endif /* CAMEL_VEE_SUMMARY_H */
 
diff --git a/camel/camel-vtrash-folder.c b/camel/camel-vtrash-folder.c
index 2383e03..d45cbed 100644
--- a/camel/camel-vtrash-folder.c
+++ b/camel/camel-vtrash-folder.c
@@ -27,7 +27,6 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-db.h"
@@ -40,7 +39,7 @@
 #include "camel-string-utils.h"
 
 /* Returns the class for a CamelFolder */
-#define CF_CLASS(so) ((CamelFolderClass *)((CamelObject *)(so))->klass)
+#define CF_CLASS(so) ((CamelFolderClass *)((CamelObject *)(so))->class)
 
 static struct {
 	const gchar *full_name;
@@ -57,67 +56,35 @@ static struct {
 	  N_("Cannot copy messages to the Junk folder"), "junk" },
 };
 
-static CamelVeeFolderClass *camel_vtrash_folder_parent;
+struct _transfer_data {
+	CamelFolder *folder;
+	CamelFolder *dest;
+	GPtrArray *uids;
+	gboolean delete;
+};
 
-static void camel_vtrash_folder_class_init (CamelVTrashFolderClass *klass);
+static gpointer parent_class;
 
 static void
-camel_vtrash_folder_init (CamelVTrashFolder *vtrash)
-{
-	/*CamelFolder *folder = CAMEL_FOLDER (vtrash);*/
-}
-
-CamelType
-camel_vtrash_folder_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_vee_folder_get_type (),
-					    "CamelVTrashFolder",
-					    sizeof (CamelVTrashFolder),
-					    sizeof (CamelVTrashFolderClass),
-					    (CamelObjectClassInitFunc) camel_vtrash_folder_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_vtrash_folder_init,
-					    NULL);
-	}
-
-	return type;
-}
-
-/**
- * camel_vtrash_folder_new:
- * @parent_store: the parent #CamelVeeStore object
- * @type: type of vfolder, #CAMEL_VTRASH_FOLDER_TRASH or
- * #CAMEL_VTRASH_FOLDER_JUNK currently.
- *
- * Create a new CamelVTrashFolder object.
- *
- * Returns: a new #CamelVTrashFolder object
- **/
-CamelFolder *
-camel_vtrash_folder_new (CamelStore *parent_store, camel_vtrash_folder_t type)
+transfer_messages(CamelFolder *folder, struct _transfer_data *md, CamelException *ex)
 {
-	CamelVTrashFolder *vtrash;
-
-	g_assert(type < CAMEL_VTRASH_FOLDER_LAST);
-
-	vtrash = (CamelVTrashFolder *)camel_object_new(camel_vtrash_folder_get_type());
-	camel_vee_folder_construct(CAMEL_VEE_FOLDER (vtrash), parent_store, vdata[type].full_name, _(vdata[type].name),
-				   CAMEL_STORE_FOLDER_PRIVATE|CAMEL_STORE_FOLDER_CREATE|CAMEL_STORE_VEE_FOLDER_AUTO|CAMEL_STORE_VEE_FOLDER_SPECIAL);
+	gint i;
 
-	((CamelFolder *)vtrash)->folder_flags |= vdata[type].flags;
-	camel_vee_folder_set_expression((CamelVeeFolder *)vtrash, vdata[type].expr);
-	vtrash->bit = vdata[type].bit;
-	vtrash->type = type;
+	if (!camel_exception_is_set (ex))
+		camel_folder_transfer_messages_to(md->folder, md->uids, md->dest, NULL, md->delete, ex);
 
-	return (CamelFolder *)vtrash;
+	for (i=0;i<md->uids->len;i++)
+		g_free(md->uids->pdata[i]);
+	g_ptr_array_free(md->uids, TRUE);
+	g_object_unref (md->folder);
+	g_free(md);
 }
 
 /* This entire code will be useless, since we sync the counts always. */
 static gint
-vtrash_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
+vtrash_folder_getv (CamelObject *object,
+                    CamelException *ex,
+                    CamelArgGetV *args)
 {
 	CamelFolder *folder = (CamelFolder *)object;
 	gint i;
@@ -200,44 +167,28 @@ vtrash_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 		arg->tag = (tag & CAMEL_ARG_TYPE) | CAMEL_ARG_IGNORE;
 	}
 
-	return ((CamelObjectClass *)camel_vtrash_folder_parent)->getv(object, ex, args);
-}
-
-static void
-vtrash_append_message (CamelFolder *folder, CamelMimeMessage *message,
-		       const CamelMessageInfo *info, gchar **appended_uid,
-		       CamelException *ex)
-{
-	camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s",
-			     _(vdata[((CamelVTrashFolder *)folder)->type].error_copy));
+	return CAMEL_OBJECT_CLASS (parent_class)->getv (object, ex, args);
 }
 
-struct _transfer_data {
-	CamelFolder *folder;
-	CamelFolder *dest;
-	GPtrArray *uids;
-	gboolean delete;
-};
-
 static void
-transfer_messages(CamelFolder *folder, struct _transfer_data *md, CamelException *ex)
+vtrash_folder_append_message (CamelFolder *folder,
+                              CamelMimeMessage *message,
+                              const CamelMessageInfo *info,
+                              gchar **appended_uid,
+                              CamelException *ex)
 {
-	gint i;
-
-	if (!camel_exception_is_set (ex))
-		camel_folder_transfer_messages_to(md->folder, md->uids, md->dest, NULL, md->delete, ex);
-
-	for (i=0;i<md->uids->len;i++)
-		g_free(md->uids->pdata[i]);
-	g_ptr_array_free(md->uids, TRUE);
-	camel_object_unref((CamelObject *)md->folder);
-	g_free(md);
+	camel_exception_setv (
+		ex, CAMEL_EXCEPTION_SYSTEM, "%s",
+		_(vdata[((CamelVTrashFolder *)folder)->type].error_copy));
 }
 
 static void
-vtrash_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
-			     CamelFolder *dest, GPtrArray **transferred_uids,
-			     gboolean delete_originals, CamelException *ex)
+vtrash_folder_transfer_messages_to (CamelFolder *source,
+                                    GPtrArray *uids,
+                                    CamelFolder *dest,
+                                    GPtrArray **transferred_uids,
+                                    gboolean delete_originals,
+                                    CamelException *ex)
 {
 	CamelVeeMessageInfo *mi;
 	gint i;
@@ -291,7 +242,7 @@ vtrash_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 			if (md == NULL) {
 				md = g_malloc0(sizeof(*md));
 				md->folder = mi->summary->folder;
-				camel_object_ref((CamelObject *)md->folder);
+				g_object_ref (md->folder);
 				md->uids = g_ptr_array_new();
 				md->dest = dest;
 				g_hash_table_insert(batch, mi->summary->folder, md);
@@ -312,15 +263,65 @@ vtrash_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 }
 
 static void
-camel_vtrash_folder_class_init (CamelVTrashFolderClass *klass)
+vtrash_folder_class_init (CamelVTrashFolderClass *class)
 {
-	CamelFolderClass *folder_class = (CamelFolderClass *) klass;
+	CamelObjectClass *camel_object_class;
+	CamelFolderClass *folder_class;
 
-	camel_vtrash_folder_parent = CAMEL_VEE_FOLDER_CLASS(camel_vee_folder_get_type());
+	parent_class = g_type_class_peek_parent (class);
 
 	/* Not required from here on. We don't count */
-	((CamelObjectClass *)klass)->getv = vtrash_getv;
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = vtrash_folder_getv;
 
-	folder_class->append_message = vtrash_append_message;
-	folder_class->transfer_messages_to = vtrash_transfer_messages_to;
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->append_message = vtrash_folder_append_message;
+	folder_class->transfer_messages_to = vtrash_folder_transfer_messages_to;
+}
+
+GType
+camel_vtrash_folder_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_VEE_FOLDER,
+			"CamelVTrashFolder",
+			sizeof (CamelVTrashFolderClass),
+			(GClassInitFunc) vtrash_folder_class_init,
+			sizeof (CamelVTrashFolder),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
+}
+
+/**
+ * camel_vtrash_folder_new:
+ * @parent_store: the parent #CamelVeeStore object
+ * @type: type of vfolder, #CAMEL_VTRASH_FOLDER_TRASH or
+ * #CAMEL_VTRASH_FOLDER_JUNK currently.
+ *
+ * Create a new CamelVTrashFolder object.
+ *
+ * Returns: a new #CamelVTrashFolder object
+ **/
+CamelFolder *
+camel_vtrash_folder_new (CamelStore *parent_store, camel_vtrash_folder_t type)
+{
+	CamelVTrashFolder *vtrash;
+
+	g_assert(type < CAMEL_VTRASH_FOLDER_LAST);
+
+	vtrash = g_object_new (CAMEL_TYPE_VTRASH_FOLDER, NULL);
+	camel_vee_folder_construct(CAMEL_VEE_FOLDER (vtrash), parent_store, vdata[type].full_name, _(vdata[type].name),
+				   CAMEL_STORE_FOLDER_PRIVATE|CAMEL_STORE_FOLDER_CREATE|CAMEL_STORE_VEE_FOLDER_AUTO|CAMEL_STORE_VEE_FOLDER_SPECIAL);
+
+	((CamelFolder *)vtrash)->folder_flags |= vdata[type].flags;
+	camel_vee_folder_set_expression((CamelVeeFolder *)vtrash, vdata[type].expr);
+	vtrash->bit = vdata[type].bit;
+	vtrash->type = type;
+
+	return (CamelFolder *)vtrash;
 }
diff --git a/camel/camel-vtrash-folder.h b/camel/camel-vtrash-folder.h
index 815327d..dcaef62 100644
--- a/camel/camel-vtrash-folder.h
+++ b/camel/camel-vtrash-folder.h
@@ -20,24 +20,43 @@
  *
  */
 
-#ifndef _CAMEL_VTRASH_FOLDER_H
-#define _CAMEL_VTRASH_FOLDER_H
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_VTRASH_FOLDER_H
+#define CAMEL_VTRASH_FOLDER_H
 
 #include <camel/camel-folder.h>
 #include <camel/camel-vee-folder.h>
 
-#define CAMEL_VTRASH_FOLDER(obj)         CAMEL_CHECK_CAST (obj, camel_vtrash_folder_get_type (), CamelVTrashFolder)
-#define CAMEL_VTRASH_FOLDER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_vtrash_folder_get_type (), CamelVTrashFolderClass)
-#define CAMEL_IS_VTRASH_FOLDER(obj)      CAMEL_CHECK_TYPE (obj, camel_vtrash_folder_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_VTRASH_FOLDER \
+	(camel_vtrash_folder_get_type ())
+#define CAMEL_VTRASH_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_VTRASH_FOLDER, CamelVTrashFolder))
+#define CAMEL_VTRASH_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_VTRASH_FOLDER, CamelVTrashFolderClass))
+#define CAMEL_IS_VTRASH_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_VTRASH_FOLDER))
+#define CAMEL_IS_VTRASH_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_VTRASH_FOLDER))
+#define CAMEL_VTRASH_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_VTRASH_FOLDER, CamelVTrashFolderClass))
+
+#define CAMEL_VTRASH_NAME	".#evolution/Trash"
+#define CAMEL_VJUNK_NAME	".#evolution/Junk"
 
 G_BEGIN_DECLS
 
-typedef struct _CamelVTrashFolder      CamelVTrashFolder;
+typedef struct _CamelVTrashFolder CamelVTrashFolder;
 typedef struct _CamelVTrashFolderClass CamelVTrashFolderClass;
 
-#define CAMEL_VTRASH_NAME ".#evolution/Trash"
-#define CAMEL_VJUNK_NAME ".#evolution/Junk"
-
 typedef enum {
 	CAMEL_VTRASH_FOLDER_TRASH,
 	CAMEL_VTRASH_FOLDER_JUNK,
@@ -56,10 +75,10 @@ struct _CamelVTrashFolderClass {
 
 };
 
-CamelType       camel_vtrash_folder_get_type    (void);
+GType       camel_vtrash_folder_get_type    (void);
 
 CamelFolder    *camel_vtrash_folder_new		(CamelStore *parent_store, camel_vtrash_folder_t type);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_VTRASH_FOLDER_H */
+#endif /* CAMEL_VTRASH_FOLDER_H */
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 0986d80..7687f1d 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_TYPE_OBJECT;
 
 #ifdef HAVE_NSS
 	if (nss_init) {
@@ -138,7 +137,7 @@ camel_init (const gchar *configdir, gboolean nss_init)
 	/* set this certdb as the default db */
 	camel_certdb_set_default (certdb);
 
-	camel_object_unref (certdb);
+	g_object_unref (certdb);
 
 	initialised = TRUE;
 
diff --git a/camel/camel.h b/camel/camel.h
index 776b274..6247ead 100644
--- a/camel/camel.h
+++ b/camel/camel.h
@@ -22,7 +22,9 @@
  */
 
 #ifndef CAMEL_H
-#define CAMEL_H 1
+#define CAMEL_H
+
+#define __CAMEL_H_INSIDE__
 
 #include <camel/camel-address.h>
 #include <camel/camel-arg.h>
@@ -32,6 +34,8 @@
 #include <camel/camel-cipher-context.h>
 #include <camel/camel-data-cache.h>
 #include <camel/camel-data-wrapper.h>
+#include <camel/camel-db.h>
+#include <camel/camel-debug.h>
 #include <camel/camel-digest-folder.h>
 #include <camel/camel-digest-store.h>
 #include <camel/camel-digest-summary.h>
@@ -71,8 +75,10 @@
 #include <camel/camel-mime-filter-index.h>
 #include <camel/camel-mime-filter-linewrap.h>
 #include <camel/camel-mime-filter-pgp.h>
+#include <camel/camel-mime-filter-progress.h>
 #include <camel/camel-mime-filter-save.h>
 #include <camel/camel-mime-filter-tohtml.h>
+#include <camel/camel-mime-filter-windows.h>
 #include <camel/camel-mime-filter-yenc.h>
 #include <camel/camel-mime-message.h>
 #include <camel/camel-mime-parser.h>
@@ -88,6 +94,7 @@
 #include <camel/camel-news-address.h>
 #include <camel/camel-nntp-address.h>
 #include <camel/camel-object.h>
+#include <camel/camel-object-bag.h>
 #include <camel/camel-offline-folder.h>
 #include <camel/camel-offline-journal.h>
 #include <camel/camel-offline-store.h>
@@ -126,7 +133,6 @@
 #include <camel/camel-text-index.h>
 #include <camel/camel-transport.h>
 #include <camel/camel-trie.h>
-#include <camel/camel-types.h>
 #include <camel/camel-uid-cache.h>
 #include <camel/camel-url.h>
 #include <camel/camel-url-scanner.h>
@@ -136,7 +142,7 @@
 #include <camel/camel-vee-summary.h>
 #include <camel/camel-vtrash-folder.h>
 
-#include <glib.h>
+#undef __CAMEL_H_INSIDE__
 
 G_BEGIN_DECLS
 
diff --git a/camel/providers/groupwise/camel-groupwise-folder.c b/camel/providers/groupwise/camel-groupwise-folder.c
index 4f340c7..b1177ce 100644
--- a/camel/providers/groupwise/camel-groupwise-folder.c
+++ b/camel/providers/groupwise/camel-groupwise-folder.c
@@ -42,18 +42,12 @@ which needs to be better organized via functions */
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include <e-gw-connection.h>
 #include <e-gw-item.h>
 
-#include "camel-folder-search.h"
-#include "camel-folder.h"
 #include "camel-private.h"
-#include "camel-session.h"
-#include "camel-stream-mem.h"
-#include "camel-string-utils.h"
 
 #include "camel-groupwise-folder.h"
 #include "camel-groupwise-journal.h"
@@ -71,7 +65,11 @@ which needs to be better organized via functions */
 #define MAX_ATTACHMENT_SIZE 1*1024*1024   /*In bytes*/
 #define GROUPWISE_BULK_DELETE_LIMIT 100
 
-static CamelOfflineFolderClass *parent_class = NULL;
+#define CAMEL_GROUPWISE_FOLDER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_GROUPWISE_FOLDER, CamelGroupwiseFolderPrivate))
+
+static gpointer parent_class;
 
 struct _CamelGroupwiseFolderPrivate {
 
@@ -146,21 +144,21 @@ groupwise_folder_get_message( CamelFolder *folder, const gchar *uid, CamelExcept
 		if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) msg, stream) == -1) {
 			if (errno == EINTR) {
 				camel_exception_setv (ex, CAMEL_EXCEPTION_USER_CANCEL, _("User canceled"));
-				camel_object_unref (msg);
-				camel_object_unref (cache_stream);
-				camel_object_unref (stream);
+				g_object_unref (msg);
+				g_object_unref (cache_stream);
+				g_object_unref (stream);
 				camel_message_info_free (&mi->info);
 				return NULL;
 			} else {
 				camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get message %s: %s"),
 						uid, g_strerror (errno));
-				camel_object_unref (msg);
+				g_object_unref (msg);
 				msg = NULL;
 			}
 		}
-		camel_object_unref (cache_stream);
+		g_object_unref (cache_stream);
 	}
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	if (msg != NULL) {
 		camel_message_info_free (&mi->info);
@@ -217,7 +215,7 @@ groupwise_folder_get_message( CamelFolder *folder, const gchar *uid, CamelExcept
 		if (camel_data_wrapper_write_to_stream ((CamelDataWrapper *) msg, cache_stream) == -1
 				|| camel_stream_flush (cache_stream) == -1)
 			camel_data_cache_remove (gw_folder->cache, "cache", uid, NULL);
-		camel_object_unref (cache_stream);
+		g_object_unref (cache_stream);
 	}
 
 	CAMEL_GROUPWISE_FOLDER_REC_UNLOCK (folder, cache_lock);
@@ -333,7 +331,7 @@ groupwise_populate_msg_body_from_item (EGwConnection *cnc, CamelMultipart *multi
 
 	camel_multipart_set_boundary (multipart, NULL);
 	camel_multipart_add_part (multipart, part);
-	camel_object_unref (part);
+	g_object_unref (part);
 }
 
 /* Set the recipients list in the message from the item */
@@ -461,8 +459,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);
@@ -664,6 +661,7 @@ groupwise_sync_summary (CamelFolder *folder, CamelException *ex)
 	camel_store_summary_save ((CamelStoreSummary *)((CamelGroupwiseStore *)folder->parent_store)->summary);
 }
 
+/* This may need to be reorganized. */
 static void
 sync_flags (CamelFolder *folder, GList *uids)
 {
@@ -920,7 +918,7 @@ camel_gw_folder_new(CamelStore *store, const gchar *folder_name, const gchar *fo
 	gchar *summary_file, *state_file, *journal_file;
 	gchar *short_name;
 
-	folder = CAMEL_FOLDER (camel_object_new(camel_groupwise_folder_get_type ()) );
+	folder = g_object_new (CAMEL_TYPE_GROUPWISE_FOLDER, NULL);
 
 	gw_folder = CAMEL_GROUPWISE_FOLDER(folder);
 	short_name = strrchr (folder_name, '/');
@@ -934,7 +932,7 @@ camel_gw_folder_new(CamelStore *store, const gchar *folder_name, const gchar *fo
 	folder->summary = camel_groupwise_summary_new(folder, summary_file);
 	g_free(summary_file);
 	if (!folder->summary) {
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				_("Could not load summary for %s"),
 				folder_name);
@@ -947,9 +945,9 @@ camel_gw_folder_new(CamelStore *store, const gchar *folder_name, const gchar *fo
 	g_free(state_file);
 	camel_object_state_read(folder);
 
-	gw_folder->cache = camel_data_cache_new (folder_dir,0 ,ex);
+	gw_folder->cache = camel_data_cache_new (folder_dir, ex);
 	if (!gw_folder->cache) {
-		camel_object_unref (folder);
+		g_object_unref (folder);
 		return NULL;
 	}
 
@@ -957,7 +955,7 @@ camel_gw_folder_new(CamelStore *store, const gchar *folder_name, const gchar *fo
 	gw_folder->journal = camel_groupwise_journal_new (gw_folder, journal_file);
 	g_free (journal_file);
 	if (!gw_folder->journal) {
-		camel_object_unref (folder);
+		g_object_unref (folder);
 		return NULL;
 	}
 
@@ -968,7 +966,7 @@ camel_gw_folder_new(CamelStore *store, const gchar *folder_name, const gchar *fo
 
 	gw_folder->search = camel_folder_search_new ();
 	if (!gw_folder->search) {
-		camel_object_unref (folder);
+		g_object_unref (folder);
 		return NULL;
 	}
 
@@ -988,7 +986,6 @@ struct _folder_update_msg {
 static void
 update_update (CamelSession *session, CamelSessionThreadMsg *msg)
 {
-
 	struct _folder_update_msg *m = (struct _folder_update_msg *)msg;
 	EGwConnectionStatus status;
 	CamelException *ex = NULL;
@@ -1099,7 +1096,7 @@ update_free (CamelSession *session, CamelSessionThreadMsg *msg)
 
 	g_free (m->t_str);
 	g_free (m->container_id);
-	camel_object_unref (m->folder);
+	g_object_unref (m->folder);
 	camel_folder_thaw (m->folder);
 	g_slist_foreach (m->slist, (GFunc) g_free, NULL);
 	g_slist_free (m->slist);
@@ -1398,7 +1395,7 @@ groupwise_refresh_folder(CamelFolder *folder, CamelException *ex)
 		msg->t_str = g_strdup (old_sync_time);
 		msg->container_id = g_strdup (container_id);
 		msg->folder = folder;
-		camel_object_ref (folder);
+		g_object_ref (folder);
 		camel_folder_freeze (folder);
 		camel_session_thread_queue (session, &msg->msg, 0);
 		/*thread creation and queueing done*/
@@ -1687,7 +1684,7 @@ gw_update_cache (CamelFolder *folder, GList *list, CamelException *ex, gboolean
 				/* add to cache if its a new message*/
 				t_cache_stream  = camel_data_cache_get (gw_folder->cache, "cache", id, ex);
 				if (t_cache_stream) {
-						camel_object_unref (t_cache_stream);
+						g_object_unref (t_cache_stream);
 
 						mail_msg = groupwise_folder_item_to_msg (folder, item, ex);
 						if (mail_msg)
@@ -1697,10 +1694,10 @@ gw_update_cache (CamelFolder *folder, GList *list, CamelException *ex, gboolean
 						if ((cache_stream = camel_data_cache_add (gw_folder->cache, "cache", id, NULL))) {
 								if (camel_data_wrapper_write_to_stream ((CamelDataWrapper *) mail_msg,	cache_stream) == -1 || camel_stream_flush (cache_stream) == -1)
 										camel_data_cache_remove (gw_folder->cache, "cache", id, NULL);
-								camel_object_unref (cache_stream);
+								g_object_unref (cache_stream);
 						}
 
-						camel_object_unref (mail_msg);
+						g_object_unref (mail_msg);
 						CAMEL_GROUPWISE_FOLDER_REC_UNLOCK (folder, cache_lock);
 				}
 				/******************** Caching stuff ends *************************/
@@ -2032,8 +2029,8 @@ groupwise_folder_item_to_msg( CamelFolder *folder,
 	if (has_mime_822 && body) {
 		temp_stream = camel_stream_mem_new_with_buffer (body, body_len);
 		if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) msg, temp_stream) == -1) {
-			camel_object_unref (msg);
-			camel_object_unref (temp_stream);
+			g_object_unref (msg);
+			g_object_unref (temp_stream);
 			msg = NULL;
 			goto end;
 		}
@@ -2130,11 +2127,11 @@ groupwise_folder_item_to_msg( CamelFolder *folder,
 					part = camel_mime_part_new ();
 					camel_data_wrapper_set_mime_type_field(CAMEL_DATA_WRAPPER (temp_msg), ct);
 					camel_content_type_unref(ct);
-					camel_medium_set_content_object ( CAMEL_MEDIUM (part),CAMEL_DATA_WRAPPER(temp_msg));
+					camel_medium_set_content (CAMEL_MEDIUM (part),CAMEL_DATA_WRAPPER(temp_msg));
 
 					camel_multipart_add_part (multipart,part);
-					camel_object_unref (temp_msg);
-					camel_object_unref (part);
+					g_object_unref (temp_msg);
+					g_object_unref (part);
 				}
 				g_object_unref (temp_item);
 			} else {
@@ -2215,7 +2212,7 @@ groupwise_folder_item_to_msg( CamelFolder *folder,
 					camel_multipart_set_boundary(multipart, NULL);
 					camel_multipart_add_part (multipart, part);
 
-					camel_object_unref (part);
+					g_object_unref (part);
 					g_free (attachment);
 				} /* if attachment */
 			}
@@ -2231,8 +2228,8 @@ groupwise_folder_item_to_msg( CamelFolder *folder,
 	if (e_gw_item_get_security (item))
 		camel_medium_add_header ( CAMEL_MEDIUM (msg), "Security", e_gw_item_get_security(item));
 
-	camel_medium_set_content_object(CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER(multipart));
-	camel_object_unref (multipart);
+	camel_medium_set_content (CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER(multipart));
+	g_object_unref (multipart);
 
 end:
 	if (body)
@@ -2452,7 +2449,7 @@ groupwise_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 				break;
 
 			camel_groupwise_journal_transfer (journal, (CamelGroupwiseFolder *)source, message, info, uids->pdata[i], NULL, ex);
-			camel_object_unref (message);
+			g_object_unref (message);
 
 			if (camel_exception_is_set (ex))
 				break;
@@ -2707,42 +2704,68 @@ groupwise_cmp_uids (CamelFolder *folder, const gchar *uid1, const gchar *uid2)
 }
 
 static void
-camel_groupwise_folder_class_init (CamelGroupwiseFolderClass *camel_groupwise_folder_class)
+groupwise_folder_dispose (GObject *object)
 {
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_groupwise_folder_class);
-
-	parent_class = CAMEL_OFFLINE_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_offline_folder_get_type ()));
-
-	((CamelObjectClass *) camel_groupwise_folder_class)->getv = gw_getv;
-
-	camel_folder_class->get_message = groupwise_folder_get_message;
-	camel_folder_class->rename = groupwise_folder_rename;
-	camel_folder_class->search_by_expression = groupwise_folder_search_by_expression;
-	camel_folder_class->count_by_expression = groupwise_folder_count_by_expression;
-	camel_folder_class->cmp_uids = groupwise_cmp_uids;
-	camel_folder_class->search_by_uids = groupwise_folder_search_by_uids;
-	camel_folder_class->search_free = groupwise_folder_search_free;
-	camel_folder_class->append_message = groupwise_append_message;
-	camel_folder_class->refresh_info = groupwise_refresh_info;
-	camel_folder_class->sync = groupwise_sync;
-	camel_folder_class->expunge = groupwise_expunge;
-	camel_folder_class->transfer_messages_to = groupwise_transfer_messages_to;
-	camel_folder_class->get_filename = groupwise_get_filename;
+	CamelGroupwiseFolder *gw_folder = CAMEL_GROUPWISE_FOLDER (object);
+
+	if (gw_folder->cache != NULL) {
+		g_object_unref (gw_folder->cache);
+		gw_folder->cache = NULL;
+	}
+
+	if (gw_folder->search != NULL) {
+		g_object_unref (gw_folder->search);
+		gw_folder->search = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_groupwise_folder_init (gpointer object, gpointer klass)
+groupwise_folder_class_init (CamelGroupwiseFolderClass *class)
 {
-	CamelGroupwiseFolder *gw_folder = CAMEL_GROUPWISE_FOLDER (object);
-	CamelFolder *folder = CAMEL_FOLDER (object);
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+	CamelFolderClass *folder_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelGroupwiseFolderPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = groupwise_folder_dispose;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = gw_getv;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->get_message = groupwise_folder_get_message;
+	folder_class->rename = groupwise_folder_rename;
+	folder_class->search_by_expression = groupwise_folder_search_by_expression;
+	folder_class->count_by_expression = groupwise_folder_count_by_expression;
+	folder_class->cmp_uids = groupwise_cmp_uids;
+	folder_class->search_by_uids = groupwise_folder_search_by_uids;
+	folder_class->search_free = groupwise_folder_search_free;
+	folder_class->append_message = groupwise_append_message;
+	folder_class->refresh_info = groupwise_refresh_info;
+	folder_class->sync = groupwise_sync;
+	folder_class->expunge = groupwise_expunge;
+	folder_class->transfer_messages_to = groupwise_transfer_messages_to;
+	folder_class->get_filename = groupwise_get_filename;
+}
+
+static void
+groupwise_folder_init (CamelGroupwiseFolder *gw_folder)
+{
+	CamelFolder *folder = CAMEL_FOLDER (gw_folder);
+
+	gw_folder->priv = CAMEL_GROUPWISE_FOLDER_GET_PRIVATE (gw_folder);
 
 	folder->permanent_flags = CAMEL_MESSAGE_ANSWERED | CAMEL_MESSAGE_DELETED |
 		CAMEL_MESSAGE_DRAFT | CAMEL_MESSAGE_FLAGGED | CAMEL_MESSAGE_SEEN;
 
 	folder->folder_flags = CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
 
-	gw_folder->priv = g_malloc0 (sizeof(*gw_folder->priv));
-
 #ifdef ENABLE_THREADS
 	g_static_mutex_init(&gw_folder->priv->search_lock);
 	g_static_rec_mutex_init(&gw_folder->priv->cache_lock);
@@ -2751,38 +2774,22 @@ camel_groupwise_folder_init (gpointer object, gpointer klass)
 	gw_folder->need_rescan = TRUE;
 }
 
-static void
-camel_groupwise_folder_finalize (CamelObject *object)
-{
-	CamelGroupwiseFolder *gw_folder = CAMEL_GROUPWISE_FOLDER (object);
-
-	if (gw_folder->priv)
-		g_free(gw_folder->priv);
-	if (gw_folder->cache)
-		camel_object_unref (gw_folder->cache);
-	if (gw_folder->search)
-		camel_object_unref (gw_folder->search);
-
-}
-
-CamelType
+GType
 camel_groupwise_folder_get_type (void)
 {
-	static CamelType camel_groupwise_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_groupwise_folder_type == CAMEL_INVALID_TYPE) {
-		camel_groupwise_folder_type =
-			camel_type_register (camel_offline_folder_get_type (),
-					"CamelGroupwiseFolder",
-					sizeof (CamelGroupwiseFolder),
-					sizeof (CamelGroupwiseFolderClass),
-					(CamelObjectClassInitFunc) camel_groupwise_folder_class_init,
-					NULL,
-					(CamelObjectInitFunc) camel_groupwise_folder_init,
-					(CamelObjectFinalizeFunc) camel_groupwise_folder_finalize);
-	}
-
-	return camel_groupwise_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OFFLINE_FOLDER,
+			"CamelGroupwiseFolder",
+			sizeof (CamelGroupwiseFolderClass),
+			(GClassInitFunc) groupwise_folder_class_init,
+			sizeof (CamelGroupwiseFolder),
+			(GInstanceInitFunc) groupwise_folder_init,
+			0);
+
+	return type;
 }
 
 static gint
diff --git a/camel/providers/groupwise/camel-groupwise-folder.h b/camel/providers/groupwise/camel-groupwise-folder.h
index 7aa37ad..937818e 100644
--- a/camel/providers/groupwise/camel-groupwise-folder.h
+++ b/camel/providers/groupwise/camel-groupwise-folder.h
@@ -25,33 +25,40 @@
  */
 
 #ifndef CAMEL_GROUPWISE_FOLDER_H
-#define CAMEL_GROUPWISE_FOLDER_H 1
-
-#include <camel/camel-offline-folder.h>
-#include <camel/camel-mime-message.h>
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-internet-address.h>
-#include <camel/camel-data-cache.h>
-#include <camel/camel-multipart.h>
-#include <camel/camel-multipart-signed.h>
-#include <camel/camel-multipart-encrypted.h>
-#include <camel/camel-offline-journal.h>
+#define CAMEL_GROUPWISE_FOLDER_H
+
+#include <camel/camel.h>
 
 #include "camel-groupwise-summary.h"
 
-#define CAMEL_GROUPWISE_FOLDER_TYPE     (camel_groupwise_folder_get_type ())
-#define CAMEL_GROUPWISE_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_GROUPWISE_FOLDER_TYPE, CamelGroupwiseFolder))
-#define CAMEL_GROUPWISE_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_GROUPWISE_FOLDER_TYPE, CamelGroupwiseFolderClass))
-#define CAMEL_IS_GROUPWISE_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_GROUPWISE_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_GROUPWISE_FOLDER \
+	(camel_groupwise_folder_get_type ())
+#define CAMEL_GROUPWISE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_GROUPWISE_FOLDER, CamelGroupwiseFolder))
+#define CAMEL_GROUPWISE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_GROUPWISE_FOLDER, CamelGroupwiseFolderClass))
+#define CAMEL_IS_GROUPWISE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_GROUPWISE_FOLDER))
+#define CAMEL_IS_GROUPWISE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_GROUPWISE_FOLDER))
+#define CAMEL_GROUPWISE_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_GROUPWISE_FOLDER, CamelGroupwiseFolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct  _CamelGroupwiseFolder CamelGroupwiseFolder;
-typedef struct  _CamelGroupwiseFolderClass CamelGroupwiseFolderClass;
-struct _CamelGroupwiseFolder {
-	CamelOfflineFolder parent_object;
+typedef struct _CamelGroupwiseFolder CamelGroupwiseFolder;
+typedef struct _CamelGroupwiseFolderClass CamelGroupwiseFolderClass;
+typedef struct _CamelGroupwiseFolderPrivate CamelGroupwiseFolderPrivate;
 
-	struct _CamelGroupwiseFolderPrivate *priv;
+struct _CamelGroupwiseFolder {
+	CamelOfflineFolder parent;
+	CamelGroupwiseFolderPrivate *priv;
 
 	CamelFolderSearch *search;
 
@@ -71,8 +78,7 @@ struct _CamelGroupwiseFolderClass {
 
 } ;
 
-/* Standard Camel function */
-CamelType camel_groupwise_folder_get_type (void);
+GType camel_groupwise_folder_get_type (void);
 
 /* implemented */
 CamelFolder * camel_gw_folder_new(CamelStore *store, const gchar *folder_dir, const gchar *folder_name, CamelException *ex);
diff --git a/camel/providers/groupwise/camel-groupwise-journal.c b/camel/providers/groupwise/camel-groupwise-journal.c
index 1068b34..cab0760 100644
--- a/camel/providers/groupwise/camel-groupwise-journal.c
+++ b/camel/providers/groupwise/camel-groupwise-journal.c
@@ -33,74 +33,51 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
-#include "camel-data-cache.h"
-#include "camel-file-utils.h"
-#include "camel-folder-summary.h"
-#include "camel-folder.h"
-#include "camel-string-utils.h"
-
 #include "camel-groupwise-folder.h"
 #include "camel-groupwise-journal.h"
 #include "camel-groupwise-store.h"
 
 #define d(x)
 
-static void camel_groupwise_journal_class_init (CamelGroupwiseJournalClass *klass);
-static void camel_groupwise_journal_init (CamelGroupwiseJournal *journal, CamelGroupwiseJournalClass *klass);
-static void camel_groupwise_journal_finalize (CamelObject *object);
-
 static void groupwise_entry_free (CamelOfflineJournal *journal, CamelDListNode *entry);
 static CamelDListNode *groupwise_entry_load (CamelOfflineJournal *journal, FILE *in);
 static gint groupwise_entry_write (CamelOfflineJournal *journal, CamelDListNode *entry, FILE *out);
 static gint groupwise_entry_play (CamelOfflineJournal *journal, CamelDListNode *entry, CamelException *ex);
 
-static CamelOfflineJournalClass *parent_class = NULL;
-
-CamelType
-camel_groupwise_journal_get_type (void)
-{
-	static CamelType type = NULL;
-
-	if (!type) {
-		type = camel_type_register (camel_offline_journal_get_type (),
-					    "CamelGroupwiseJournal",
-					    sizeof (CamelGroupwiseJournal),
-					    sizeof (CamelGroupwiseJournalClass),
-					    (CamelObjectClassInitFunc) camel_groupwise_journal_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_groupwise_journal_init,
-					    (CamelObjectFinalizeFunc) camel_groupwise_journal_finalize);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static void
-camel_groupwise_journal_class_init (CamelGroupwiseJournalClass *klass)
+groupwise_journal_class_init (CamelGroupwiseJournalClass *class)
 {
-	CamelOfflineJournalClass *journal_class = (CamelOfflineJournalClass *) klass;
+	CamelOfflineJournalClass *offline_journal_class;
 
-	parent_class = (CamelOfflineJournalClass *) camel_type_get_global_classfuncs (CAMEL_TYPE_OFFLINE_JOURNAL);
+	parent_class = g_type_class_peek_parent (class);
 
-	journal_class->entry_free = groupwise_entry_free;
-	journal_class->entry_load = groupwise_entry_load;
-	journal_class->entry_write = groupwise_entry_write;
-	journal_class->entry_play = groupwise_entry_play;
+	offline_journal_class = CAMEL_OFFLINE_JOURNAL_CLASS (class);
+	offline_journal_class->entry_free = groupwise_entry_free;
+	offline_journal_class->entry_load = groupwise_entry_load;
+	offline_journal_class->entry_write = groupwise_entry_write;
+	offline_journal_class->entry_play = groupwise_entry_play;
 }
 
-static void
-camel_groupwise_journal_init (CamelGroupwiseJournal *journal, CamelGroupwiseJournalClass *klass)
-{
-
-}
-
-static void
-camel_groupwise_journal_finalize (CamelObject *object)
+GType
+camel_groupwise_journal_get_type (void)
 {
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OFFLINE_JOURNAL,
+			"CamelGroupwiseJournal",
+			sizeof (CamelGroupwiseJournalClass),
+			(GClassInitFunc) groupwise_journal_class_init,
+			sizeof (CamelGroupwiseJournal),
+			(GInstanceInitFunc) NULL,
+			0);
 
+	return type;
 }
 
 static void
@@ -209,12 +186,12 @@ groupwise_entry_play_append (CamelOfflineJournal *journal, CamelGroupwiseJournal
 
 	message = camel_mime_message_new ();
 	if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream) == -1) {
-		camel_object_unref (message);
-		camel_object_unref (stream);
+		g_object_unref (message);
+		g_object_unref (stream);
 		goto done;
 	}
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	if (!(info = camel_folder_summary_uid (folder->summary, entry->uid))) {
 		/* Note: this should never happen, but rather than crash lets make a new info */
@@ -224,7 +201,7 @@ groupwise_entry_play_append (CamelOfflineJournal *journal, CamelGroupwiseJournal
 	camel_exception_init (&lex);
 	camel_folder_append_message (folder, message, info, NULL, &lex);
 	camel_message_info_free (info);
-	camel_object_unref (message);
+	g_object_unref (message);
 
 	if (camel_exception_is_set (&lex)) {
 		camel_exception_xfer (ex, &lex);
@@ -276,7 +253,7 @@ groupwise_entry_play_transfer (CamelOfflineJournal *journal, CamelGroupwiseJourn
 
 		g_ptr_array_free (xuids, TRUE);
 		g_ptr_array_free (uids, TRUE);
-		camel_object_unref (src);
+		g_object_unref (src);
 	} else if (!name) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get folder container %s"),
 				      entry->source_container);
@@ -320,7 +297,7 @@ camel_groupwise_journal_new (CamelGroupwiseFolder *folder, const gchar *filename
 
 	g_return_val_if_fail (CAMEL_IS_GROUPWISE_FOLDER (folder), NULL);
 
-	journal = (CamelOfflineJournal *) camel_object_new (camel_groupwise_journal_get_type ());
+	journal = g_object_new (CAMEL_TYPE_OFFLINE_JOURNAL, NULL);
 	camel_offline_journal_construct (journal, (CamelFolder *) folder, filename);
 
 	return journal;
@@ -360,12 +337,12 @@ update_cache (CamelGroupwiseJournal *groupwise_journal, CamelMimeMessage *messag
 				      g_strerror (errno));
 		camel_data_cache_remove (groupwise_folder->cache, "cache", uid, NULL);
 		folder->summary->nextuid--;
-		camel_object_unref (cache);
+		g_object_unref (cache);
 		g_free (uid);
 		return FALSE;
 	}
 
-	camel_object_unref (cache);
+	g_object_unref (cache);
 
 	info = camel_folder_summary_info_new_from_message (folder->summary, message, NULL);
 	camel_pstring_free(info->uid);
diff --git a/camel/providers/groupwise/camel-groupwise-journal.h b/camel/providers/groupwise/camel-groupwise-journal.h
index a1901b2..d6246ea 100644
--- a/camel/providers/groupwise/camel-groupwise-journal.h
+++ b/camel/providers/groupwise/camel-groupwise-journal.h
@@ -20,22 +20,30 @@
  *
  */
 
-#ifndef __CAMEL_GROUPWISE_JOURNAL_H__
-#define __CAMEL_GROUPWISE_JOURNAL_H__
+#ifndef CAMEL_GROUPWISE_JOURNAL_H
+#define CAMEL_GROUPWISE_JOURNAL_H
 
 #include <stdarg.h>
-
-#include <glib.h>
-
-#include <camel/camel-offline-journal.h>
-#include <camel/camel-mime-message.h>
-
-#define CAMEL_TYPE_GROUPWISE_JOURNAL            (camel_groupwise_journal_get_type ())
-#define CAMEL_GROUPWISE_JOURNAL(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournal))
-#define CAMEL_GROUPWISE_JOURNAL_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournalClass))
-#define CAMEL_IS_GROUPWISE_JOURNAL(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_GROUPWISE_JOURNAL))
-#define CAMEL_IS_GROUPWISE_JOURNAL_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_GROUPWISE_JOURNAL))
-#define CAMEL_GROUPWISE_JOURNAL_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournalClass))
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_GROUPWISE_JOURNAL \
+	(camel_groupwise_journal_get_type ())
+#define CAMEL_GROUPWISE_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournal))
+#define CAMEL_GROUPWISE_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournalClass))
+#define CAMEL_IS_GROUPWISE_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_GROUPWISE_JOURNAL))
+#define CAMEL_IS_GROUPWISE_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_GROUPWISE_JOURNAL))
+#define CAMEL_GROUPWISE_JOURNAL_GET_CLASS(obj) \
+	(CAMEL_CHECK_GET_CLASS \
+	((obj), CAMEL_TYPE_GROUPWISE_JOURNAL, CamelGroupwiseJournalClass))
 
 G_BEGIN_DECLS
 
@@ -61,7 +69,7 @@ struct _CamelGroupwiseJournalEntry {
 };
 
 struct _CamelGroupwiseJournal {
-	CamelOfflineJournal parent_object;
+	CamelOfflineJournal parent;
 
 };
 
@@ -70,7 +78,7 @@ struct _CamelGroupwiseJournalClass {
 
 };
 
-CamelType camel_groupwise_journal_get_type (void);
+GType camel_groupwise_journal_get_type (void);
 
 CamelOfflineJournal *camel_groupwise_journal_new (struct _CamelGroupwiseFolder *folder, const gchar *filename);
 
@@ -82,4 +90,4 @@ void camel_groupwise_journal_transfer (CamelGroupwiseJournal *journal, CamelGrou
 
 G_END_DECLS
 
-#endif /* __CAMEL_GROUPWISE_JOURNAL_H__ */
+#endif /* CAMEL_GROUPWISE_JOURNAL_H */
diff --git a/camel/providers/groupwise/camel-groupwise-private.h b/camel/providers/groupwise/camel-groupwise-private.h
index 3cfcf66..580a0a3 100644
--- a/camel/providers/groupwise/camel-groupwise-private.h
+++ b/camel/providers/groupwise/camel-groupwise-private.h
@@ -20,7 +20,7 @@
  */
 
 #ifndef CAMEL_GROUPWISE_PRIVATE_H
-#define CAMEL_GROUPWISE_PRIVATE_H 1
+#define CAMEL_GROUPWISE_PRIVATE_H
 
 /* need a way to configure and save this data, if this header is to
    be installed.  For now, dont install it */
diff --git a/camel/providers/groupwise/camel-groupwise-provider.c b/camel/providers/groupwise/camel-groupwise-provider.c
index 69b898e..41b5dfa 100644
--- a/camel/providers/groupwise/camel-groupwise-provider.c
+++ b/camel/providers/groupwise/camel-groupwise-provider.c
@@ -30,15 +30,9 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <gmodule.h>
 
-#include "camel-provider.h"
-#include "camel-sasl.h"
-#include "camel-session.h"
-#include "camel-url.h"
-
 #include "camel-groupwise-store.h"
 #include "camel-groupwise-transport.h"
 
@@ -141,8 +135,8 @@ camel_provider_module_init(void)
 	if (use_imap)
 		groupwise_provider.object_types[CAMEL_PROVIDER_STORE] = imap_provider->object_types [CAMEL_PROVIDER_STORE];
 	else	{
-		groupwise_provider.object_types[CAMEL_PROVIDER_STORE] =  camel_groupwise_store_get_type();
-		groupwise_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_groupwise_transport_get_type();
+		groupwise_provider.object_types[CAMEL_PROVIDER_STORE] =  camel_groupwise_store_get_type ();
+		groupwise_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_groupwise_transport_get_type ();
 	}
 
 	camel_provider_register (&groupwise_provider);
diff --git a/camel/providers/groupwise/camel-groupwise-store-summary.c b/camel/providers/groupwise/camel-groupwise-store-summary.c
index 8b833bf..f027ff7 100644
--- a/camel/providers/groupwise/camel-groupwise-store-summary.c
+++ b/camel/providers/groupwise/camel-groupwise-store-summary.c
@@ -31,9 +31,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "camel-file-utils.h"
 #include "camel-private.h"
-#include "camel-utf8.h"
 
 #include "camel-groupwise-store-summary.h"
 
@@ -54,57 +52,48 @@ static void store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint
 static const gchar *store_info_string(CamelStoreSummary *s, const CamelStoreInfo *mi, gint type);
 CamelGroupwiseStoreNamespace *camel_groupwise_store_summary_namespace_find_full(CamelGroupwiseStoreSummary *s, const gchar *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 CamelStoreSummaryClass *camel_groupwise_store_summary_parent;
+static gpointer parent_class;
 
 static void
-camel_groupwise_store_summary_class_init (CamelGroupwiseStoreSummaryClass *klass)
+groupwise_store_summary_class_init (CamelGroupwiseStoreSummaryClass *class)
 {
-	CamelStoreSummaryClass *ssklass = (CamelStoreSummaryClass *)klass;
-
-	ssklass->summary_header_load = summary_header_load;
-	ssklass->summary_header_save = summary_header_save;
-
-	ssklass->store_info_load = store_info_load;
-	ssklass->store_info_save = store_info_save;
-	ssklass->store_info_free = store_info_free;
-
-	ssklass->store_info_string = store_info_string;
-	ssklass->store_info_set_string = store_info_set_string;
-
+	CamelStoreSummaryClass *store_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (class);
+	store_summary_class->summary_header_load = summary_header_load;
+	store_summary_class->summary_header_save = summary_header_save;
+	store_summary_class->store_info_load = store_info_load;
+	store_summary_class->store_info_save = store_info_save;
+	store_summary_class->store_info_free = store_info_free;
+	store_summary_class->store_info_string = store_info_string;
+	store_summary_class->store_info_set_string = store_info_set_string;
 }
 
 static void
-camel_groupwise_store_summary_init (CamelGroupwiseStoreSummary *s)
+groupwise_store_summary_init (CamelGroupwiseStoreSummary *gw_summary)
 {
+	CamelStoreSummary *summary = CAMEL_STORE_SUMMARY (gw_summary);
 
-	((CamelStoreSummary *)s)->store_info_size = sizeof(CamelGroupwiseStoreInfo);
-	s->version = CAMEL_GW_STORE_SUMMARY_VERSION;
+	summary->store_info_size = sizeof (CamelGroupwiseStoreInfo);
+	gw_summary->version = CAMEL_GW_STORE_SUMMARY_VERSION;
 }
 
-static void
-camel_groupwise_store_summary_finalise (CamelObject *obj)
-{
-}
-
-CamelType
+GType
 camel_groupwise_store_summary_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		camel_groupwise_store_summary_parent = (CamelStoreSummaryClass *)camel_store_summary_get_type();
-		type = camel_type_register((CamelType)camel_groupwise_store_summary_parent, "CamelGroupwiseStoreSummary",
-				sizeof (CamelGroupwiseStoreSummary),
-				sizeof (CamelGroupwiseStoreSummaryClass),
-				(CamelObjectClassInitFunc) camel_groupwise_store_summary_class_init,
-				NULL,
-				(CamelObjectInitFunc) camel_groupwise_store_summary_init,
-				(CamelObjectFinalizeFunc) camel_groupwise_store_summary_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE_SUMMARY,
+			"CamelGroupwiseStoreSummary",
+			sizeof (CamelGroupwiseStoreSummaryClass),
+			(GClassInitFunc) groupwise_store_summary_class_init,
+			sizeof (CamelGroupwiseStoreSummary),
+			(GInstanceInitFunc) groupwise_store_summary_init,
+			0);
 
 	return type;
 }
@@ -112,9 +101,7 @@ camel_groupwise_store_summary_get_type (void)
 CamelGroupwiseStoreSummary *
 camel_groupwise_store_summary_new (void)
 {
-	CamelGroupwiseStoreSummary *new = CAMEL_GW_STORE_SUMMARY ( camel_object_new (camel_groupwise_store_summary_get_type ()));
-
-	return new;
+	return g_object_new (CAMEL_TYPE_GROUPWISE_STORE_SUMMARY, NULL);
 }
 
 CamelGroupwiseStoreInfo *
@@ -458,7 +445,7 @@ summary_header_load(CamelStoreSummary *s, FILE *in)
 
 	namespace_clear (s);
 
-	if (camel_groupwise_store_summary_parent->summary_header_load ((CamelStoreSummary *)s, in) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->summary_header_load ((CamelStoreSummary *)s, in) == -1
 			|| camel_file_util_decode_fixed_int32(in, &version) == -1)
 		return -1;
 
@@ -484,7 +471,7 @@ summary_header_save(CamelStoreSummary *s, FILE *out)
 	guint32 count;
 
 	count = summary->namespace?1:0;
-	if (camel_groupwise_store_summary_parent->summary_header_save((CamelStoreSummary *)s, out) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->summary_header_save((CamelStoreSummary *)s, out) == -1
 			|| camel_file_util_encode_fixed_int32(out, 0) == -1
 			|| camel_file_util_encode_fixed_int32(out, summary->capabilities) == -1
 			|| camel_file_util_encode_fixed_int32(out, count) == -1)
@@ -501,7 +488,7 @@ store_info_load(CamelStoreSummary *s, FILE *in)
 {
 	CamelGroupwiseStoreInfo *si;
 
-	si = (CamelGroupwiseStoreInfo *)camel_groupwise_store_summary_parent->store_info_load(s, in);
+	si = (CamelGroupwiseStoreInfo *)CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_load(s, in);
 	if (si) {
 		if (camel_file_util_decode_string(in, &si->full_name) == -1) {
 			camel_store_summary_info_free(s, (CamelStoreInfo *)si);
@@ -517,7 +504,7 @@ store_info_save(CamelStoreSummary *s, FILE *out, CamelStoreInfo *mi)
 {
 	CamelGroupwiseStoreInfo *summary = (CamelGroupwiseStoreInfo *)mi;
 
-	if (camel_groupwise_store_summary_parent->store_info_save(s, out, mi) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_save(s, out, mi) == -1
 			|| camel_file_util_encode_string(out, summary->full_name) == -1)
 		return -1;
 
@@ -530,7 +517,7 @@ store_info_free(CamelStoreSummary *s, CamelStoreInfo *mi)
 	CamelGroupwiseStoreInfo *si = (CamelGroupwiseStoreInfo *)mi;
 
 	g_free(si->full_name);
-	camel_groupwise_store_summary_parent->store_info_free(s, mi);
+	CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_free(s, mi);
 }
 
 static const gchar *
@@ -546,7 +533,7 @@ store_info_string(CamelStoreSummary *s, const CamelStoreInfo *mi, gint type)
 		case CAMEL_STORE_INFO_LAST:
 			return isi->full_name;
 		default:
-			return camel_groupwise_store_summary_parent->store_info_string(s, mi, type);
+			return CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_string(s, mi, type);
 	}
 }
 
@@ -566,7 +553,7 @@ store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const
 			CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
 			break;
 		default:
-			camel_groupwise_store_summary_parent->store_info_set_string(s, mi, type, str);
+			CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_set_string(s, mi, type, str);
 			break;
 	}
 }
diff --git a/camel/providers/groupwise/camel-groupwise-store-summary.h b/camel/providers/groupwise/camel-groupwise-store-summary.h
index 41ea304..45eebf7 100644
--- a/camel/providers/groupwise/camel-groupwise-store-summary.h
+++ b/camel/providers/groupwise/camel-groupwise-store-summary.h
@@ -19,20 +19,35 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_GW_STORE_SUMMARY_H
-#define _CAMEL_GW_STORE_SUMMARY_H
-
-#include <camel/camel-object.h>
-#include <camel/camel-store-summary.h>
-
-#define CAMEL_GW_STORE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_groupwise_store_summary_get_type (), CamelGroupwiseStoreSummary)
-#define CAMEL_GW_STORE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_groupwise_store_summary_get_type (), CamelGroupwiseStoreSummaryClass)
-#define CAMEL_IS_GW_STORE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_groupwise_store_summary_get_type ())
+#ifndef CAMEL_GROUPWISE_STORE_SUMMARY_H
+#define CAMEL_GROUPWISE_STORE_SUMMARY_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_GROUPWISE_STORE_SUMMARY \
+	(camel_groupwise_store_summary_get_type ())
+#define CAMEL_GROUPWISE_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_GROUPWISE_STORE_SUMMARY, CamelGroupwiseStoreSummary))
+#define CAMEL_GROUPWISE_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_GROUPWISE_STORE_SUMMARY, CamelGroupwiseStoreSummaryClass))
+#define CAMEL_IS_GROUPWISE_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_GROUPWISE_STORE_SUMMARY))
+#define CAMEL_IS_GROUPWISE_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_GROUPWISE_STORE_SUMMARY))
+#define CAMEL_GROUPWISE_STORE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_GROUPWISE_STORE_SUMMARY, CamelGroupwiseStoreSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelGroupwiseStoreSummary      CamelGroupwiseStoreSummary;
+typedef struct _CamelGroupwiseStoreSummary CamelGroupwiseStoreSummary;
 typedef struct _CamelGroupwiseStoreSummaryClass CamelGroupwiseStoreSummaryClass;
+typedef struct _CamelGroupwiseStoreSummaryPrivate CamelGroupwiseStoreSummaryPrivate;
 
 typedef struct _CamelGroupwiseStoreInfo CamelGroupwiseStoreInfo;
 
@@ -56,8 +71,7 @@ struct _CamelGroupwiseStoreNamespace {
 
 struct _CamelGroupwiseStoreSummary {
 	CamelStoreSummary summary;
-
-	struct _CamelGroupwiseStoreSummaryPrivate *priv;
+	CamelGroupwiseStoreSummaryPrivate *priv;
 
 	/* header info */
 	guint32 version;        /* version of base part of file */
@@ -69,7 +83,7 @@ struct _CamelGroupwiseStoreSummaryClass {
 	CamelStoreSummaryClass summary_class;
 };
 
-CamelType                        camel_groupwise_store_summary_get_type      (void);
+GType                        camel_groupwise_store_summary_get_type      (void);
 CamelGroupwiseStoreSummary      *camel_groupwise_store_summary_new        (void);
 CamelGroupwiseStoreInfo *camel_groupwise_store_summary_full_name(CamelGroupwiseStoreSummary *s, const gchar *full_name);
 CamelGroupwiseStoreInfo *camel_groupwise_store_summary_add_from_full(CamelGroupwiseStoreSummary *s, const gchar *full, gchar dir_sep);
@@ -86,4 +100,4 @@ void camel_groupwise_store_summary_namespace_set(CamelGroupwiseStoreSummary *s,
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_IMAP_STORE_SUMMARY_H */
+#endif /* CAMEL_GROUPWISE_STORE_SUMMARY_H */
diff --git a/camel/providers/groupwise/camel-groupwise-store.c b/camel/providers/groupwise/camel-groupwise-store.c
index 90aa3ee..ac624e4 100644
--- a/camel/providers/groupwise/camel-groupwise-store.c
+++ b/camel/providers/groupwise/camel-groupwise-store.c
@@ -34,16 +34,10 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "camel-debug.h"
-#include "camel-folder.h"
-#include "camel-net-utils.h"
 #include "camel-private.h"
-#include "camel-session.h"
-#include "camel-types.h"
 
 #include "camel-groupwise-folder.h"
 #include "camel-groupwise-store-summary.h"
@@ -56,6 +50,10 @@
 #define JUNK_ENABLE 1
 #define JUNK_PERSISTENCE 14
 
+#define CAMEL_GROUPWISE_STORE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_GROUPWISE_STORE, CamelGroupwiseStorePrivate))
+
 const gchar * CREATE_CURSOR_VIEW = "peek id default recipient threading hasAttachment subject status priority startDate created delivered size recurrenceKey";
 
 struct _CamelGroupwiseStorePrivate {
@@ -73,7 +71,7 @@ struct _CamelGroupwiseStorePrivate {
 	EGwConnection *cnc;
 };
 
-static CamelOfflineStoreClass *parent_class = NULL;
+static gpointer parent_class;
 
 extern CamelServiceAuthType camel_groupwise_password_authtype; /*for the query_auth_types function*/
 static CamelFolderInfo *convert_to_folder_info (CamelGroupwiseStore *store, EGwContainer *container, const gchar *url, CamelException *ex);
@@ -263,12 +261,12 @@ groupwise_store_set_current_folder (CamelGroupwiseStore *groupwise_store, CamelF
 	CAMEL_SERVICE_REC_LOCK (groupwise_store, connect_lock);
 
 	if (groupwise_store->current_folder) {
-		camel_object_unref (groupwise_store->current_folder);
+		g_object_unref (groupwise_store->current_folder);
 		groupwise_store->current_folder = NULL;
 	}
 
 	if (folder) {
-		camel_object_ref (folder);
+		g_object_ref (folder);
 		groupwise_store->current_folder = folder;
 	}
 
@@ -346,10 +344,10 @@ groupwise_disconnect_cleanup (CamelService *service, gboolean clean, CamelExcept
 	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service);
 	CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
 
-	g_print ("camel_groupwise_store_finalize\n");
+	g_print ("groupwise_store_finalize\n");
 	if (groupwise_store->summary) {
 		camel_store_summary_save ((CamelStoreSummary *)groupwise_store->summary);
-		camel_object_unref (groupwise_store->summary);
+		g_object_unref (groupwise_store->summary);
 	}
 
 	if (priv) {
@@ -647,7 +645,7 @@ groupwise_get_folder (CamelStore *store, const gchar *folder_name, guint32 flags
 						camel_folder_summary_save_to_db (folder->summary, ex);
 						camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID, _("Authentication failed"));
 						camel_operation_end (NULL);
-						camel_object_unref (folder);
+						g_object_unref (folder);
 						g_free (container_id);
 						return NULL;*/
 				}
@@ -919,7 +917,7 @@ convert_to_folder_info (CamelGroupwiseStore *store, EGwContainer *container, con
 	if (store->current_folder
 	    && !strcmp (store->current_folder->full_name, fi->full_name)
 	    && type != E_GW_CONTAINER_TYPE_INBOX) {
-		CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (store->current_folder))->refresh_info(store->current_folder, ex);
+		CAMEL_FOLDER_GET_CLASS (store->current_folder)->refresh_info (store->current_folder, ex);
 	}
 	return fi;
 }
@@ -1124,7 +1122,7 @@ store_refresh_free(CamelSession *session, CamelSessionThreadMsg *msg)
 {
 	struct _store_refresh_msg *m = (struct _store_refresh_msg *)msg;
 
-	camel_object_unref (m->store);
+	g_object_unref (m->store);
 	camel_exception_clear (&m->ex);
 }
 
@@ -1194,7 +1192,7 @@ groupwise_get_folder_info (CamelStore *store, const gchar *top, guint32 flags, C
 		}
 		if (camel_groupwise_store_connected (groupwise_store, ex)) {
 			if (groupwise_store->current_folder)
-				CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (groupwise_store->current_folder))->sync(groupwise_store->current_folder, FALSE, ex);
+				CAMEL_FOLDER_GET_CLASS (groupwise_store->current_folder)->sync (groupwise_store->current_folder, FALSE, ex);
 			groupwise_folders_sync (groupwise_store, ex);
 			if (camel_exception_is_set (ex)) {
 				CAMEL_SERVICE_REC_UNLOCK (store, connect_lock);
@@ -1519,131 +1517,121 @@ match_path(const gchar *path, const gchar *name)
 	return n == 0 && (p == '%' || p == 0);
 }
 
-/* GObject Init and finalise methods */
 static void
-camel_groupwise_store_class_init (CamelGroupwiseStoreClass *camel_groupwise_store_class)
+groupwise_store_dispose (GObject *object)
 {
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_groupwise_store_class);
-	CamelStoreClass *camel_store_class =
-		CAMEL_STORE_CLASS (camel_groupwise_store_class);
-
-	parent_class = CAMEL_OFFLINE_STORE_CLASS (camel_type_get_global_classfuncs (camel_offline_store_get_type ()));
-
-	camel_service_class->construct = groupwise_store_construct;
-	camel_service_class->query_auth_types = groupwise_store_query_auth_types;
-	camel_service_class->get_name = groupwise_get_name;
-	camel_service_class->connect = groupwise_connect;
-	camel_service_class->disconnect = groupwise_disconnect;
-
-	camel_store_class->hash_folder_name = groupwise_hash_folder_name;
-	camel_store_class->compare_folder_name = groupwise_compare_folder_name;
-
-	camel_store_class->get_folder = groupwise_get_folder;
-	camel_store_class->create_folder = groupwise_create_folder;
-	camel_store_class->delete_folder = groupwise_delete_folder;
-	camel_store_class->rename_folder = groupwise_rename_folder;
-	camel_store_class->get_folder_info = groupwise_get_folder_info;
-	camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-	camel_store_class->get_trash = groupwise_get_trash;
-	camel_store_class->can_refresh_folder = groupwise_can_refresh_folder;
-}
+	CamelGroupwiseStore *groupwise_store;
 
-/*This frees the private structure*/
-static void
-camel_groupwise_store_finalize (CamelObject *object)
-{
-	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (object);
-	CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
+	groupwise_store = CAMEL_GROUPWISE_STORE (object);
 
-	g_print ("camel_groupwise_store_finalize\n");
-	if (groupwise_store->summary) {
-		camel_store_summary_save ((CamelStoreSummary *)groupwise_store->summary);
-		camel_object_unref (groupwise_store->summary);
+	if (groupwise_store->summary != NULL) {
+		camel_store_summary_save (
+			CAMEL_STORE_SUMMARY (groupwise_store->summary));
+		g_object_unref (groupwise_store->summary);
+		groupwise_store->summary = NULL;
 	}
 
-	if (priv) {
-		if (priv->user) {
-			g_free (priv->user);
-			priv->user = NULL;
-		}
-		if (priv->server_name) {
-			g_free (priv->server_name);
-			priv->server_name = NULL;
-		}
-		if (priv->port) {
-			g_free (priv->port);
-			priv->port = NULL;
-		}
-		if (priv->use_ssl) {
-			g_free (priv->use_ssl);
-			priv->use_ssl = NULL;
-		}
-		if (priv->base_url) {
-			g_free (priv->base_url);
-			priv->base_url = NULL;
-		}
+	if (groupwise_store->priv->cnc != NULL) {
+		g_object_unref (groupwise_store->priv->cnc);
+		groupwise_store->priv->cnc = NULL;
+	}
 
-		if (E_IS_GW_CONNECTION (priv->cnc)) {
-			g_object_unref (priv->cnc);
-			priv->cnc = NULL;
-		}
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
 
-		if (priv->storage_path)
-			g_free(priv->storage_path);
+static void
+groupwise_store_finalize (GObject *object)
+{
+	CamelGroupwiseStore *groupwise_store;
 
-		if (groupwise_store->root_container)
-			g_free (groupwise_store->root_container);
+	groupwise_store = CAMEL_GROUPWISE_STORE (object);
 
-		if (priv->id_hash)
-			g_hash_table_destroy (priv->id_hash);
+	g_free (groupwise_store->priv->user);
+	g_free (groupwise_store->priv->server_name);
+	g_free (groupwise_store->priv->port);
+	g_free (groupwise_store->priv->use_ssl);
+	g_free (groupwise_store->priv->base_url);
+	g_free (groupwise_store->priv->storage_path);
+	g_free (groupwise_store->root_container);
 
-		if (priv->name_hash)
-			g_hash_table_destroy (priv->name_hash);
+	if (groupwise_store->priv->id_hash != NULL)
+		g_hash_table_destroy (groupwise_store->priv->id_hash);
 
-		if (priv->parent_hash)
-			g_hash_table_destroy (priv->parent_hash);
+	if (groupwise_store->priv->name_hash != NULL)
+		g_hash_table_destroy (groupwise_store->priv->name_hash);
 
-		g_free (groupwise_store->priv);
-		groupwise_store->priv = NULL;
-	}
+	if (groupwise_store->priv->parent_hash != NULL)
+		g_hash_table_destroy (groupwise_store->priv->parent_hash);
 
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_groupwise_store_init (gpointer object, gpointer klass)
+groupwise_store_class_init (CamelGroupwiseStoreClass *class)
 {
-	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (object);
-	CamelGroupwiseStorePrivate *priv = g_new0 (CamelGroupwiseStorePrivate, 1);
+	GObjectClass *object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelGroupwiseStorePrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = groupwise_store_dispose;
+	object_class->finalize = groupwise_store_finalize;
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = groupwise_store_construct;
+	service_class->query_auth_types = groupwise_store_query_auth_types;
+	service_class->get_name = groupwise_get_name;
+	service_class->connect = groupwise_connect;
+	service_class->disconnect = groupwise_disconnect;
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->hash_folder_name = groupwise_hash_folder_name;
+	store_class->compare_folder_name = groupwise_compare_folder_name;
+	store_class->get_folder = groupwise_get_folder;
+	store_class->create_folder = groupwise_create_folder;
+	store_class->delete_folder = groupwise_delete_folder;
+	store_class->rename_folder = groupwise_rename_folder;
+	store_class->get_folder_info = groupwise_get_folder_info;
+	store_class->free_folder_info = camel_store_free_folder_info_full;
+	store_class->get_trash = groupwise_get_trash;
+	store_class->can_refresh_folder = groupwise_can_refresh_folder;
+}
+
+static void
+groupwise_store_init (CamelGroupwiseStore *groupwise_store)
+{
+	groupwise_store->priv =
+		CAMEL_GROUPWISE_STORE_GET_PRIVATE (groupwise_store);
 
 	d("in groupwise store init\n");
-	priv->server_name = NULL;
-	priv->port = NULL;
-	priv->use_ssl = NULL;
-	priv->user = NULL;
-	priv->cnc = NULL;
-	groupwise_store->priv = priv;
+	groupwise_store->priv->server_name = NULL;
+	groupwise_store->priv->port = NULL;
+	groupwise_store->priv->use_ssl = NULL;
+	groupwise_store->priv->user = NULL;
+	groupwise_store->priv->cnc = NULL;
 	groupwise_store->current_folder = NULL;
-
 }
 
-CamelType
+GType
 camel_groupwise_store_get_type (void)
 {
-	static CamelType camel_groupwise_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_groupwise_store_type == CAMEL_INVALID_TYPE)	{
-		camel_groupwise_store_type =
-			camel_type_register (camel_offline_store_get_type (),
-					     "CamelGroupwiseStore",
-					     sizeof (CamelGroupwiseStore),
-					     sizeof (CamelGroupwiseStoreClass),
-					     (CamelObjectClassInitFunc) camel_groupwise_store_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) camel_groupwise_store_init,
-					     (CamelObjectFinalizeFunc) camel_groupwise_store_finalize);
-	}
-
-	return camel_groupwise_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OFFLINE_STORE,
+			"CamelGroupwiseStore",
+			sizeof (CamelGroupwiseStoreClass),
+			(GClassInitFunc) groupwise_store_class_init,
+			sizeof (CamelGroupwiseStore),
+			(GInstanceInitFunc) groupwise_store_init,
+			0);
+
+	return type;
 }
 
diff --git a/camel/providers/groupwise/camel-groupwise-store.h b/camel/providers/groupwise/camel-groupwise-store.h
index d4c5b1f..da6793f 100644
--- a/camel/providers/groupwise/camel-groupwise-store.h
+++ b/camel/providers/groupwise/camel-groupwise-store.h
@@ -22,19 +22,33 @@
  */
 
 #ifndef CAMEL_GROUPWISE_STORE_H
-#define CAMEL_GROUPWISE_STORE_H 1
+#define CAMEL_GROUPWISE_STORE_H
+
+#include <camel/camel.h>
 
-#include <camel/camel-store.h>
-#include <camel/camel-offline-store.h>
 #include "camel-groupwise-store-summary.h"
 
 #include <e-gw-connection.h>
 #include <e-gw-container.h>
 
-#define CAMEL_GROUPWISE_STORE_TYPE     (camel_groupwise_store_get_type ())
-#define CAMEL_GROUPWISE_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_GROUPWISE_STORE_TYPE, CamelGroupwiseStore))
-#define CAMEL_GROUPWISE_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_GROUPWISE_STORE_TYPE, CamelGroupwiseStoreClass))
-#define CAMEL_IS_GROUPWISE_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_GROUPWISE_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_GROUPWISE_STORE \
+	(camel_groupwise_store_get_type ())
+#define CAMEL_GROUPWISE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_GROUPWISE_STORE, CamelGroupwiseStore))
+#define CAMEL_GROUPWISE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_GROUPWISE_STORE, CamelGroupwiseStoreClass))
+#define CAMEL_IS_GROUPWISE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_GROUPWISE_STORE))
+#define CAMEL_IS_GROUPWISE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_GROUPWISE_STORE))
+#define CAMEL_GROUPWISE_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_GROUPWISE_STORE, CamelGroupwiseStoreClass))
 
 #define GW_PARAM_FILTER_INBOX		(1 << 0)
 
@@ -45,7 +59,7 @@ typedef struct _CamelGroupwiseStoreClass CamelGroupwiseStoreClass;
 typedef struct _CamelGroupwiseStorePrivate CamelGroupwiseStorePrivate;
 
 struct _CamelGroupwiseStore {
-	CamelOfflineStore parent_object;
+	CamelOfflineStore parent;
 
 	struct _CamelGroupwiseStoreSummary *summary;
 
@@ -63,8 +77,7 @@ struct _CamelGroupwiseStoreClass {
 	CamelOfflineStoreClass parent_class;
 };
 
-/* Standard Camel function */
-CamelType camel_groupwise_store_get_type (void);
+GType camel_groupwise_store_get_type (void);
 gchar * groupwise_get_name(CamelService *service, gboolean brief);
 
 /*IMplemented*/
diff --git a/camel/providers/groupwise/camel-groupwise-summary.c b/camel/providers/groupwise/camel-groupwise-summary.c
index b765645..cadad35 100644
--- a/camel/providers/groupwise/camel-groupwise-summary.c
+++ b/camel/providers/groupwise/camel-groupwise-summary.c
@@ -33,12 +33,6 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include "camel-db.h"
-#include "camel-data-cache.h"
-#include "camel-file-utils.h"
-#include "camel-folder.h"
-#include "camel-string-utils.h"
-
 #include "camel-groupwise-folder.h"
 #include "camel-groupwise-summary.h"
 
@@ -67,31 +61,9 @@ static CamelMessageInfo * message_info_from_db (CamelFolderSummary *s, CamelMIRe
 static gint content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelMIRecord *mir);
 static CamelMessageContentInfo * content_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir);
 
-static void camel_groupwise_summary_class_init (CamelGroupwiseSummaryClass *klass);
-static void camel_groupwise_summary_init       (CamelGroupwiseSummary *obj);
-
 /*End of Prototypes*/
 
-static CamelFolderSummaryClass *camel_groupwise_summary_parent;
-
-CamelType
-camel_groupwise_summary_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(
-				camel_folder_summary_get_type(), "CamelGroupwiseSummary",
-				sizeof (CamelGroupwiseSummary),
-				sizeof (CamelGroupwiseSummaryClass),
-				(CamelObjectClassInitFunc) camel_groupwise_summary_class_init,
-				NULL,
-				(CamelObjectInitFunc) camel_groupwise_summary_init,
-				NULL);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static CamelMessageInfo *
 gw_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
@@ -99,7 +71,7 @@ gw_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
 	CamelGroupwiseMessageInfo *to;
 	const CamelGroupwiseMessageInfo *from = (const CamelGroupwiseMessageInfo *)mi;
 
-	to = (CamelGroupwiseMessageInfo *)camel_groupwise_summary_parent->message_info_clone(s, mi);
+	to = (CamelGroupwiseMessageInfo *)CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_clone(s, mi);
 	to->server_flags = from->server_flags;
 
 	/* FIXME: parent clone should do this */
@@ -109,41 +81,58 @@ gw_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
 }
 
 static void
-camel_groupwise_summary_class_init (CamelGroupwiseSummaryClass *klass)
+groupwise_summary_class_init (CamelGroupwiseSummaryClass *class)
 {
-	CamelFolderSummaryClass *cfs_class = (CamelFolderSummaryClass *) klass;
-
-	camel_groupwise_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS (camel_type_get_global_classfuncs (camel_folder_summary_get_type()));
-
-	cfs_class->message_info_clone = gw_message_info_clone;
-	cfs_class->summary_header_load = gw_summary_header_load;
-	cfs_class->summary_header_save = gw_summary_header_save;
-	cfs_class->message_info_load = gw_message_info_load;
-	cfs_class->message_info_save = gw_message_info_save;
-	cfs_class->content_info_load = gw_content_info_load;
-	cfs_class->content_info_save = gw_content_info_save;
-	cfs_class->info_set_flags = gw_info_set_flags;
-
-	cfs_class->summary_header_to_db = summary_header_to_db;
-	cfs_class->summary_header_from_db = summary_header_from_db;
-	cfs_class->message_info_to_db = message_info_to_db;
-	cfs_class->message_info_from_db = message_info_from_db;
-	cfs_class->content_info_to_db = content_info_to_db;
-	cfs_class->content_info_from_db = content_info_from_db;
-
+	CamelFolderSummaryClass *folder_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->message_info_clone = gw_message_info_clone;
+	folder_summary_class->summary_header_load = gw_summary_header_load;
+	folder_summary_class->summary_header_save = gw_summary_header_save;
+	folder_summary_class->message_info_load = gw_message_info_load;
+	folder_summary_class->message_info_save = gw_message_info_save;
+	folder_summary_class->content_info_load = gw_content_info_load;
+	folder_summary_class->content_info_save = gw_content_info_save;
+	folder_summary_class->info_set_flags = gw_info_set_flags;
+	folder_summary_class->summary_header_to_db = summary_header_to_db;
+	folder_summary_class->summary_header_from_db = summary_header_from_db;
+	folder_summary_class->message_info_to_db = message_info_to_db;
+	folder_summary_class->message_info_from_db = message_info_from_db;
+	folder_summary_class->content_info_to_db = content_info_to_db;
+	folder_summary_class->content_info_from_db = content_info_from_db;
 }
 
 static void
-camel_groupwise_summary_init (CamelGroupwiseSummary *obj)
+groupwise_summary_init (CamelGroupwiseSummary *gw_summary)
 {
-	CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (gw_summary);
 
 	/* subclasses need to set the right instance data sizes */
-	s->message_info_size = sizeof(CamelGroupwiseMessageInfo);
-	s->content_info_size = sizeof(CamelGroupwiseMessageContentInfo);
+	summary->message_info_size = sizeof (CamelGroupwiseMessageInfo);
+	summary->content_info_size = sizeof (CamelGroupwiseMessageContentInfo);
 
 	/* Meta-summary - Overriding UID len */
-	s->meta_summary->uid_len = 2048;
+	summary->meta_summary->uid_len = 2048;
+}
+
+GType
+camel_groupwise_summary_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER_SUMMARY,
+			"CamelGroupwiseSummary",
+			sizeof (CamelGroupwiseSummaryClass),
+			(GClassInitFunc) groupwise_summary_class_init,
+			sizeof (CamelGroupwiseSummary),
+			(GInstanceInitFunc) groupwise_summary_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -159,9 +148,9 @@ CamelFolderSummary *
 camel_groupwise_summary_new (struct _CamelFolder *folder, const gchar *filename)
 {
 	CamelException ex;
-	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (
-			camel_object_new (camel_groupwise_summary_get_type ()));
+	CamelFolderSummary *summary;
 
+	summary = g_object_new (CAMEL_TYPE_GROUPWISE_SUMMARY, NULL);
 	summary->folder = folder;
 	camel_folder_summary_set_build_content (summary, TRUE);
 	camel_folder_summary_set_filename (summary, filename);
@@ -180,7 +169,7 @@ summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir)
 	CamelGroupwiseSummary *gms = CAMEL_GROUPWISE_SUMMARY (s);
 	gchar *part;
 
-	if (camel_groupwise_summary_parent->summary_header_from_db (s, mir) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_from_db (s, mir) == -1)
 		return -1;
 
 	part = mir->bdata;
@@ -203,7 +192,7 @@ gw_summary_header_load (CamelFolderSummary *s, FILE *in)
 {
 	CamelGroupwiseSummary *gms = CAMEL_GROUPWISE_SUMMARY (s);
 
-	if (camel_groupwise_summary_parent->summary_header_load (s, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (s, in) == -1)
 		return -1;
 
 	if (camel_file_util_decode_fixed_int32(in, &gms->version) == -1
@@ -221,7 +210,7 @@ summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 	CamelGroupwiseSummary *ims = CAMEL_GROUPWISE_SUMMARY(s);
 	struct _CamelFIRecord *fir;
 
-	fir = camel_groupwise_summary_parent->summary_header_to_db (s, ex);
+	fir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_to_db (s, ex);
 	if (!fir)
 		return NULL;
 
@@ -236,7 +225,7 @@ gw_summary_header_save (CamelFolderSummary *s, FILE *out)
 {
 	CamelGroupwiseSummary *gms = CAMEL_GROUPWISE_SUMMARY(s);
 
-	if (camel_groupwise_summary_parent->summary_header_save (s, out) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_save (s, out) == -1)
 		return -1;
 
 	camel_file_util_encode_fixed_int32(out, CAMEL_GW_SUMMARY_VERSION);
@@ -250,7 +239,7 @@ message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
 	CamelMessageInfo *info;
 	CamelGroupwiseMessageInfo *iinfo;
 
-	info = camel_groupwise_summary_parent->message_info_from_db (s, mir);
+	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_from_db (s, mir);
 	if (info) {
 		gchar *part = mir->bdata;
 		iinfo = (CamelGroupwiseMessageInfo *)info;
@@ -265,7 +254,7 @@ gw_message_info_load (CamelFolderSummary *s, FILE *in)
 	CamelMessageInfo *info;
 	CamelGroupwiseMessageInfo *gw_info;
 
-	info = camel_groupwise_summary_parent->message_info_load(s,in);
+	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load(s,in);
 	if (info) {
 		gw_info = (CamelGroupwiseMessageInfo*) info;
 		if (camel_file_util_decode_uint32 (in, &gw_info->server_flags) == -1)
@@ -284,7 +273,7 @@ message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info)
 	CamelGroupwiseMessageInfo *iinfo = (CamelGroupwiseMessageInfo *)info;
 	struct _CamelMIRecord *mir;
 
-	mir = camel_groupwise_summary_parent->message_info_to_db (s, info);
+	mir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_to_db (s, info);
 	if (mir)
 		mir->bdata = g_strdup_printf ("%u", iinfo->server_flags);
 
@@ -296,7 +285,7 @@ gw_message_info_save (CamelFolderSummary *s, FILE *out, CamelMessageInfo *info)
 {
 	CamelGroupwiseMessageInfo *gw_info = (CamelGroupwiseMessageInfo *)info;
 
-	if (camel_groupwise_summary_parent->message_info_save (s, out, info) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_save (s, out, info) == -1)
 		return -1;
 
 	return camel_file_util_encode_uint32 (out, gw_info->server_flags);
@@ -317,7 +306,7 @@ content_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
 	}
 	mir->cinfo = part;
 	if (type)
-		return camel_groupwise_summary_parent->content_info_from_db (s, mir);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_from_db (s, mir);
 	else
 		return camel_folder_summary_content_info_new (s);
 }
@@ -326,7 +315,7 @@ static CamelMessageContentInfo *
 gw_content_info_load (CamelFolderSummary *s, FILE *in)
 {
 	if (fgetc (in))
-		return camel_groupwise_summary_parent->content_info_load (s, in);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_load (s, in);
 	else
 		return camel_folder_summary_content_info_new (s);
 }
@@ -337,7 +326,7 @@ content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelM
 
 	if (info->type) {
 		mir->cinfo = g_strdup ("1");
-		return camel_groupwise_summary_parent->content_info_to_db (s, info, mir);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_to_db (s, info, mir);
 	} else {
 		mir->cinfo = g_strdup ("0");
 		return 0;
@@ -350,7 +339,7 @@ gw_content_info_save (CamelFolderSummary *s, FILE *out,
 {
 	if (info->type) {
 		fputc (1, out);
-		return camel_groupwise_summary_parent->content_info_save (s, out, info);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_save (s, out, info);
 	} else
 		return fputc (0, out);
 }
diff --git a/camel/providers/groupwise/camel-groupwise-summary.h b/camel/providers/groupwise/camel-groupwise-summary.h
index b5d61ad..527cda5 100644
--- a/camel/providers/groupwise/camel-groupwise-summary.h
+++ b/camel/providers/groupwise/camel-groupwise-summary.h
@@ -19,16 +19,29 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_GW_SUMMARY_H
-#define _CAMEL_GW_SUMMARY_H
-
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-exception.h>
-#include <camel/camel-store.h>
-
-#define CAMEL_GROUPWISE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_groupwise_summary_get_type (), CamelGroupwiseSummary)
-#define CAMEL_GROUPWISE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_groupwise_summary_get_type (), CamelGroupwiseSummaryClass)
-#define CAMEL_IS_GROUPWISE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_groupwise_summary_get_type ())
+#ifndef CAMEL_GW_SUMMARY_H
+#define CAMEL_GW_SUMMARY_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_GROUPWISE_SUMMARY \
+	(camel_groupwise_summary_get_type ())
+#define CAMEL_GROUPWISE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_GROUPWISE_SUMMARY, CamelGroupwiseSummary))
+#define CAMEL_GROUPWISE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_GROUPWISE_SUMMARY, CamelGroupwiseSummaryClass))
+#define CAMEL_IS_GROUPWISE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_GROUPWISE_SUMMARY))
+#define CAMEL_IS_GROUPWISE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_GROUPWISE_SUMMARY))
+#define CAMEL_GROUPWISE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_GROUPWISE_SUMMARY, CamelGroupwiseSummaryClass))
 
 G_BEGIN_DECLS
 
@@ -65,7 +78,7 @@ struct _CamelGroupwiseSummaryClass {
 	CamelFolderSummaryClass parent_class;
 } ;
 
-CamelType camel_groupwise_summary_get_type (void);
+GType camel_groupwise_summary_get_type (void);
 
 CamelFolderSummary *camel_groupwise_summary_new (struct _CamelFolder *folder, const gchar *filename);
 
@@ -76,4 +89,4 @@ void groupwise_summary_clear (CamelFolderSummary *summary, gboolean uncache);
 
 G_END_DECLS
 
-#endif /*_CAMEL_GW_SUMMARY_H*/
+#endif /*CAMEL_GW_SUMMARY_H*/
diff --git a/camel/providers/groupwise/camel-groupwise-transport.c b/camel/providers/groupwise/camel-groupwise-transport.c
index af7ff93..1c85b1f 100644
--- a/camel/providers/groupwise/camel-groupwise-transport.c
+++ b/camel/providers/groupwise/camel-groupwise-transport.c
@@ -28,18 +28,8 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
-#include "camel-data-wrapper.h"
-#include "camel-medium.h"
-#include "camel-mime-message.h"
-#include "camel-mime-utils.h"
-#include "camel-multipart.h"
-#include "camel-session.h"
-#include "camel-stream-mem.h"
-#include "camel-stream.h"
-
 #include "camel-groupwise-store.h"
 #include "camel-groupwise-transport.h"
 #include "camel-groupwise-utils.h"
@@ -52,91 +42,52 @@ static gboolean groupwise_send_to (CamelTransport *transport,
 				  CamelAddress *recipients,
 				  CamelException *ex);
 
-static gboolean groupwise_transport_connect (CamelService *service, CamelException *ex);
-static gchar *groupwise_transport_get_name (CamelService *service, gboolean brief);
-static void groupwise_transport_construct (CamelService *service, CamelSession *session,
-					   CamelProvider *provider, CamelURL *url, CamelException *ex);
-
-static CamelTransportClass *parent_class = NULL;
+static gpointer parent_class;
 
-static void
-camel_groupwise_transport_class_init (CamelGroupwiseTransportClass *camel_groupwise_transport_class)
+static gboolean
+groupwise_transport_connect (CamelService *service,
+                             CamelException *ex)
 {
-	CamelTransportClass *camel_transport_class =
-		CAMEL_TRANSPORT_CLASS (camel_groupwise_transport_class);
-
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_groupwise_transport_class);
-
-	parent_class = CAMEL_TRANSPORT_CLASS (camel_type_get_global_classfuncs (camel_transport_get_type ()));
-
-	camel_service_class->connect = groupwise_transport_connect;
-	camel_service_class->get_name = groupwise_transport_get_name;
-	camel_service_class->construct = groupwise_transport_construct;
-
-	/* virtual method overload */
-	camel_transport_class->send_to = groupwise_send_to;
+	return TRUE;
 }
 
-static void
-camel_groupwise_transport_init (CamelTransport *transport)
+static gchar *
+groupwise_transport_get_name (CamelService *service,
+                              gboolean brief)
 {
-	return;
+	if (brief)
+		return g_strdup_printf (
+			_("GroupWise server %s"),
+			service->url->host);
+	else
+		return g_strdup_printf (
+			_("GroupWise mail delivery via %s"),
+			service->url->host);
 }
 
 static void
-groupwise_transport_construct (CamelService *service, CamelSession *session,
-		CamelProvider *provider, CamelURL *url,
-		CamelException *ex)
-{
-	CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
-	if (camel_exception_is_set (ex))
-		return;
-}
-
-CamelType
-camel_groupwise_transport_get_type (void)
-{
-	static CamelType camel_groupwise_transport_type = CAMEL_INVALID_TYPE;
-
-	if (camel_groupwise_transport_type == CAMEL_INVALID_TYPE) {
-		camel_groupwise_transport_type =
-			camel_type_register (CAMEL_TRANSPORT_TYPE,
-					     "CamelGroupwiseTransport",
-					     sizeof (CamelGroupwiseTransport),
-					     sizeof (CamelGroupwiseTransportClass),
-					     (CamelObjectClassInitFunc) camel_groupwise_transport_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) camel_groupwise_transport_init,
-					     NULL);
-	}
-
-	return camel_groupwise_transport_type;
-}
-
-static gchar *groupwise_transport_get_name (CamelService *service, gboolean brief)
+groupwise_transport_construct (CamelService *service,
+                               CamelSession *session,
+                               CamelProvider *provider,
+                               CamelURL *url,
+                               CamelException *ex)
 {
-	if (brief)
-		return g_strdup_printf (_("GroupWise server %s"), service->url->host);
-	else {
-		return g_strdup_printf (_("GroupWise mail delivery via %s"),
-				service->url->host);
-	}
-}
+	CamelServiceClass *service_class;
 
-static gboolean
-groupwise_transport_connect (CamelService *service, CamelException *ex)
-{
-	return TRUE;
+	/* Chain up to parent's construct() method. */
+	service_class = CAMEL_SERVICE_CLASS (parent_class);
+	service_class->construct (service, session, provider, url, ex);
 
+	if (camel_exception_is_set (ex))
+		return;
 }
 
 static gboolean
 groupwise_send_to (CamelTransport *transport,
-		   CamelMimeMessage *message,
-		   CamelAddress *from,
-		   CamelAddress *recipients,
-		   CamelException *ex)
+                   CamelMimeMessage *message,
+                   CamelAddress *from,
+                   CamelAddress *recipients,
+                   CamelException *ex)
 {
 	CamelService *service;
 	CamelStore *store =  NULL;
@@ -228,3 +179,37 @@ groupwise_send_to (CamelTransport *transport,
 	return TRUE;
 }
 
+static void
+groupwise_transport_class_init (CamelGroupwiseTransportClass *class)
+{
+	CamelServiceClass *service_class;
+	CamelTransportClass *transport_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->connect = groupwise_transport_connect;
+	service_class->get_name = groupwise_transport_get_name;
+	service_class->construct = groupwise_transport_construct;
+
+	transport_class = CAMEL_TRANSPORT_CLASS (class);
+	transport_class->send_to = groupwise_send_to;
+}
+
+GType
+camel_groupwise_transport_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_TRANSPORT,
+			"CamelGroupwiseTransport",
+			sizeof (CamelGroupwiseTransportClass),
+			(GClassInitFunc) groupwise_transport_class_init,
+			sizeof (CamelGroupwiseTransport),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
+}
diff --git a/camel/providers/groupwise/camel-groupwise-transport.h b/camel/providers/groupwise/camel-groupwise-transport.h
index 53f69f4..9abf71a 100644
--- a/camel/providers/groupwise/camel-groupwise-transport.h
+++ b/camel/providers/groupwise/camel-groupwise-transport.h
@@ -22,30 +22,44 @@
  */
 
 #ifndef CAMEL_GROUPWISE_TRANSPORT_H
-#define CAMEL_GROUPWISE_TRANSPORT_H 1
+#define CAMEL_GROUPWISE_TRANSPORT_H
 
-#include <camel/camel-transport.h>
+#include <camel/camel.h>
 
-#define CAMEL_GROUPWISE_TRANSPORT_TYPE     (camel_groupwise_transport_get_type ())
-#define CAMEL_GROUPWISE_TRANSPORT(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_GROUPWISE_TRANSPORT_TYPE, CamelGroupwiseTransport))
-#define CAMEL_GROUPWISE_TRANSPORT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_GROUPWISE_TRANSPORT_TYPE, CamelGroupwiseTransportClass))
-#define CAMEL_IS_GROUPWISE_TRANSPORT(o)    (CAMEL_CHECK_TYPE((o), CAMEL_GROUPWISE_TRANSPORT_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_GROUPWISE_TRANSPORT \
+	(camel_groupwise_transport_get_type ())
+#define CAMEL_GROUPWISE_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_GROUPWISE_TRANSPORT, CamelGroupwiseTransport))
+#define CAMEL_GROUPWISE_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_GROUPWISE_TRANSPORT, CamelGroupwiseTransportClass))
+#define CAMEL_IS_GROUPWISE_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_GROUPWISE_TRANSPORT))
+#define CAMEL_IS_GROUPWISE_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_GROUPWISE_TRANSPORT))
+#define CAMEL_GROUPWISE_TRANSPORT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_GROUPWISE_TRANSPORT, CamelGroupwiseTransportClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelTransport parent_object;
-	gboolean connected;
+typedef struct _CamelGroupwiseTransport CamelGroupwiseTransport;
+typedef struct _CamelGroupwiseTransportClass CamelGroupwiseTransportClass;
 
-} CamelGroupwiseTransport;
+struct _CamelGroupwiseTransport {
+	CamelTransport parent;
+	gboolean connected;
+};
 
-typedef struct {
+struct _CamelGroupwiseTransportClass {
 	CamelTransportClass parent_class;
+};
 
-} CamelGroupwiseTransportClass;
-
-/* Standard Camel function */
-CamelType camel_groupwise_transport_get_type (void);
+GType camel_groupwise_transport_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/providers/groupwise/camel-groupwise-utils.c b/camel/providers/groupwise/camel-groupwise-utils.c
index 8a48641..01e7a6b 100644
--- a/camel/providers/groupwise/camel-groupwise-utils.c
+++ b/camel/providers/groupwise/camel-groupwise-utils.c
@@ -27,17 +27,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
-#include "camel/camel-address.h"
-#include "camel/camel-mime-filter-charset.h"
-#include "camel/camel-mime-message.h"
-#include "camel/camel-multipart.h"
-#include "camel/camel-service.h"
-#include "camel/camel-stream-filter.h"
-#include "camel/camel-stream-mem.h"
-
 #include "camel-groupwise-utils.h"
 
 #define SUBFOLDER_DIR_NAME     "subfolders"
@@ -285,12 +276,13 @@ add_recipients(GSList *recipient_list, CamelAddress *recipients, gint recipient_
 }
 
 static void
-send_as_attachment (EGwConnection *cnc, EGwItem *item, CamelStreamMem *content, CamelContentType *type, CamelDataWrapper *dw, const gchar *filename, const gchar *cid, GSList **attach_list)
+send_as_attachment (EGwConnection *cnc, EGwItem *item, CamelStream *content, CamelContentType *type, CamelDataWrapper *dw, const gchar *filename, const gchar *cid, GSList **attach_list)
 {
 	EGwItemLinkInfo *info = NULL;
 	EGwConnectionStatus status;
 	EGwItemAttachment *attachment;
 	EGwItem *temp_item;
+	GByteArray *buffer;
 
 	attachment = g_new0 (EGwItemAttachment, 1);
 	attachment->contentType = camel_content_type_simple (type);
@@ -298,27 +290,29 @@ send_as_attachment (EGwConnection *cnc, EGwItem *item, CamelStreamMem *content,
 	if (cid)
 		attachment->contentid = camel_header_contentid_decode (cid);
 
-	if (filename && content->buffer->data) {
+	buffer = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (content));
+
+	if (filename && buffer->data) {
 		if (camel_content_type_is (type, "application", "pgp-signature")) {
 			gchar *temp_str;
 			gint temp_len;
-			temp_str = g_base64_encode (content->buffer->data, content->buffer->len);
+			temp_str = g_base64_encode (buffer->data, buffer->len);
 			temp_len = strlen (temp_str);
 			attachment->data = g_strdup (temp_str);
 			attachment->size = temp_len;
 			g_free (temp_str);
 			temp_str = NULL;
 		} else {
-			attachment->data = g_base64_encode(content->buffer->data, content->buffer->len);
+			attachment->data = g_base64_encode(buffer->data, buffer->len);
 			attachment->size = strlen (attachment->data);
 		}
-	} else if (content->buffer->data) {
+	} else if (buffer->data) {
 		gchar *temp_str;
 		gint temp_len;
 		if (!strcmp (attachment->contentType, "multipart/digest")) {
 			/* FIXME? */
 		} else {
-			temp_str = g_base64_encode (content->buffer->data, content->buffer->len);
+			temp_str = g_base64_encode (buffer->data, buffer->len);
 			temp_len = strlen (temp_str);
 			attachment->data = g_strdup (temp_str);
 			attachment->size = temp_len;
@@ -406,7 +400,7 @@ camel_groupwise_util_item_from_message (EGwConnection *cnc, CamelMimeMessage *me
 	recipient_list = g_slist_reverse (recipient_list);
 
 	/** Get the mime parts from CamelMimemessge **/
-	mp = (CamelMultipart *)camel_medium_get_content_object (CAMEL_MEDIUM (message));
+	mp = (CamelMultipart *)camel_medium_get_content (CAMEL_MEDIUM (message));
 	if (!mp) {
 		g_warning ("ERROR: Could not get content object");
 		camel_operation_end (NULL);
@@ -418,11 +412,15 @@ camel_groupwise_util_item_from_message (EGwConnection *cnc, CamelMimeMessage *me
 		do_multipart (cnc, item, mp, &attach_list);
 	} else {
 		/*only message*/
-		CamelStreamMem *content = (CamelStreamMem *)camel_stream_mem_new ();
+		CamelStream *content;
 		CamelDataWrapper *dw = NULL;
 		CamelContentType *type;
+		GByteArray *buffer;
 
-		dw = camel_medium_get_content_object (CAMEL_MEDIUM (message));
+		buffer = g_byte_array_new ();
+		content = camel_stream_mem_new_with_byte_array (buffer);
+
+		dw = camel_medium_get_content (CAMEL_MEDIUM (message));
 		type = camel_mime_part_get_content_type((CamelMimePart *)message);
 
 		if (camel_content_type_is (type, "text", "plain")) {
@@ -437,28 +435,28 @@ camel_groupwise_util_item_from_message (EGwConnection *cnc, CamelMimeMessage *me
 
 			charset = camel_content_type_param (type, "charset");
 			if (charset && g_ascii_strcasecmp (charset, "US-ASCII") && g_ascii_strcasecmp (charset, "UTF-8")) {
-				filter = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "UTF-8");
-				filtered_stream = (CamelStream *) camel_stream_filter_new_with_stream ((CamelStream *) content);
+				filter = camel_mime_filter_charset_new (charset, "UTF-8");
+				filtered_stream = camel_stream_filter_new (content);
 				camel_stream_filter_add ((CamelStreamFilter *) filtered_stream, filter);
-				camel_object_unref (filter);
+				g_object_unref (filter);
 			} else {
 				/* US-ASCII or UTF-8 */
-				filtered_stream = (CamelStream *) content;
-				camel_object_ref (content);
+				filtered_stream = content;
+				g_object_ref (content);
 			}
 
 			camel_data_wrapper_decode_to_stream (dw, filtered_stream);
 			camel_stream_flush (filtered_stream);
-			camel_object_unref (filtered_stream);
+			g_object_unref (filtered_stream);
 
-			camel_stream_write ((CamelStream *) content, "", 1);
-			e_gw_item_set_message (item, (const gchar *)content->buffer->data);
+			camel_stream_write (content, "", 1);
+			e_gw_item_set_message (item, (const gchar *)buffer->data);
 		} else {
 			camel_data_wrapper_decode_to_stream (dw, (CamelStream *) content);
 			send_as_attachment (cnc, item, content, type, dw, NULL, NULL, &attach_list);
 		}
 
-		camel_object_unref (content);
+		g_object_unref (content);
 	}
 	/*Populate EGwItem*/
 	/*From Address*/
@@ -608,11 +606,16 @@ do_multipart (EGwConnection *cnc, EGwItem *item, CamelMultipart *mp, GSList **at
 	for ( i=0; i<part_count; i++) {
 		CamelContentType *type;
 		CamelMimePart *part;
-		CamelStreamMem *content = (CamelStreamMem *)camel_stream_mem_new ();
+		CamelStream *content;
 		CamelDataWrapper *dw = NULL;
+		GByteArray *buffer;
 		const gchar *disposition, *filename;
 		const gchar *content_id = NULL;
 		gboolean is_alternative = FALSE;
+
+		buffer = g_byte_array_new ();
+		content = camel_stream_mem_new_with_byte_array (buffer);
+
 		/*
 		 * XXX:
 		 * Assuming the first part always is the actual message
@@ -624,10 +627,10 @@ do_multipart (EGwConnection *cnc, EGwItem *item, CamelMultipart *mp, GSList **at
 			continue;
 
 		type = camel_mime_part_get_content_type(part);
-		dw = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+		dw = camel_medium_get_content (CAMEL_MEDIUM (part));
 
 		if (CAMEL_IS_MULTIPART (dw)) {
-			do_multipart (cnc, item, (CamelMultipart *) camel_medium_get_content_object ((CamelMedium *) part), attach_list);
+			do_multipart (cnc, item, (CamelMultipart *) camel_medium_get_content ((CamelMedium *) part), attach_list);
 			continue;
 		}
 
@@ -635,20 +638,24 @@ do_multipart (EGwConnection *cnc, EGwItem *item, CamelMultipart *mp, GSList **at
 			/* eh... I don't think this code will ever get hit? */
 			CamelMimePart *temp_part;
 			const gchar *cid = NULL;
-			CamelStreamMem *temp_content = (CamelStreamMem *)camel_stream_mem_new ();
+			CamelStream *temp_content;
 			CamelDataWrapper *temp_dw = NULL;
+			GByteArray *temp_buffer;
+
+			temp_buffer = g_byte_array_new ();
+			temp_content = camel_stream_mem_new_with_byte_array (temp_buffer);
 
 			temp_part = camel_multipart_get_part ((CamelMultipart *)dw, 1);
 			if (temp_part) {
 				is_alternative = TRUE;
-				temp_dw = camel_medium_get_content_object (CAMEL_MEDIUM (temp_part));
-				camel_data_wrapper_write_to_stream(temp_dw, (CamelStream *)temp_content);
+				temp_dw = camel_medium_get_content (CAMEL_MEDIUM (temp_part));
+				camel_data_wrapper_write_to_stream(temp_dw, temp_content);
 				filename = camel_mime_part_get_filename (temp_part);
 				disposition = camel_mime_part_get_disposition (temp_part);
 				cid = camel_mime_part_get_content_id (temp_part);
 				send_as_attachment (cnc, item, temp_content, type, temp_dw, filename, cid, attach_list);
 			}
-			camel_object_unref (temp_content);
+			g_object_unref (temp_content);
 			continue;
 		}
 
@@ -664,31 +671,31 @@ do_multipart (EGwConnection *cnc, EGwItem *item, CamelMultipart *mp, GSList **at
 
 			charset = camel_content_type_param (type, "charset");
 			if (charset && g_ascii_strcasecmp (charset, "US-ASCII") && g_ascii_strcasecmp (charset, "UTF-8")) {
-				filter = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "UTF-8");
-				filtered_stream = (CamelStream *) camel_stream_filter_new_with_stream ((CamelStream *) content);
+				filter = camel_mime_filter_charset_new (charset, "UTF-8");
+				filtered_stream = camel_stream_filter_new (content);
 				camel_stream_filter_add ((CamelStreamFilter *) filtered_stream, filter);
-				camel_object_unref (filter);
+				g_object_unref (filter);
 			} else {
 				/* US-ASCII or UTF-8 */
-				filtered_stream = (CamelStream *) content;
-				camel_object_ref (content);
+				filtered_stream = content;
+				g_object_ref (content);
 			}
 
 			camel_data_wrapper_decode_to_stream (dw, filtered_stream);
 			camel_stream_flush (filtered_stream);
-			camel_object_unref (filtered_stream);
+			g_object_unref (filtered_stream);
 
-			camel_stream_write ((CamelStream *) content, "", 1);
-			e_gw_item_set_message (item, (const gchar *)content->buffer->data);
+			camel_stream_write (content, "", 1);
+			e_gw_item_set_message (item, (const gchar *)buffer->data);
 		} else {
 			filename = camel_mime_part_get_filename (part);
 			disposition = camel_mime_part_get_disposition (part);
 			content_id = camel_mime_part_get_content_id (part);
 
-			camel_data_wrapper_decode_to_stream (dw, (CamelStream *) content);
+			camel_data_wrapper_decode_to_stream (dw, content);
 			send_as_attachment (cnc, item, content, type, dw, filename, content_id, attach_list);
 		}
 
-		camel_object_unref (content);
+		g_object_unref (content);
 	} /*end of for*/
 }
diff --git a/camel/providers/groupwise/camel-groupwise-utils.h b/camel/providers/groupwise/camel-groupwise-utils.h
index 8093444..42f3672 100644
--- a/camel/providers/groupwise/camel-groupwise-utils.h
+++ b/camel/providers/groupwise/camel-groupwise-utils.h
@@ -17,12 +17,10 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_GROUPWISE_UTILS__
-#define __CAMEL_GROUPWISE_UTILS__
+#ifndef CAMEL_GROUPWISE_UTILS__
+#define CAMEL_GROUPWISE_UTILS__
 
-#include <glib.h>
-#include <camel/camel-mime-message.h>
-#include <camel/camel-string-utils.h>
+#include <camel/camel.h>
 #include <e-gw-connection.h>
 #include <e-gw-container.h>
 #include <e-gw-item.h>
diff --git a/camel/providers/hula/camel-hula-provider.c b/camel/providers/hula/camel-hula-provider.c
index 5bf2a96..aaa453a 100644
--- a/camel/providers/hula/camel-hula-provider.c
+++ b/camel/providers/hula/camel-hula-provider.c
@@ -28,15 +28,9 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <gmodule.h>
 
-#include "camel-provider.h"
-#include "camel-sasl.h"
-#include "camel-session.h"
-#include "camel-url.h"
-
 static void add_hash (guint *hash, gchar *s);
 static guint hula_url_hash (gconstpointer key);
 static gint check_equal (gchar *s1, gchar *s2);
diff --git a/camel/providers/imap/Makefile.am b/camel/providers/imap/Makefile.am
index d514b4c..44ca8a8 100644
--- a/camel/providers/imap/Makefile.am
+++ b/camel/providers/imap/Makefile.am
@@ -34,7 +34,6 @@ noinst_HEADERS =			\
 	camel-imap-store-summary.h		\
 	camel-imap-summary.h			\
 	camel-imap-journal.h			\
-	camel-imap-types.h			\
 	camel-imap-utils.h			\
 	camel-imap-wrapper.h                    \
 	camel-imap-private.h
diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c
index 27beb32..39eec71 100644
--- a/camel/providers/imap/camel-imap-command.c
+++ b/camel/providers/imap/camel-imap-command.c
@@ -35,11 +35,7 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-debug.h"
-#include "camel-exception.h"
 #include "camel-private.h"
-#include "camel-session.h"
-#include "camel-utf8.h"
 
 #include "camel-imap-command.h"
 #include "camel-imap-folder.h"
@@ -99,9 +95,9 @@ camel_imap_command (CamelImapStore *store, CamelFolder *folder,
 		cmd = imap_command_strdup_vprintf (store, fmt, ap);
 		va_end (ap);
 	} else {
-		camel_object_ref(folder);
+		g_object_ref (folder);
 		if (store->current_folder)
-			camel_object_unref(store->current_folder);
+			g_object_unref (store->current_folder);
 		store->current_folder = folder;
 		cmd = imap_command_strdup_printf (store, "SELECT %F", folder->full_name);
 	}
@@ -389,7 +385,7 @@ imap_read_response (CamelImapStore *store, CamelException *ex)
 	response = g_new0 (CamelImapResponse, 1);
 /*FIXME	if (store->current_folder && camel_disco_store_status (CAMEL_DISCO_STORE (store)) != CAMEL_DISCO_STORE_RESYNCING) {
 		response->folder = store->current_folder;
-		camel_object_ref (CAMEL_OBJECT (response->folder));
+		g_object_ref (CAMEL_OBJECT (response->folder));
 	} */
 
 	response->untagged = g_ptr_array_new ();
@@ -637,7 +633,7 @@ camel_imap_response_free (CamelImapStore *store, CamelImapResponse *response)
 				g_array_free (expunged, TRUE);
 		}
 
-		camel_object_unref (CAMEL_OBJECT (response->folder));
+		g_object_unref (CAMEL_OBJECT (response->folder));
 	}
 
 	g_free (response);
@@ -660,7 +656,7 @@ camel_imap_response_free_without_processing (CamelImapStore *store,
 		return;
 
 	if (response->folder) {
-		camel_object_unref (CAMEL_OBJECT (response->folder));
+		g_object_unref (CAMEL_OBJECT (response->folder));
 		response->folder = NULL;
 	}
 	camel_imap_response_free (store, response);
diff --git a/camel/providers/imap/camel-imap-command.h b/camel/providers/imap/camel-imap-command.h
index 391684d..fc330a2 100644
--- a/camel/providers/imap/camel-imap-command.h
+++ b/camel/providers/imap/camel-imap-command.h
@@ -24,13 +24,14 @@
  */
 
 #ifndef CAMEL_IMAP_COMMAND_H
-#define CAMEL_IMAP_COMMAND_H 1
+#define CAMEL_IMAP_COMMAND_H
 
-#include <glib.h>
-#include "camel-imap-types.h"
+#include "camel-imap-store.h"
 
 G_BEGIN_DECLS
 
+typedef struct _CamelImapResponse CamelImapResponse;
+
 typedef enum {
 	CAMEL_IMAP_RESPONSE_ERROR,
 	CAMEL_IMAP_RESPONSE_CONTINUATION,
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index 90ee0d4..50805d4 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -39,32 +39,11 @@
 #include <libedataserver/e-data-server-util.h>
 #include <libedataserver/e-time-utils.h>
 
-#include "camel-db.h"
-#include "camel-data-wrapper.h"
-#include "camel-debug.h"
-#include "camel-imap-journal.h"
-#include "camel-exception.h"
-#include "camel-file-utils.h"
-#include "camel-mime-filter-crlf.h"
-#include "camel-mime-filter-from.h"
-#include "camel-mime-message.h"
-#include "camel-mime-utils.h"
-#include "camel-mime-part-utils.h"
-#include "camel-multipart-encrypted.h"
-#include "camel-multipart-signed.h"
-#include "camel-multipart.h"
-#include "camel-operation.h"
 #include "camel-private.h"
-#include "camel-session.h"
-#include "camel-store-summary.h"
-#include "camel-stream-buffer.h"
-#include "camel-stream-filter.h"
-#include "camel-stream-mem.h"
-#include "camel-stream.h"
-#include "camel-string-utils.h"
 
 #include "camel-imap-command.h"
 #include "camel-imap-folder.h"
+#include "camel-imap-journal.h"
 #include "camel-imap-message-cache.h"
 #include "camel-imap-private.h"
 #include "camel-imap-search.h"
@@ -82,16 +61,16 @@
  * octets) */
 #define UID_SET_LIMIT  (768)
 
-extern gint camel_application_is_exiting;
+#define CAMEL_IMAP_FOLDER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_IMAP_FOLDER, CamelImapFolderPrivate))
 
-#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(o)))
-static CamelOfflineFolderClass *offline_folder_class = NULL;
+extern gint camel_application_is_exiting;
 
 static CamelProperty imap_property_list[] = {
 	{ CAMEL_IMAP_FOLDER_CHECK_FOLDER, "check_folder", N_("Always check for new mail in this folder") },
 };
 
-static void imap_finalize (CamelObject *object);
 static gint imap_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
 static gint imap_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
 
@@ -137,7 +116,7 @@ static void       imap_search_free          (CamelFolder *folder, GPtrArray *uid
 static void imap_thaw (CamelFolder *folder);
 static CamelFolderQuotaInfo *imap_get_quota_info (CamelFolder *folder);
 
-static CamelObjectClass *parent_class;
+static gpointer parent_class;
 
 static GData *parse_fetch_response (CamelImapFolder *imap_folder, gchar *msg_att);
 
@@ -156,39 +135,101 @@ static CamelImapMessageInfo * imap_folder_summary_uid_or_error(
 #endif
 
 static void
-camel_imap_folder_class_init (CamelImapFolderClass *camel_imap_folder_class)
+imap_folder_dispose (GObject *object)
 {
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_imap_folder_class);
-
-	offline_folder_class = CAMEL_OFFLINE_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_offline_folder_get_type ()));
-
-	/* virtual method overload */
-	((CamelObjectClass *)camel_imap_folder_class)->getv = imap_getv;
-	((CamelObjectClass *)camel_imap_folder_class)->setv = imap_setv;
-
-	camel_folder_class->get_message = imap_get_message;
-	camel_folder_class->rename = imap_rename;
-	camel_folder_class->search_by_expression = imap_search_by_expression;
-	camel_folder_class->count_by_expression = imap_count_by_expression;
-	camel_folder_class->search_by_uids = imap_search_by_uids;
-	camel_folder_class->search_free = imap_search_free;
-	camel_folder_class->thaw = imap_thaw;
-	camel_folder_class->get_quota_info = imap_get_quota_info;
-	camel_folder_class->refresh_info = imap_refresh_info;
-	camel_folder_class->expunge = imap_expunge;
-	camel_folder_class->sync= imap_sync;
-	camel_folder_class->append_message = imap_append_online;
-	camel_folder_class->sync_message = imap_sync_message;
-	camel_folder_class->transfer_messages_to = imap_transfer_online;
-	camel_folder_class->get_uncached_uids = imap_get_uncached_uids;
-	camel_folder_class->get_filename = imap_get_filename;
+	CamelImapFolder *imap_folder;
+
+	imap_folder = CAMEL_IMAP_FOLDER (object);
+
+	if (imap_folder->search != NULL) {
+		g_object_unref (imap_folder->search);
+		imap_folder->search = NULL;
+	}
+
+	if (imap_folder->cache != NULL) {
+		g_object_unref (imap_folder->cache);
+		imap_folder->cache = NULL;
+	}
+
+	if (imap_folder->priv->ignore_recent != NULL) {
+		g_hash_table_unref (imap_folder->priv->ignore_recent);
+		imap_folder->priv->ignore_recent = NULL;
+	}
+
+	if (imap_folder->journal != NULL) {
+		camel_offline_journal_write (imap_folder->journal, NULL);
+		g_object_unref (imap_folder->journal);
+		imap_folder->journal = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_imap_folder_init (gpointer object, gpointer klass)
+imap_folder_finalize (GObject *object)
 {
-	CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (object);
-	CamelFolder *folder = CAMEL_FOLDER (object);
+	CamelImapFolder *imap_folder;
+
+	imap_folder = CAMEL_IMAP_FOLDER (object);
+
+#ifdef ENABLE_THREADS
+	g_static_mutex_free (&imap_folder->priv->search_lock);
+	g_static_rec_mutex_free (&imap_folder->priv->cache_lock);
+#endif
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+imap_folder_class_init (CamelImapFolderClass *class)
+{
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+	CamelFolderClass *folder_class;
+	gint i;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelImapFolderPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = imap_folder_dispose;
+	object_class->finalize = imap_folder_finalize;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = imap_getv;
+	camel_object_class->setv = imap_setv;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->get_message = imap_get_message;
+	folder_class->rename = imap_rename;
+	folder_class->search_by_expression = imap_search_by_expression;
+	folder_class->count_by_expression = imap_count_by_expression;
+	folder_class->search_by_uids = imap_search_by_uids;
+	folder_class->search_free = imap_search_free;
+	folder_class->thaw = imap_thaw;
+	folder_class->get_quota_info = imap_get_quota_info;
+	folder_class->refresh_info = imap_refresh_info;
+	folder_class->expunge = imap_expunge;
+	folder_class->sync= imap_sync;
+	folder_class->append_message = imap_append_online;
+	folder_class->sync_message = imap_sync_message;
+	folder_class->transfer_messages_to = imap_transfer_online;
+	folder_class->get_uncached_uids = imap_get_uncached_uids;
+	folder_class->get_filename = imap_get_filename;
+
+	/* only localize here, do not create GSList, we do not want to leak */
+	for (i = 0; i < G_N_ELEMENTS (imap_property_list); i++)
+		imap_property_list[i].description = _(imap_property_list[i].description);
+}
+
+static void
+imap_folder_init (CamelImapFolder *imap_folder)
+{
+	CamelFolder *folder = CAMEL_FOLDER (imap_folder);
+
+	imap_folder->priv = CAMEL_IMAP_FOLDER_GET_PRIVATE (imap_folder);
 
 	folder->permanent_flags = CAMEL_MESSAGE_ANSWERED | CAMEL_MESSAGE_DELETED |
 		CAMEL_MESSAGE_DRAFT | CAMEL_MESSAGE_FLAGGED | CAMEL_MESSAGE_SEEN;
@@ -196,7 +237,6 @@ camel_imap_folder_init (gpointer object, gpointer klass)
 	folder->folder_flags |= (CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY |
 				 CAMEL_FOLDER_HAS_SEARCH_CAPABILITY);
 
-	imap_folder->priv = g_malloc0(sizeof(*imap_folder->priv));
 #ifdef ENABLE_THREADS
 	g_static_mutex_init(&imap_folder->priv->search_lock);
 	g_static_rec_mutex_init(&imap_folder->priv->cache_lock);
@@ -207,30 +247,22 @@ camel_imap_folder_init (gpointer object, gpointer klass)
 	imap_folder->need_rescan = TRUE;
 }
 
-CamelType
+GType
 camel_imap_folder_get_type (void)
 {
-	static CamelType camel_imap_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_imap_folder_type == CAMEL_INVALID_TYPE) {
-		gint i;
-
-		parent_class = camel_offline_folder_get_type();
-		camel_imap_folder_type =
-			camel_type_register (parent_class, "CamelImapFolder",
-					     sizeof (CamelImapFolder),
-					     sizeof (CamelImapFolderClass),
-					     (CamelObjectClassInitFunc) camel_imap_folder_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) camel_imap_folder_init,
-					     (CamelObjectFinalizeFunc) imap_finalize);
-
-		/* only localize here, do not create GSList, we do not want to leak */
-		for (i = 0; i < G_N_ELEMENTS (imap_property_list); i++)
-			imap_property_list [i].description = _(imap_property_list [i].description);
-	}
-
-	return camel_imap_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OFFLINE_FOLDER,
+			"CamelImapFolder",
+			sizeof (CamelImapFolderClass),
+			(GClassInitFunc) imap_folder_class_init,
+			sizeof (CamelImapFolder),
+			(GInstanceInitFunc) imap_folder_init,
+			0);
+
+	return type;
 }
 
 static void
@@ -279,7 +311,7 @@ camel_imap_folder_new (CamelStore *parent, const gchar *folder_name,
 		return NULL;
 	}
 
-	folder = CAMEL_FOLDER (camel_object_new (camel_imap_folder_get_type ()));
+	folder = g_object_new (CAMEL_TYPE_IMAP_FOLDER, NULL);
 	short_name = strrchr (folder_name, '/');
 	if (short_name)
 		short_name++;
@@ -291,7 +323,7 @@ camel_imap_folder_new (CamelStore *parent, const gchar *folder_name,
 	folder->summary = camel_imap_summary_new (folder, summary_file);
 	g_free (summary_file);
 	if (!folder->summary) {
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not load summary for %s"),
 				      folder_name);
@@ -311,7 +343,7 @@ camel_imap_folder_new (CamelStore *parent, const gchar *folder_name,
 
 	imap_folder->cache = camel_imap_message_cache_new (folder_dir, folder->summary, ex);
 	if (!imap_folder->cache) {
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 		return NULL;
 	}
 
@@ -468,31 +500,6 @@ camel_imap_folder_selected (CamelFolder *folder, CamelImapResponse *response,
 	/* And we're done. */
 }
 
-static void
-imap_finalize (CamelObject *object)
-{
-	CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (object);
-
-	if (imap_folder->search)
-		camel_object_unref (CAMEL_OBJECT (imap_folder->search));
-	if (imap_folder->cache)
-		camel_object_unref (CAMEL_OBJECT (imap_folder->cache));
-
-#ifdef ENABLE_THREADS
-	g_static_mutex_free(&imap_folder->priv->search_lock);
-	g_static_rec_mutex_free(&imap_folder->priv->cache_lock);
-#endif
-	if (imap_folder->priv->ignore_recent)
-		g_hash_table_unref (imap_folder->priv->ignore_recent);
-
-	if (imap_folder->journal) {
-		camel_offline_journal_write (imap_folder->journal, NULL);
-		camel_object_unref (imap_folder->journal);
-	}
-
-	g_free(imap_folder->priv);
-}
-
 static gchar *
 imap_get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex)
 {
@@ -632,7 +639,7 @@ imap_rename (CamelFolder *folder, const gchar *new)
 	g_free(summary_path);
 	g_free(folder_dir);
 
-	((CamelFolderClass *)offline_folder_class)->rename(folder, new);
+	CAMEL_FOLDER_CLASS (parent_class)->rename (folder, new);
 }
 
 /* called with connect_lock locked */
@@ -1601,7 +1608,7 @@ imap_expunge_uids_online (CamelFolder *folder, GPtrArray *uids, CamelException *
 	CAMEL_SERVICE_REC_LOCK (store, connect_lock);
 
 	if ((store->capabilities & IMAP_CAPABILITY_UIDPLUS) == 0) {
-		((CamelFolderClass *)CAMEL_OBJECT_GET_CLASS(folder))->sync(folder, 0, ex);
+		CAMEL_FOLDER_GET_CLASS (folder)->sync (folder, 0, ex);
 		if (camel_exception_is_set(ex)) {
 			CAMEL_SERVICE_REC_UNLOCK (store, connect_lock);
 			return;
@@ -1712,7 +1719,7 @@ imap_expunge_uids_resyncing (CamelFolder *folder, GPtrArray *uids, CamelExceptio
 
 	CAMEL_SERVICE_REC_LOCK (store, connect_lock);
 
-	((CamelFolderClass *)CAMEL_OBJECT_GET_CLASS(folder))->sync(folder, 0, ex);
+	CAMEL_FOLDER_GET_CLASS (folder)->sync (folder, 0, ex);
 	if (camel_exception_is_set(ex)) {
 		CAMEL_SERVICE_REC_UNLOCK (store, connect_lock);
 		return;
@@ -1931,7 +1938,7 @@ do_append (CamelFolder *folder, CamelMimeMessage *message,
 	CamelImapResponse *response, *response2;
 	CamelStream *memstream;
 	CamelMimeFilter *crlf_filter;
-	CamelStreamFilter *streamfilter;
+	CamelStream *streamfilter;
 	GByteArray *ba;
 	gchar *flagstr, *end;
 	guint32 flags = 0;
@@ -1944,15 +1951,16 @@ do_append (CamelFolder *folder, CamelMimeMessage *message,
 	ba = g_byte_array_new ();
 	camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (memstream), ba);
 
-	streamfilter = camel_stream_filter_new_with_stream (memstream);
+	streamfilter = camel_stream_filter_new (memstream);
 	crlf_filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE,
 						  CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
-	camel_stream_filter_add (streamfilter, crlf_filter);
-	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message),
-					    CAMEL_STREAM (streamfilter));
-	camel_object_unref (CAMEL_OBJECT (streamfilter));
-	camel_object_unref (CAMEL_OBJECT (crlf_filter));
-	camel_object_unref (CAMEL_OBJECT (memstream));
+	camel_stream_filter_add (
+		CAMEL_STREAM_FILTER (streamfilter), crlf_filter);
+	camel_data_wrapper_write_to_stream (
+		CAMEL_DATA_WRAPPER (message), streamfilter);
+	g_object_unref (streamfilter);
+	g_object_unref (crlf_filter);
+	g_object_unref (memstream);
 
 	/* Some servers don't let us append with (CamelMessageInfo *)custom flags.  If the command fails for
 	   whatever reason, assume this is the case and save the state and try again */
@@ -2149,7 +2157,7 @@ imap_transfer_offline (CamelFolder *source, GPtrArray *uids,
 
 		if (message) {
 			camel_imap_summary_add_offline (dest->summary, destuid, message, mi);
-			camel_object_unref (CAMEL_OBJECT (message));
+			g_object_unref (CAMEL_OBJECT (message));
 		} else
 			camel_imap_summary_add_offline_uncached (dest->summary, destuid, mi);
 
@@ -2476,7 +2484,7 @@ imap_transfer_resyncing (CamelFolder *source, GPtrArray *uids,
 
 			imap_append_online (dest, message, info, NULL, ex);
 			camel_folder_free_message_info (source, info);
-			camel_object_unref (CAMEL_OBJECT (message));
+			g_object_unref (CAMEL_OBJECT (message));
 			if (delete_originals && !camel_exception_is_set (ex))
 				camel_folder_delete_message (source, uid);
 			i++;
@@ -2689,9 +2697,9 @@ get_content (CamelImapFolder *imap_folder, const gchar *uid,
 		stream = camel_imap_folder_fetch_data (imap_folder, uid, spec, FALSE, ex);
 		if (stream) {
 			ret = camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (body_mp), stream);
-			camel_object_unref (CAMEL_OBJECT (stream));
+			g_object_unref (CAMEL_OBJECT (stream));
 			if (ret == -1) {
-				camel_object_unref ((CamelObject *) body_mp);
+				g_object_unref ( body_mp);
 				return NULL;
 			}
 		}
@@ -2729,10 +2737,10 @@ get_content (CamelImapFolder *imap_folder, const gchar *uid,
 
 				part = camel_mime_part_new ();
 				ret = camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (part), stream);
-				camel_object_unref (CAMEL_OBJECT (stream));
+				g_object_unref (CAMEL_OBJECT (stream));
 				if (ret == -1) {
-					camel_object_unref (CAMEL_OBJECT (part));
-					camel_object_unref (CAMEL_OBJECT (body_mp));
+					g_object_unref (CAMEL_OBJECT (part));
+					g_object_unref (CAMEL_OBJECT (body_mp));
 					g_free (child_spec);
 					return NULL;
 				}
@@ -2741,7 +2749,7 @@ get_content (CamelImapFolder *imap_folder, const gchar *uid,
 			}
 
 			if (!stream || !content) {
-				camel_object_unref (CAMEL_OBJECT (body_mp));
+				g_object_unref (CAMEL_OBJECT (body_mp));
 				g_free (child_spec);
 				return NULL;
 			}
@@ -2766,11 +2774,11 @@ get_content (CamelImapFolder *imap_folder, const gchar *uid,
 				camel_data_wrapper_set_mime_type_field(content, camel_mime_part_get_content_type(part));
 			}
 
-			camel_medium_set_content_object (CAMEL_MEDIUM (part), content);
-			camel_object_unref(content);
+			camel_medium_set_content (CAMEL_MEDIUM (part), content);
+			g_object_unref (content);
 
 			camel_multipart_add_part (body_mp, part);
-			camel_object_unref(part);
+			g_object_unref (part);
 
 			ci = ci->next;
 		}
@@ -2825,15 +2833,15 @@ get_message (CamelImapFolder *imap_folder, const gchar *uid,
 
 	msg = camel_mime_message_new ();
 	ret = camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), stream);
-	camel_object_unref (CAMEL_OBJECT (stream));
+	g_object_unref (CAMEL_OBJECT (stream));
 	if (ret == -1) {
-		camel_object_unref (CAMEL_OBJECT (msg));
+		g_object_unref (CAMEL_OBJECT (msg));
 		return NULL;
 	}
 
 	content = get_content (imap_folder, uid, CAMEL_MIME_PART (msg), ci, TRUE, ex);
 	if (!content) {
-		camel_object_unref (CAMEL_OBJECT (msg));
+		g_object_unref (CAMEL_OBJECT (msg));
 		return NULL;
 	}
 
@@ -2847,8 +2855,8 @@ get_message (CamelImapFolder *imap_folder, const gchar *uid,
 	}
 
 	camel_data_wrapper_set_mime_type_field(content, camel_mime_part_get_content_type((CamelMimePart *)msg));
-	camel_medium_set_content_object (CAMEL_MEDIUM (msg), content);
-	camel_object_unref (CAMEL_OBJECT (content));
+	camel_medium_set_content (CAMEL_MEDIUM (msg), content);
+	g_object_unref (CAMEL_OBJECT (content));
 
 	return msg;
 }
@@ -2872,12 +2880,12 @@ get_message_simple (CamelImapFolder *imap_folder, const gchar *uid,
 	msg = camel_mime_message_new ();
 	ret = camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg),
 							stream);
-	camel_object_unref (CAMEL_OBJECT (stream));
+	g_object_unref (CAMEL_OBJECT (stream));
 	if (ret == -1) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 				      _("Unable to retrieve message: %s"),
 				      g_strerror (errno));
-		camel_object_unref (CAMEL_OBJECT (msg));
+		g_object_unref (CAMEL_OBJECT (msg));
 		return NULL;
 	}
 
@@ -3046,7 +3054,11 @@ done:
 
 		if (!mi->info.mlist || !*mi->info.mlist) {
 			/* update mailing list information, if necessary */
-			gchar *mlist = camel_header_raw_check_mailing_list (&(CAMEL_MIME_PART (msg)->headers));
+			struct _camel_header_raw *headers;
+			gchar *mlist;
+
+			headers = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (msg));
+			mlist = camel_header_raw_check_mailing_list (&headers);
 
 			if (mlist) {
 				if (mi->info.mlist)
@@ -3103,12 +3115,12 @@ imap_sync_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 	/* If its cached in full, just get it as is, this is only a shortcut,
 	   since we get stuff from the cache anyway.  It affects a busted connection though. */
 	if ((stream = camel_imap_folder_fetch_data(imap_folder, uid, "", TRUE, NULL))) {
-		camel_object_unref (stream);
+		g_object_unref (stream);
 		return;
 	}
 	msg = imap_get_message(folder, uid, ex);
 	if (msg)
-		camel_object_unref(msg);
+		g_object_unref (msg);
 }
 
 /* FIXME Remove it after confirming
@@ -3121,7 +3133,7 @@ imap_cache_message (CamelDiscoFolder *disco_folder, const gchar *uid,
 
 	stream = camel_imap_folder_fetch_data (imap_folder, uid, "", FALSE, ex);
 	if (stream)
-		camel_object_unref (CAMEL_OBJECT (stream));
+		g_object_unref (CAMEL_OBJECT (stream));
 }
 */
 
@@ -3254,14 +3266,14 @@ add_message_from_data (CamelFolder *folder, GPtrArray *messages,
 
 	msg = camel_mime_message_new ();
 	if (camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), stream) == -1) {
-		camel_object_unref (CAMEL_OBJECT (msg));
+		g_object_unref (CAMEL_OBJECT (msg));
 		return;
 	}
 
 	bodystructure = g_datalist_get_data (&data, "BODY");
 
 	mi = (CamelImapMessageInfo *)camel_folder_summary_info_new_from_message (folder->summary, msg, bodystructure);
-	camel_object_unref (CAMEL_OBJECT (msg));
+	g_object_unref (CAMEL_OBJECT (msg));
 
 	if ((idate = g_datalist_get_data (&data, "INTERNALDATE")))
 		mi->info.date_received = decode_internaldate ((const guchar *) idate);
@@ -3755,7 +3767,7 @@ imap_thaw (CamelFolder *folder)
 {
 	CamelImapFolder *imap_folder;
 
-	CAMEL_FOLDER_CLASS (offline_folder_class)->thaw (folder);
+	CAMEL_FOLDER_CLASS (parent_class)->thaw (folder);
 	if (camel_folder_is_frozen (folder))
 		return;
 
@@ -3847,7 +3859,7 @@ camel_imap_folder_fetch_data (CamelImapFolder *imap_folder, const gchar *uid,
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 				      _("Could not find message body in FETCH response."));
 	} else {
-		camel_object_ref (CAMEL_OBJECT (stream));
+		g_object_ref (CAMEL_OBJECT (stream));
 		g_datalist_clear (&fetch_data);
 	}
 
@@ -3998,7 +4010,7 @@ parse_fetch_response (CamelImapFolder *imap_folder, gchar *response)
 
 		if (stream)
 			g_datalist_set_data_full (&data, "BODY_PART_STREAM", stream,
-						  (GDestroyNotify) camel_object_unref);
+						  (GDestroyNotify) g_object_unref);
 	}
 
 	return data;
diff --git a/camel/providers/imap/camel-imap-folder.h b/camel/providers/imap/camel-imap-folder.h
index 8071df1..963aba5 100644
--- a/camel/providers/imap/camel-imap-folder.h
+++ b/camel/providers/imap/camel-imap-folder.h
@@ -24,17 +24,31 @@
  */
 
 #ifndef CAMEL_IMAP_FOLDER_H
-#define CAMEL_IMAP_FOLDER_H 1
-
-#include "camel-imap-types.h"
-#include <camel/camel-offline-folder.h>
-#include <camel/camel-folder-search.h>
-#include <camel/camel-offline-journal.h>
-
-#define CAMEL_IMAP_FOLDER_TYPE     (camel_imap_folder_get_type ())
-#define CAMEL_IMAP_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_FOLDER_TYPE, CamelImapFolder))
-#define CAMEL_IMAP_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_IMAP_FOLDER_TYPE, CamelImapFolderClass))
-#define CAMEL_IS_IMAP_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_FOLDER_TYPE))
+#define CAMEL_IMAP_FOLDER_H
+
+#include <camel.h>
+
+#include "camel-imap-command.h"
+#include "camel-imap-message-cache.h"
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP_FOLDER \
+	(camel_imap_folder_get_type ())
+#define CAMEL_IMAP_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_FOLDER, CamelImapFolder))
+#define CAMEL_IMAP_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_FOLDER, CamelImapFolderClass))
+#define CAMEL_IS_IMAP_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_FOLDER))
+#define CAMEL_IS_IMAP_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_FOLDER))
+#define CAMEL_IMAP_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_FOLDER, CamelImapFolderClass))
 
 G_BEGIN_DECLS
 
@@ -49,11 +63,12 @@ enum {
 	CAMEL_IMAP_FOLDER_CHECK_FOLDER = CAMEL_IMAP_FOLDER_ARG_CHECK_FOLDER | CAMEL_ARG_BOO
 };
 
+typedef struct _CamelImapFolder CamelImapFolder;
 typedef struct _CamelImapFolderClass CamelImapFolderClass;
 typedef struct _CamelImapFolderPrivate CamelImapFolderPrivate;
 
 struct _CamelImapFolder {
-	CamelOfflineFolder parent_object;
+	CamelOfflineFolder parent;
 
 	CamelImapFolderPrivate *priv;
 
@@ -69,9 +84,6 @@ struct _CamelImapFolder {
 
 struct _CamelImapFolderClass {
 	CamelOfflineFolderClass parent_class;
-
-	/* Virtual methods */
-
 };
 
 /* public methods */
@@ -103,8 +115,7 @@ imap_transfer_resyncing (CamelFolder *source, GPtrArray *uids,
 void
 imap_expunge_uids_resyncing (CamelFolder *folder, GPtrArray *uids, CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_imap_folder_get_type (void);
+GType camel_imap_folder_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/providers/imap/camel-imap-journal.c b/camel/providers/imap/camel-imap-journal.c
index b164a27..716723e 100644
--- a/camel/providers/imap/camel-imap-journal.c
+++ b/camel/providers/imap/camel-imap-journal.c
@@ -36,22 +36,11 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-data-cache.h>
-#include <camel/camel-file-utils.h>
-#include <camel/camel-folder.h>
-#include <camel/camel-store.h>
-#include <camel/camel-session.h>
-
 #include "camel-imap-journal.h"
 #include "camel-imap-folder.h"
 
 #define d(x)
 
-static void camel_imap_journal_class_init (CamelIMAPJournalClass *klass);
-static void camel_imap_journal_init (CamelIMAPJournal *journal, CamelIMAPJournalClass *klass);
-static void camel_imap_journal_finalize (CamelObject *object);
-
 static void imap_entry_free (CamelOfflineJournal *journal, CamelDListNode *entry);
 static CamelDListNode *imap_entry_load (CamelOfflineJournal *journal, FILE *in);
 static gint imap_entry_write (CamelOfflineJournal *journal, CamelDListNode *entry, FILE *out);
@@ -60,46 +49,7 @@ static void unref_folder (gpointer key, gpointer value, gpointer data);
 static void free_uids (GPtrArray *array);
 static void close_folder (gpointer name, gpointer folder, gpointer data);
 
-static CamelOfflineJournalClass *parent_class = NULL;
-
-CamelType
-camel_imap_journal_get_type (void)
-{
-	static CamelType type = NULL;
-
-	if (!type) {
-		type = camel_type_register (camel_offline_journal_get_type (),
-					    "CamelIMAPJournal",
-					    sizeof (CamelIMAPJournal),
-					    sizeof (CamelIMAPJournalClass),
-					    (CamelObjectClassInitFunc) camel_imap_journal_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap_journal_init,
-					    (CamelObjectFinalizeFunc) camel_imap_journal_finalize);
-	}
-
-	return type;
-}
-
-static void
-camel_imap_journal_class_init (CamelIMAPJournalClass *klass)
-{
-	CamelOfflineJournalClass *journal_class = (CamelOfflineJournalClass *) klass;
-
-	parent_class = (CamelOfflineJournalClass *) camel_type_get_global_classfuncs (CAMEL_TYPE_OFFLINE_JOURNAL);
-
-	journal_class->entry_free = imap_entry_free;
-	journal_class->entry_load = imap_entry_load;
-	journal_class->entry_write = imap_entry_write;
-	journal_class->entry_play = imap_entry_play;
-}
-
-static void
-camel_imap_journal_init (CamelIMAPJournal *journal, CamelIMAPJournalClass *klass)
-{
-	journal->folders = g_hash_table_new (g_str_hash, g_str_equal);
-	journal->uidmap = g_hash_table_new (g_str_hash, g_str_equal);
-}
+static gpointer parent_class;
 
 static void
 free_uid (gpointer key, gpointer value, gpointer data)
@@ -109,25 +59,72 @@ free_uid (gpointer key, gpointer value, gpointer data)
 }
 
 static void
-camel_imap_journal_finalize (CamelObject *object)
+imap_journal_finalize (GObject *object)
 {
-	CamelIMAPJournal *journal = (CamelIMAPJournal *) object;
+	CamelIMAPJournal *journal = CAMEL_IMAP_JOURNAL (object);
 
 	if (journal->folders) {
 		g_hash_table_foreach (journal->folders, unref_folder, NULL);
 		g_hash_table_destroy (journal->folders);
 		journal->folders = NULL;
 	}
+
 	if (journal->uidmap) {
 		g_hash_table_foreach (journal->uidmap, free_uid, NULL);
 		g_hash_table_destroy (journal->uidmap);
 	}
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+imap_journal_class_init (CamelIMAPJournalClass *class)
+{
+	GObjectClass *object_class;
+	CamelOfflineJournalClass *offline_journal_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = imap_journal_finalize;
+
+	offline_journal_class = CAMEL_OFFLINE_JOURNAL_CLASS (class);
+	offline_journal_class->entry_free = imap_entry_free;
+	offline_journal_class->entry_load = imap_entry_load;
+	offline_journal_class->entry_write = imap_entry_write;
+	offline_journal_class->entry_play = imap_entry_play;
+}
+
+static void
+imap_journal_init (CamelIMAPJournal *journal)
+{
+	journal->folders = g_hash_table_new (g_str_hash, g_str_equal);
+	journal->uidmap = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+GType
+camel_imap_journal_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OFFLINE_JOURNAL,
+			"CamelIMAPJournal",
+			sizeof (CamelIMAPJournalClass),
+			(GClassInitFunc) imap_journal_class_init,
+			sizeof (CamelIMAPJournal),
+			(GInstanceInitFunc) imap_journal_init,
+			0);
+
+	return type;
 }
 
 static void
 unref_folder (gpointer key, gpointer value, gpointer data)
 {
-	camel_object_unref (value);
+	g_object_unref (value);
 }
 
 static void
@@ -408,7 +405,7 @@ camel_imap_journal_new (CamelImapFolder *folder, const gchar *filename)
 	g_return_val_if_fail (CAMEL_IS_IMAP_FOLDER (folder), NULL);
 
 	d(g_print ("Creating the journal \n"));
-	journal = (CamelOfflineJournal *) camel_object_new (camel_imap_journal_get_type ());
+	journal = g_object_new (CAMEL_TYPE_IMAP_JOURNAL, NULL);
 	camel_offline_journal_construct (journal, (CamelFolder *) folder, filename);
 
 	return journal;
@@ -465,7 +462,7 @@ close_folder (gpointer name, gpointer folder, gpointer data)
 {
 	g_free (name);
 	camel_folder_sync (folder, FALSE, NULL);
-	camel_object_unref (folder);
+	g_object_unref (folder);
 }
 
 void
diff --git a/camel/providers/imap/camel-imap-journal.h b/camel/providers/imap/camel-imap-journal.h
index d6d31e4..8cc6f13 100644
--- a/camel/providers/imap/camel-imap-journal.h
+++ b/camel/providers/imap/camel-imap-journal.h
@@ -21,23 +21,30 @@
  *
  */
 
-#ifndef __CAMEL_IMAP_JOURNAL_H__
-#define __CAMEL_IMAP_JOURNAL_H__
+#ifndef CAMEL_IMAP_JOURNAL_H
+#define CAMEL_IMAP_JOURNAL_H
 
 #include <stdarg.h>
-
-#include <glib.h>
-
-#include <camel/camel-list-utils.h>
-#include <camel/camel-offline-journal.h>
-#include <camel/camel-mime-message.h>
-
-#define CAMEL_TYPE_IMAP_JOURNAL            (camel_imap_journal_get_type ())
-#define CAMEL_IMAP_JOURNAL(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP_JOURNAL, CamelIMAPJournal))
-#define CAMEL_IMAP_JOURNAL_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_IMAP_JOURNAL, CamelIMAPJournalClass))
-#define CAMEL_IS_IMAP_JOURNAL(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_IMAP_JOURNAL))
-#define CAMEL_IS_IMAP_JOURNAL_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_IMAP_JOURNAL))
-#define CAMEL_IMAP_JOURNAL_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_IMAP_JOURNAL, CamelIMAPJournalClass))
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP_JOURNAL \
+	(camel_imap_journal_get_type ())
+#define CAMEL_IMAP_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_JOURNAL, CamelIMAPJournal))
+#define CAMEL_IMAP_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_JOURNAL, CamelIMAPJournalClass))
+#define CAMEL_IS_IMAP_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_JOURNAL))
+#define CAMEL_IS_IMAP_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_JOURNAL))
+#define CAMEL_IMAP_JOURNAL_GET_CLASS(obj) \
+	(CAMEL_CHECK_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_JOURNAL, CamelIMAPJournalClass))
 
 G_BEGIN_DECLS
 
@@ -66,7 +73,7 @@ struct _CamelIMAPJournalEntry {
 };
 
 struct _CamelIMAPJournal {
-	CamelOfflineJournal parent_object;
+	CamelOfflineJournal parent;
 
 	GHashTable *folders;
 	GHashTable *uidmap;
@@ -78,7 +85,7 @@ struct _CamelIMAPJournalClass {
 
 };
 
-CamelType camel_imap_journal_get_type (void);
+GType camel_imap_journal_get_type (void);
 
 CamelOfflineJournal *camel_imap_journal_new (struct _CamelImapFolder *folder, const gchar *filename);
 void camel_imap_journal_log (CamelOfflineJournal *journal, CamelOfflineAction action, ...);
@@ -88,4 +95,4 @@ void camel_imap_journal_close_folders (CamelIMAPJournal *journal);
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP_JOURNAL_H__ */
+#endif /* CAMEL_IMAP_JOURNAL_H */
diff --git a/camel/providers/imap/camel-imap-message-cache.c b/camel/providers/imap/camel-imap-message-cache.c
index 4509a49..35f9f60 100644
--- a/camel/providers/imap/camel-imap-message-cache.c
+++ b/camel/providers/imap/camel-imap-message-cache.c
@@ -32,11 +32,6 @@
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "camel-data-wrapper.h"
-#include "camel-exception.h"
-#include "camel-stream-fs.h"
-#include "camel-string-utils.h"
-
 #include "camel-imap-message-cache.h"
 
 #ifndef O_BINARY
@@ -52,7 +47,8 @@
 #define BASE_PART_SUFFIX "."
 #endif
 
-static void finalize (CamelImapMessageCache *cache);
+static gpointer parent_class;
+
 static void stream_finalize (CamelObject *stream, gpointer event_data, gpointer user_data);
 
 struct _part_find {
@@ -64,25 +60,6 @@ struct _part_find {
 	gint found;
 };
 
-CamelType
-camel_imap_message_cache_get_type (void)
-{
-	static CamelType camel_imap_message_cache_type = CAMEL_INVALID_TYPE;
-
-	if (camel_imap_message_cache_type == CAMEL_INVALID_TYPE) {
-		camel_imap_message_cache_type = camel_type_register (
-			CAMEL_OBJECT_TYPE, "CamelImapMessageCache",
-			sizeof (CamelImapMessageCache),
-			sizeof (CamelImapMessageCacheClass),
-			NULL,
-			NULL,
-			NULL,
-			(CamelObjectFinalizeFunc) finalize);
-	}
-
-	return camel_imap_message_cache_type;
-}
-
 static void
 free_part (gpointer key, gpointer value, gpointer data)
 {
@@ -90,7 +67,7 @@ free_part (gpointer key, gpointer value, gpointer data)
 		if (strchr (key, '.')) {
 			camel_object_unhook_event (value, "finalize",
 						   stream_finalize, data);
-			camel_object_unref (value);
+			g_object_unref (value);
 		} else
 			g_ptr_array_free (value, TRUE);
 	}
@@ -98,16 +75,53 @@ free_part (gpointer key, gpointer value, gpointer data)
 }
 
 static void
-finalize (CamelImapMessageCache *cache)
+imap_message_cache_finalize (GObject *object)
 {
-	if (cache->path)
-		g_free (cache->path);
+	CamelImapMessageCache *cache;
+
+	cache = CAMEL_IMAP_MESSAGE_CACHE (object);
+
+	g_free (cache->path);
+
 	if (cache->parts) {
 		g_hash_table_foreach (cache->parts, free_part, cache);
 		g_hash_table_destroy (cache->parts);
 	}
+
 	if (cache->cached)
 		g_hash_table_destroy (cache->cached);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+imap_message_cache_class_init (CamelImapMessageCacheClass *class)
+{
+	GObjectClass *object_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = imap_message_cache_finalize;
+}
+
+GType
+camel_imap_message_cache_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelImapMessageCache",
+			sizeof (CamelImapMessageCacheClass),
+			(GClassInitFunc) imap_message_cache_class_init,
+			sizeof (CamelImapMessageCache),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 static void
@@ -134,7 +148,7 @@ cache_put (CamelImapMessageCache *cache, const gchar *uid, const gchar *key,
 			camel_object_unhook_event (ostream, "finalize",
 						   stream_finalize, cache);
 			g_hash_table_remove (cache->cached, ostream);
-			camel_object_unref (ostream);
+			g_object_unref (ostream);
 		}
 		hash_key = okey;
 	} else {
@@ -184,7 +198,7 @@ camel_imap_message_cache_new (const gchar *path, CamelFolderSummary *summary,
 		return NULL;
 	}
 
-	cache = (CamelImapMessageCache *)camel_object_new (CAMEL_IMAP_MESSAGE_CACHE_TYPE);
+	cache = g_object_new (CAMEL_TYPE_IMAP_MESSAGE_CACHE, NULL);
 	cache->path = g_strdup (path);
 
 	cache->parts = g_hash_table_new (g_str_hash, g_str_equal);
@@ -322,7 +336,7 @@ insert_setup (CamelImapMessageCache *cache, const gchar *uid, const gchar *part_
 	*key = strrchr (*path, '/') + 1;
 	stream = g_hash_table_lookup (cache->parts, *key);
 	if (stream)
-		camel_object_unref (CAMEL_OBJECT (stream));
+		g_object_unref (CAMEL_OBJECT (stream));
 
 	fd = g_open (*path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0600);
 	if (fd == -1) {
@@ -341,7 +355,7 @@ insert_abort (gchar *path, CamelStream *stream)
 {
 	g_unlink (path);
 	g_free (path);
-	camel_object_unref (CAMEL_OBJECT (stream));
+	g_object_unref (CAMEL_OBJECT (stream));
 	return NULL;
 }
 
@@ -420,7 +434,7 @@ camel_imap_message_cache_insert_stream (CamelImapMessageCache *cache,
 		insert_abort (path, stream);
 	} else {
 		insert_finish (cache, uid, path, key, stream);
-		camel_object_unref (CAMEL_OBJECT (stream));
+		g_object_unref (CAMEL_OBJECT (stream));
 	}
 }
 
@@ -452,7 +466,7 @@ camel_imap_message_cache_insert_wrapper (CamelImapMessageCache *cache,
 		insert_abort (path, stream);
 	} else {
 		insert_finish (cache, uid, path, key, stream);
-		camel_object_unref (CAMEL_OBJECT (stream));
+		g_object_unref (CAMEL_OBJECT (stream));
 	}
 }
 
@@ -517,7 +531,7 @@ camel_imap_message_cache_get (CamelImapMessageCache *cache, const gchar *uid,
 	stream = g_hash_table_lookup (cache->parts, key);
 	if (stream) {
 		camel_stream_reset (CAMEL_STREAM (stream));
-		camel_object_ref (CAMEL_OBJECT (stream));
+		g_object_ref (CAMEL_OBJECT (stream));
 		g_free (path);
 		return stream;
 	}
@@ -563,7 +577,7 @@ camel_imap_message_cache_remove (CamelImapMessageCache *cache, const gchar *uid)
 		if (stream) {
 			camel_object_unhook_event (stream, "finalize",
 						   stream_finalize, cache);
-			camel_object_unref (stream);
+			g_object_unref (stream);
 			g_hash_table_remove (cache->cached, stream);
 		}
 		g_hash_table_remove (cache->parts, key);
@@ -633,7 +647,7 @@ camel_imap_message_cache_copy (CamelImapMessageCache *source,
 
 		if ((stream = camel_imap_message_cache_get (source, source_uid, part, ex))) {
 			camel_imap_message_cache_insert_stream (dest, dest_uid, part, stream, ex);
-			camel_object_unref (CAMEL_OBJECT (stream));
+			g_object_unref (CAMEL_OBJECT (stream));
 		}
 	}
 }
diff --git a/camel/providers/imap/camel-imap-message-cache.h b/camel/providers/imap/camel-imap-message-cache.h
index ac7d35f..640c388 100644
--- a/camel/providers/imap/camel-imap-message-cache.h
+++ b/camel/providers/imap/camel-imap-message-cache.h
@@ -23,21 +23,36 @@
  */
 
 #ifndef CAMEL_IMAP_MESSAGE_CACHE_H
-#define CAMEL_IMAP_MESSAGE_CACHE_H 1
-
-#include "camel-imap-types.h"
-#include "camel-folder.h"
-#include <camel/camel-folder-search.h>
-
-#define CAMEL_IMAP_MESSAGE_CACHE_TYPE     (camel_imap_message_cache_get_type ())
-#define CAMEL_IMAP_MESSAGE_CACHE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_MESSAGE_CACHE_TYPE, CamelImapFolder))
-#define CAMEL_IMAP_MESSAGE_CACHE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_IMAP_MESSAGE_CACHE_TYPE, CamelImapFolderClass))
-#define CAMEL_IS_IMAP_MESSAGE_CACHE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_MESSAGE_CACHE_TYPE))
+#define CAMEL_IMAP_MESSAGE_CACHE_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP_MESSAGE_CACHE \
+	(camel_imap_message_cache_get_type ())
+#define CAMEL_IMAP_MESSAGE_CACHE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_MESSAGE_CACHE, CamelImapMessageCache))
+#define CAMEL_IMAP_MESSAGE_CACHE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_MESSAGE_CACHE, CamelImapMessageCacheClass))
+#define CAMEL_IS_IMAP_MESSAGE_CACHE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_MESSAGE_CACHE))
+#define CAMEL_IS_IMAP_MESSAGE_CACHE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_MESSAGE_CACHE))
+#define CAMEL_IMAP_MESSAGE_CACHE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_MESSAGE_CACHE, CamelImapMessageCacheClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelImapMessageCache CamelImapMessageCache;
+typedef struct _CamelImapMessageCacheClass CamelImapMessageCacheClass;
+
 struct _CamelImapMessageCache {
-	CamelObject parent_object;
+	CamelObject parent;
 
 	gchar *path;
         /* parts contains two sorts of objects.
@@ -51,12 +66,9 @@ struct _CamelImapMessageCache {
 	guint32 max_uid;
 };
 
-typedef struct {
-	CamelFolderClass parent_class;
-
-	/* Virtual methods */
-
-} CamelImapMessageCacheClass;
+struct _CamelImapMessageCacheClass {
+	CamelObjectClass parent_class;
+};
 
 /* public methods */
 CamelImapMessageCache *camel_imap_message_cache_new (const gchar *path,
@@ -111,8 +123,7 @@ GPtrArray *  camel_imap_message_cache_filter_cached(CamelImapMessageCache *,
                                               GPtrArray *uids,
                                               CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_imap_message_cache_get_type (void);
+GType camel_imap_message_cache_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/providers/imap/camel-imap-private.h b/camel/providers/imap/camel-imap-private.h
index 7d09c83..c2a4901 100644
--- a/camel/providers/imap/camel-imap-private.h
+++ b/camel/providers/imap/camel-imap-private.h
@@ -1,5 +1,5 @@
 #ifndef CAMEL_IMAP_PRIVATE_H
-#define CAMEL_IMAP_PRIVATE_H 1
+#define CAMEL_IMAP_PRIVATE_H
 
 /* need a way to configure and save this data, if this header is to
    be installed.  For now, dont install it */
diff --git a/camel/providers/imap/camel-imap-provider.c b/camel/providers/imap/camel-imap-provider.c
index d5c9ef8..aa5028c 100644
--- a/camel/providers/imap/camel-imap-provider.c
+++ b/camel/providers/imap/camel-imap-provider.c
@@ -25,14 +25,10 @@
 #include <config.h>
 
 #include <string.h>
-
+#include <camel/camel.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-imap-store.h"
-#include "camel-provider.h"
-#include "camel-sasl.h"
-#include "camel-session.h"
-#include "camel-url.h"
 
 static void add_hash (guint *hash, gchar *s);
 static guint imap_url_hash (gconstpointer key);
diff --git a/camel/providers/imap/camel-imap-search.c b/camel/providers/imap/camel-imap-search.c
index aca5442..f84df81 100644
--- a/camel/providers/imap/camel-imap-search.c
+++ b/camel/providers/imap/camel-imap-search.c
@@ -32,9 +32,7 @@
 
 #include <libedataserver/e-sexp.h>
 
-#include "camel-mime-utils.h"	/* base64 encoding */
 #include "camel-search-private.h"
-#include "camel-seekable-stream.h"
 
 #include "camel-imap-command.h"
 #include "camel-imap-folder.h"
@@ -93,61 +91,96 @@ struct _match_record {
 	GArray *matches;
 };
 
-static void free_match(CamelImapSearch *is, struct _match_record *mr);
 static ESExpResult *imap_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
 
-static CamelFolderSearchClass *imap_search_parent_class;
+static gpointer parent_class;
 
 static void
-camel_imap_search_class_init (CamelImapSearchClass *camel_imap_search_class)
+free_match(CamelImapSearch *is, struct _match_record *mr)
 {
-	/* virtual method overload */
-	CamelFolderSearchClass *camel_folder_search_class =
-		CAMEL_FOLDER_SEARCH_CLASS (camel_imap_search_class);
-
-	imap_search_parent_class = (CamelFolderSearchClass *)camel_type_get_global_classfuncs (camel_folder_search_get_type ());
+	gint i;
 
-	/* virtual method overload */
-	camel_folder_search_class->body_contains = imap_body_contains;
+	for (i=0;i<mr->termcount;i++)
+		g_free(mr->terms[i]);
+	g_free(mr->terms);
+	g_array_free(mr->matches, TRUE);
+	g_free(mr);
 }
 
 static void
-camel_imap_search_init(CamelImapSearch *is)
+imap_search_dispose (GObject *object)
 {
-	camel_dlist_init(&is->matches);
-	is->matches_hash = g_hash_table_new(g_str_hash, g_str_equal);
-	is->matches_count = 0;
-	is->lastuid = 0;
+	CamelImapSearch *search;
+
+	search = CAMEL_IMAP_SEARCH (object);
+
+	if (search->cache != NULL) {
+		g_object_unref (search->cache);
+		search->cache = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_imap_search_finalise(CamelImapSearch *is)
+imap_search_finalize (GObject *object)
 {
+	CamelImapSearch *search;
 	struct _match_record *mr;
 
-	while ( (mr = (struct _match_record *)camel_dlist_remtail(&is->matches)) )
-		free_match(is, mr);
-	g_hash_table_destroy(is->matches_hash);
-	if (is->cache)
-		camel_object_unref((CamelObject *)is->cache);
+	search = CAMEL_IMAP_SEARCH (object);
+
+	while ( (mr = (struct _match_record *)camel_dlist_remtail(&search->matches)) )
+		free_match (search, mr);
+
+	g_hash_table_destroy (search->matches_hash);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+imap_search_class_init (CamelImapSearchClass *class)
+{
+	GObjectClass *object_class;
+	CamelFolderSearchClass *folder_search_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = imap_search_dispose;
+	object_class->finalize = imap_search_finalize;
+
+	folder_search_class = CAMEL_FOLDER_SEARCH_CLASS (class);
+	folder_search_class->body_contains = imap_body_contains;
 }
 
-CamelType
+static void
+imap_search_init (CamelImapSearch *is)
+{
+	camel_dlist_init(&is->matches);
+	is->matches_hash = g_hash_table_new(g_str_hash, g_str_equal);
+	is->matches_count = 0;
+	is->lastuid = 0;
+}
+
+GType
 camel_imap_search_get_type (void)
 {
-	static CamelType camel_imap_search_type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (camel_imap_search_type == CAMEL_INVALID_TYPE) {
-		camel_imap_search_type = camel_type_register (
-			CAMEL_FOLDER_SEARCH_TYPE, "CamelImapSearch",
-			sizeof (CamelImapSearch),
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER_SEARCH,
+			"CamelImapSearch",
 			sizeof (CamelImapSearchClass),
-			(CamelObjectClassInitFunc) camel_imap_search_class_init, NULL,
-			(CamelObjectInitFunc) camel_imap_search_init,
-			(CamelObjectFinalizeFunc) camel_imap_search_finalise);
-	}
+			(GClassInitFunc) imap_search_class_init,
+			sizeof (CamelImapSearch),
+			(GInstanceInitFunc) imap_search_init,
+			0);
 
-	return camel_imap_search_type;
+	return type;
 }
 
 /**
@@ -158,12 +191,12 @@ camel_imap_search_get_type (void)
 CamelFolderSearch *
 camel_imap_search_new (const gchar *cachedir)
 {
-	CamelFolderSearch *new = CAMEL_FOLDER_SEARCH (camel_object_new (camel_imap_search_get_type ()));
+	CamelFolderSearch *new = g_object_new (CAMEL_TYPE_IMAP_SEARCH, NULL);
 	CamelImapSearch *is = (CamelImapSearch *)new;
 
 	camel_folder_search_construct (new);
 
-	is->cache = camel_data_cache_new(cachedir, 0, NULL);
+	is->cache = camel_data_cache_new(cachedir, NULL);
 	if (is->cache) {
 		/* Expire entries after 14 days of inactivity */
 		camel_data_cache_set_expire_access(is->cache, 60*60*24*14);
@@ -241,22 +274,10 @@ save_match(CamelImapSearch *is, struct _match_record *mr)
 		ret = -1;
 	}
 
-	camel_object_unref((CamelObject *)stream);
+	g_object_unref (stream);
 	return ret;
 }
 
-static void
-free_match(CamelImapSearch *is, struct _match_record *mr)
-{
-	gint i;
-
-	for (i=0;i<mr->termcount;i++)
-		g_free(mr->terms[i]);
-	g_free(mr->terms);
-	g_array_free(mr->matches, TRUE);
-	g_free(mr);
-}
-
 static struct _match_record *
 load_match(CamelImapSearch *is, gchar hash[17], gint argc, struct _ESExpResult **argv)
 {
@@ -299,7 +320,7 @@ load_match(CamelImapSearch *is, gchar hash[17], gint argc, struct _ESExpResult *
 			d(printf(" file format invalid/validity changed\n"));
 			memset(&header, 0, sizeof(header));
 		}
-		camel_object_unref((CamelObject *)stream);
+		g_object_unref (stream);
 	} else {
 		d(printf(" no cache entry found\n"));
 	}
@@ -438,7 +459,7 @@ imap_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, Cam
 
 	/* If offline, search using the parent class, which can handle this manually */
 	if (CAMEL_OFFLINE_STORE (store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL)
-		return imap_search_parent_class->body_contains(f, argc, argv, s);
+		return CAMEL_FOLDER_SEARCH_CLASS (parent_class)->body_contains(f, argc, argv, s);
 
 	/* optimise the match "" case - match everything */
 	if (argc == 1 && argv[0]->value.string[0] == '\0') {
diff --git a/camel/providers/imap/camel-imap-search.h b/camel/providers/imap/camel-imap-search.h
index afe4e2b..26e8993 100644
--- a/camel/providers/imap/camel-imap-search.h
+++ b/camel/providers/imap/camel-imap-search.h
@@ -23,20 +23,33 @@
  *
  */
 
-#ifndef _CAMEL_IMAP_SEARCH_H
-#define _CAMEL_IMAP_SEARCH_H
+#ifndef CAMEL_IMAP_SEARCH_H
+#define CAMEL_IMAP_SEARCH_H
 
-#include <camel/camel-folder-search.h>
-#include <camel/camel-list-utils.h>
-#include <camel/camel-data-cache.h>
+#include <camel/camel.h>
 
-#define CAMEL_IMAP_SEARCH_TYPE         (camel_imap_search_get_type ())
-#define CAMEL_IMAP_SEARCH(obj)         CAMEL_CHECK_CAST (obj, camel_imap_search_get_type (), CamelImapSearch)
-#define CAMEL_IMAP_SEARCH_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_imap_search_get_type (), CamelImapSearchClass)
-#define CAMEL_IS_IMAP_SEARCH(obj)      CAMEL_CHECK_TYPE (obj, camel_imap_search_get_type ())
+/* Standard GObject class */
+#define CAMEL_TYPE_IMAP_SEARCH \
+	(camel_imap_search_get_type ())
+#define CAMEL_IMAP_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_SEARCH, CamelImapSearch))
+#define CAMEL_IMAP_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_SEARCH, CamelImapSearchClass))
+#define CAMEL_IS_IMAP_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_SEARCH))
+#define CAMEL_IS_IMAP_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_SEARCH))
+#define CAMEL_IMAP_SEARCH_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_SEARCH, CamelImapSearchClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelImapSearch CamelImapSearch;
 typedef struct _CamelImapSearchClass CamelImapSearchClass;
 
 struct _CamelImapSearch {
@@ -58,9 +71,9 @@ struct _CamelImapSearchClass {
 
 };
 
-CamelType              camel_imap_search_get_type (void);
+GType              camel_imap_search_get_type (void);
 CamelFolderSearch *camel_imap_search_new      (const gchar *cachedir);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_IMAP_SEARCH_H */
+#endif /* CAMEL_IMAP_SEARCH_H */
diff --git a/camel/providers/imap/camel-imap-store-summary.c b/camel/providers/imap/camel-imap-store-summary.c
index ac0c223..4f650cc 100644
--- a/camel/providers/imap/camel-imap-store-summary.c
+++ b/camel/providers/imap/camel-imap-store-summary.c
@@ -29,10 +29,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "camel-file-utils.h"
 #include "camel-private.h"
-#include "camel-store.h"
-#include "camel-utf8.h"
 
 #include "camel-imap-store-summary.h"
 
@@ -43,8 +40,6 @@
 
 #define CAMEL_IMAP_STORE_SUMMARY_VERSION (0)
 
-#define _PRIVATE(o) (((CamelImapStoreSummary *)(o))->priv)
-
 static gint summary_header_load(CamelStoreSummary *, FILE *);
 static gint summary_header_save(CamelStoreSummary *, FILE *);
 
@@ -56,65 +51,51 @@ static void		 store_info_free(CamelStoreSummary *, CamelStoreInfo *);
 static const gchar *store_info_string(CamelStoreSummary *, const CamelStoreInfo *, gint);
 static void store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int, const gchar *);
 
-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 CamelStoreSummaryClass *camel_imap_store_summary_parent;
+static gpointer parent_class;
 
 static void
-camel_imap_store_summary_class_init (CamelImapStoreSummaryClass *klass)
+imap_store_summary_class_init (CamelImapStoreSummaryClass *class)
 {
-	CamelStoreSummaryClass *ssklass = (CamelStoreSummaryClass *)klass;
-
-	ssklass->summary_header_load = summary_header_load;
-	ssklass->summary_header_save = summary_header_save;
-
-	/*ssklass->store_info_new  = store_info_new;*/
-	ssklass->store_info_load = store_info_load;
-	ssklass->store_info_save = store_info_save;
-	ssklass->store_info_free = store_info_free;
-
-	ssklass->store_info_string = store_info_string;
-	ssklass->store_info_set_string = store_info_set_string;
+	CamelStoreSummaryClass *store_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (class);
+	store_summary_class->summary_header_load = summary_header_load;
+	store_summary_class->summary_header_save = summary_header_save;
+	/*store_summary_class->store_info_new  = store_info_new;*/
+	store_summary_class->store_info_load = store_info_load;
+	store_summary_class->store_info_save = store_info_save;
+	store_summary_class->store_info_free = store_info_free;
+	store_summary_class->store_info_string = store_info_string;
+	store_summary_class->store_info_set_string = store_info_set_string;
 }
 
 static void
-camel_imap_store_summary_init (CamelImapStoreSummary *s)
+imap_store_summary_init (CamelImapStoreSummary *imap_store_summary)
 {
-	/*struct _CamelImapStoreSummaryPrivate *p;
-
-	  p = _PRIVATE(s) = g_malloc0(sizeof(*p));*/
+	CamelStoreSummary *store_summary;
 
-	((CamelStoreSummary *)s)->store_info_size = sizeof(CamelImapStoreInfo);
-	s->version = CAMEL_IMAP_STORE_SUMMARY_VERSION;
-}
-
-static void
-camel_imap_store_summary_finalise (CamelObject *obj)
-{
-	/*struct _CamelImapStoreSummaryPrivate *p;*/
-	/*CamelImapStoreSummary *s = (CamelImapStoreSummary *)obj;*/
+	store_summary = CAMEL_STORE_SUMMARY (imap_store_summary);
+	store_summary->store_info_size = sizeof (CamelImapStoreInfo);
 
-	/*p = _PRIVATE(obj);
-	  g_free(p);*/
+	imap_store_summary->version = CAMEL_IMAP_STORE_SUMMARY_VERSION;
 }
 
-CamelType
+GType
 camel_imap_store_summary_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		camel_imap_store_summary_parent = (CamelStoreSummaryClass *)camel_store_summary_get_type();
-		type = camel_type_register((CamelType)camel_imap_store_summary_parent, "CamelImapStoreSummary",
-					   sizeof (CamelImapStoreSummary),
-					   sizeof (CamelImapStoreSummaryClass),
-					   (CamelObjectClassInitFunc) camel_imap_store_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_imap_store_summary_init,
-					   (CamelObjectFinalizeFunc) camel_imap_store_summary_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE_SUMMARY,
+			"CamelImapStoreSummary",
+			sizeof (CamelImapStoreSummaryClass),
+			(GClassInitFunc) imap_store_summary_class_init,
+			sizeof (CamelImapStoreSummary),
+			(GInstanceInitFunc) imap_store_summary_init,
+			0);
 
 	return type;
 }
@@ -129,9 +110,7 @@ camel_imap_store_summary_get_type (void)
 CamelImapStoreSummary *
 camel_imap_store_summary_new (void)
 {
-	CamelImapStoreSummary *new = CAMEL_IMAP_STORE_SUMMARY ( camel_object_new (camel_imap_store_summary_get_type ()));
-
-	return new;
+	return g_object_new (CAMEL_TYPE_IMAP_STORE_SUMMARY, NULL);
 }
 
 /**
@@ -593,7 +572,7 @@ summary_header_load(CamelStoreSummary *s, FILE *in)
 
 	namespace_clear (is);
 
-	if (camel_imap_store_summary_parent->summary_header_load((CamelStoreSummary *)s, in) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->summary_header_load((CamelStoreSummary *)s, in) == -1
 	    || camel_file_util_decode_fixed_int32(in, &version) == -1)
 		return -1;
 
@@ -629,7 +608,7 @@ summary_header_save(CamelStoreSummary *s, FILE *out)
 	}
 
 	/* always write as latest version */
-	if (camel_imap_store_summary_parent->summary_header_save((CamelStoreSummary *)s, out) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->summary_header_save((CamelStoreSummary *)s, out) == -1
 	    || camel_file_util_encode_fixed_int32(out, CAMEL_IMAP_STORE_SUMMARY_VERSION) == -1
 	    || camel_file_util_encode_fixed_int32(out, is->capabilities) == -1
 	    || camel_file_util_encode_fixed_int32(out, count) == -1)
@@ -646,7 +625,7 @@ store_info_load(CamelStoreSummary *s, FILE *in)
 {
 	CamelImapStoreInfo *mi;
 
-	mi = (CamelImapStoreInfo *)camel_imap_store_summary_parent->store_info_load(s, in);
+	mi = (CamelImapStoreInfo *) CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_load(s, in);
 	if (mi) {
 		if (camel_file_util_decode_string(in, &mi->full_name) == -1) {
 			camel_store_summary_info_free(s, (CamelStoreInfo *)mi);
@@ -666,7 +645,7 @@ store_info_save(CamelStoreSummary *s, FILE *out, CamelStoreInfo *mi)
 {
 	CamelImapStoreInfo *isi = (CamelImapStoreInfo *)mi;
 
-	if (camel_imap_store_summary_parent->store_info_save(s, out, mi) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_save(s, out, mi) == -1
 	    || camel_file_util_encode_string(out, isi->full_name) == -1)
 		return -1;
 
@@ -679,7 +658,7 @@ store_info_free(CamelStoreSummary *s, CamelStoreInfo *mi)
 	CamelImapStoreInfo *isi = (CamelImapStoreInfo *)mi;
 
 	g_free(isi->full_name);
-	camel_imap_store_summary_parent->store_info_free(s, mi);
+	CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_free(s, mi);
 }
 
 static const gchar *
@@ -695,7 +674,7 @@ store_info_string(CamelStoreSummary *s, const CamelStoreInfo *mi, gint type)
 	case CAMEL_IMAP_STORE_INFO_FULL_NAME:
 		return isi->full_name;
 	default:
-		return camel_imap_store_summary_parent->store_info_string(s, mi, type);
+		return CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_string(s, mi, type);
 	}
 }
 
@@ -715,7 +694,7 @@ store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const
 		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
 		break;
 	default:
-		camel_imap_store_summary_parent->store_info_set_string(s, mi, type, str);
+		CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_set_string(s, mi, type, str);
 		break;
 	}
 }
diff --git a/camel/providers/imap/camel-imap-store-summary.h b/camel/providers/imap/camel-imap-store-summary.h
index fe5123a..039b34a 100644
--- a/camel/providers/imap/camel-imap-store-summary.h
+++ b/camel/providers/imap/camel-imap-store-summary.h
@@ -19,20 +19,35 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_IMAP_STORE_SUMMARY_H
-#define _CAMEL_IMAP_STORE_SUMMARY_H
-
-#include <camel/camel-object.h>
-#include <camel/camel-store-summary.h>
-
-#define CAMEL_IMAP_STORE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_imap_store_summary_get_type (), CamelImapStoreSummary)
-#define CAMEL_IMAP_STORE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_imap_store_summary_get_type (), CamelImapStoreSummaryClass)
-#define CAMEL_IS_IMAP_STORE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_imap_store_summary_get_type ())
+#ifndef CAMEL_IMAP_STORE_SUMMARY_H
+#define CAMEL_IMAP_STORE_SUMMARY_H
+
+#include <camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP_STORE_SUMMARY \
+	(camel_imap_store_summary_get_type ())
+#define CAMEL_IMAP_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_STORE_SUMMARY, CamelImapStoreSummary))
+#define CAMEL_IMAP_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_STORE_SUMMARY, CamelImapStoreSummaryClass))
+#define CAMEL_IS_IMAP_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_STORE_SUMMARY))
+#define CAMEL_IS_IMAP_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_STORE_SUMMARY))
+#define CAMEL_IMAP_STORE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_STORE_SUMMARY, CamelImapStoreSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelImapStoreSummary      CamelImapStoreSummary;
+typedef struct _CamelImapStoreSummary CamelImapStoreSummary;
 typedef struct _CamelImapStoreSummaryClass CamelImapStoreSummaryClass;
+typedef struct _CamelImapStoreSummaryPrivate CamelImapStoreSummaryPrivate;
 
 typedef struct _CamelImapStoreInfo CamelImapStoreInfo;
 
@@ -58,8 +73,7 @@ struct _CamelImapStoreNamespace {
 
 struct _CamelImapStoreSummary {
 	CamelStoreSummary summary;
-
-	struct _CamelImapStoreSummaryPrivate *priv;
+	CamelImapStoreSummaryPrivate *priv;
 
 	/* header info */
 	guint32 version;	/* version of base part of file */
@@ -71,7 +85,7 @@ struct _CamelImapStoreSummaryClass {
 	CamelStoreSummaryClass summary_class;
 };
 
-CamelType			 camel_imap_store_summary_get_type	(void);
+GType			 camel_imap_store_summary_get_type	(void);
 CamelImapStoreSummary      *camel_imap_store_summary_new	(void);
 
 void camel_imap_store_summary_namespace_set_main (CamelImapStoreSummary *s, const gchar *full_name, gchar dir_sep);
@@ -95,4 +109,4 @@ gchar *camel_imap_store_summary_full_from_path(CamelImapStoreSummary *s, const g
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_IMAP_STORE_SUMMARY_H */
+#endif /* CAMEL_IMAP_STORE_SUMMARY_H */
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index cba10a6..aa1b83a 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -32,28 +32,10 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "camel/camel-db.h"
-#include "camel/camel-debug.h"
-#include "camel/camel-exception.h"
-#include "camel/camel-file-utils.h"
-#include "camel/camel-folder.h"
-#include "camel/camel-net-utils.h"
-#include "camel/camel-private.h"
-#include "camel/camel-sasl.h"
-#include "camel/camel-session.h"
-#include "camel/camel-stream-buffer.h"
-#include "camel/camel-stream-fs.h"
-#include "camel/camel-stream-process.h"
-#include "camel/camel-stream.h"
-#include "camel/camel-string-utils.h"
-#include "camel/camel-tcp-stream-raw.h"
-#include "camel/camel-tcp-stream-ssl.h"
-#include "camel/camel-url.h"
-#include "camel/camel-utf8.h"
+#include "camel-private.h"
 
 #include "camel-imap-command.h"
 #include "camel-imap-folder.h"
@@ -77,7 +59,7 @@
 #define strtok_r(s,sep,lasts) (*(lasts)=strtok((s),(sep)))
 #endif
 
-static CamelOfflineStoreClass *parent_class = NULL;
+static gpointer parent_class;
 
 static gchar imap_tag_prefix = 'A';
 
@@ -121,45 +103,6 @@ static CamelFolderInfo * get_folder_info (CamelStore *store, const gchar *top, g
 static CamelFolder * get_folder_offline (CamelStore *store, const gchar *folder_name, guint32 flags, CamelException *ex);
 static CamelFolderInfo * get_folder_info_offline (CamelStore *store, const gchar *top, guint32 flags, CamelException *ex);
 
-static void
-camel_imap_store_class_init (CamelImapStoreClass *camel_imap_store_class)
-{
-	CamelObjectClass *camel_object_class =
-		CAMEL_OBJECT_CLASS (camel_imap_store_class);
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_imap_store_class);
-	CamelStoreClass *camel_store_class =
-		CAMEL_STORE_CLASS (camel_imap_store_class);
-
-	parent_class = CAMEL_OFFLINE_STORE_CLASS (camel_type_get_global_classfuncs (camel_offline_store_get_type ()));
-
-	/* virtual method overload */
-	camel_object_class->setv = imap_setv;
-	camel_object_class->getv = imap_getv;
-
-	camel_service_class->construct = construct;
-	camel_service_class->query_auth_types = query_auth_types;
-	camel_service_class->get_name = imap_get_name;
-	camel_service_class->connect = imap_connect;
-	camel_service_class->disconnect = imap_disconnect;
-
-	camel_store_class->hash_folder_name = hash_folder_name;
-	camel_store_class->compare_folder_name = compare_folder_name;
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->create_folder = create_folder;
-	camel_store_class->delete_folder = delete_folder;
-	camel_store_class->rename_folder = rename_folder;
-	camel_store_class->get_folder_info = get_folder_info;
-	camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-	camel_store_class->folder_subscribed = folder_subscribed;
-	camel_store_class->subscribe_folder = subscribe_folder;
-	camel_store_class->unsubscribe_folder = unsubscribe_folder;
-	camel_store_class->noop = imap_noop;
-	camel_store_class->get_trash = imap_get_trash;
-	camel_store_class->get_junk = imap_get_junk;
-	camel_store_class->can_refresh_folder = imap_can_refresh_folder;
-}
-
 static gboolean
 free_key (gpointer key, gpointer value, gpointer user_data)
 {
@@ -168,34 +111,84 @@ free_key (gpointer key, gpointer value, gpointer user_data)
 }
 
 static void
-camel_imap_store_finalize (CamelObject *object)
+imap_store_dispose (GObject *object)
 {
 	CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
 
-	/* This frees current_folder, folders, authtypes, streams, and namespace. */
-	camel_service_disconnect((CamelService *)imap_store, TRUE, NULL);
-
-	if (imap_store->summary) {
-		camel_store_summary_save((CamelStoreSummary *)imap_store->summary);
-		camel_object_unref(imap_store->summary);
+	if (imap_store->summary != NULL) {
+		camel_store_summary_save (
+			CAMEL_STORE_SUMMARY (imap_store->summary));
+		g_object_unref (imap_store->summary);
+		imap_store->summary = NULL;
 	}
 
-	if (imap_store->base_url)
-		g_free (imap_store->base_url);
-	if (imap_store->storage_path)
-		g_free (imap_store->storage_path);
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+imap_store_finalize (GObject *object)
+{
+	CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
 
-	g_free (imap_store->users_namespace);
-	imap_store->users_namespace = NULL;
+	/* This frees current_folder, folders, authtypes, streams, and namespace. */
+	camel_service_disconnect (CAMEL_SERVICE (imap_store), TRUE, NULL);
 
+	g_free (imap_store->base_url);
+	g_free (imap_store->storage_path);
 	g_free (imap_store->custom_headers);
+        g_free (imap_store->users_namespace);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_imap_store_init (gpointer object, gpointer klass)
+imap_store_class_init (CamelImapStoreClass *class)
 {
-	CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = imap_store_dispose;
+	object_class->finalize = imap_store_finalize;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->setv = imap_setv;
+	camel_object_class->getv = imap_getv;
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = construct;
+	service_class->query_auth_types = query_auth_types;
+	service_class->get_name = imap_get_name;
+	service_class->connect = imap_connect;
+	service_class->disconnect = imap_disconnect;
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->hash_folder_name = hash_folder_name;
+	store_class->compare_folder_name = compare_folder_name;
+	store_class->get_folder = get_folder;
+	store_class->create_folder = create_folder;
+	store_class->delete_folder = delete_folder;
+	store_class->rename_folder = rename_folder;
+	store_class->get_folder_info = get_folder_info;
+	store_class->free_folder_info = camel_store_free_folder_info_full;
+	store_class->folder_subscribed = folder_subscribed;
+	store_class->subscribe_folder = subscribe_folder;
+	store_class->unsubscribe_folder = unsubscribe_folder;
+	store_class->noop = imap_noop;
+	store_class->get_trash = imap_get_trash;
+	store_class->get_junk = imap_get_junk;
+	store_class->can_refresh_folder = imap_can_refresh_folder;
+}
 
+static void
+imap_store_init (CamelImapStore *imap_store)
+{
 	imap_store->istream = NULL;
 	imap_store->ostream = NULL;
 
@@ -211,24 +204,22 @@ camel_imap_store_init (gpointer object, gpointer klass)
 		imap_tag_prefix = 'A';
 }
 
-CamelType
+GType
 camel_imap_store_get_type (void)
 {
-	static CamelType camel_imap_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_imap_store_type == CAMEL_INVALID_TYPE)	{
-		camel_imap_store_type =
-			camel_type_register (camel_offline_store_get_type (),
-					     "CamelImapStore",
-					     sizeof (CamelImapStore),
-					     sizeof (CamelImapStoreClass),
-					     (CamelObjectClassInitFunc) camel_imap_store_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) camel_imap_store_init,
-					     (CamelObjectFinalizeFunc) camel_imap_store_finalize);
-	}
-
-	return camel_imap_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OFFLINE_STORE,
+			"CamelImapStore",
+			sizeof (CamelImapStoreClass),
+			(GClassInitFunc) imap_store_class_init,
+			sizeof (CamelImapStore),
+			(GInstanceInitFunc) imap_store_init,
+			0);
+
+	return type;
 }
 
 static void
@@ -582,7 +573,7 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 					      service->url->host,
 					      g_strerror (errno));
 
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 
 		return FALSE;
 	}
@@ -607,12 +598,12 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 	/* Read the greeting, if any, and deal with PREAUTH */
 	if (camel_imap_store_readline (store, &buf, ex) < 0) {
 		if (store->istream) {
-			camel_object_unref (store->istream);
+			g_object_unref (store->istream);
 			store->istream = NULL;
 		}
 
 		if (store->ostream) {
-			camel_object_unref (store->ostream);
+			g_object_unref (store->ostream);
 			store->ostream = NULL;
 		}
 
@@ -657,12 +648,12 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 	/* get the imap server capabilities */
 	if (!imap_get_capability (service, ex)) {
 		if (store->istream) {
-			camel_object_unref (store->istream);
+			g_object_unref (store->istream);
 			store->istream = NULL;
 		}
 
 		if (store->ostream) {
-			camel_object_unref (store->ostream);
+			g_object_unref (store->ostream);
 			store->ostream = NULL;
 		}
 
@@ -694,8 +685,8 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 
 	response = camel_imap_command (store, NULL, ex, "STARTTLS");
 	if (!response) {
-		camel_object_unref (store->istream);
-		camel_object_unref (store->ostream);
+		g_object_unref (store->istream);
+		g_object_unref (store->ostream);
 		store->istream = store->ostream = NULL;
 		return FALSE;
 	}
@@ -720,12 +711,12 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
            command, the client MUST discard prior CAPA responses */
 	if (!imap_get_capability (service, ex)) {
 		if (store->istream) {
-			camel_object_unref (store->istream);
+			g_object_unref (store->istream);
 			store->istream = NULL;
 		}
 
 		if (store->ostream) {
-			camel_object_unref (store->ostream);
+			g_object_unref (store->ostream);
 			store->ostream = NULL;
 		}
 
@@ -754,12 +745,12 @@ exception:
 	}
 
 	if (store->istream) {
-		camel_object_unref (store->istream);
+		g_object_unref (store->istream);
 		store->istream = NULL;
 	}
 
 	if (store->ostream) {
-		camel_object_unref (store->ostream);
+		g_object_unref (store->ostream);
 		store->ostream = NULL;
 	}
 
@@ -863,7 +854,7 @@ connect_to_server_process (CamelService *service, const gchar *cmd, CamelExcepti
 					      _("Could not connect with command \"%s\": %s"),
 					      full_cmd, g_strerror (errno));
 
-		camel_object_unref (cmd_stream);
+		g_object_unref (cmd_stream);
 		g_free (full_cmd);
 		return FALSE;
 	}
@@ -879,12 +870,12 @@ connect_to_server_process (CamelService *service, const gchar *cmd, CamelExcepti
 	/* Read the greeting, if any, and deal with PREAUTH */
 	if (camel_imap_store_readline (store, &buf, ex) < 0) {
 		if (store->istream) {
-			camel_object_unref (store->istream);
+			g_object_unref (store->istream);
 			store->istream = NULL;
 		}
 
 		if (store->ostream) {
-			camel_object_unref (store->ostream);
+			g_object_unref (store->ostream);
 			store->ostream = NULL;
 		}
 
@@ -899,12 +890,12 @@ connect_to_server_process (CamelService *service, const gchar *cmd, CamelExcepti
 	/* get the imap server capabilities */
 	if (!imap_get_capability (service, ex)) {
 		if (store->istream) {
-			camel_object_unref (store->istream);
+			g_object_unref (store->istream);
 			store->istream = NULL;
 		}
 
 		if (store->ostream) {
-			camel_object_unref (store->ostream);
+			g_object_unref (store->ostream);
 			store->ostream = NULL;
 		}
 
@@ -1190,13 +1181,13 @@ imap_store_refresh_folders (CamelImapStore *store, CamelException *ex)
 
 		/* NB: we can have vtrash folders also in our store ... bit hacky */
 		if (!CAMEL_IS_IMAP_FOLDER(folder)) {
-			camel_object_unref(folder);
+			g_object_unref (folder);
 			continue;
 		}
 
 		CAMEL_IMAP_FOLDER (folder)->need_rescan = TRUE;
 		if (!camel_exception_is_set(ex))
-			CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(folder))->refresh_info(folder, ex);
+			CAMEL_FOLDER_GET_CLASS (folder)->refresh_info (folder, ex);
 
 		if (camel_exception_is_set (ex) &&
 		    imap_check_folder_still_extant (store, folder->full_name, ex) == FALSE) {
@@ -1206,12 +1197,12 @@ imap_store_refresh_folders (CamelImapStore *store, CamelException *ex)
 			 * after being offline */
 
 			namedup = g_strdup (folder->full_name);
-			camel_object_unref(folder);
+			g_object_unref (folder);
 			imap_folder_effectively_unsubscribed (store, namedup, ex);
 			imap_forget_folder (store, namedup, ex);
 			g_free (namedup);
 		} else
-			camel_object_unref(folder);
+			g_object_unref (folder);
 	}
 
 	g_ptr_array_free (folders, TRUE);
@@ -1231,7 +1222,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;
@@ -1256,7 +1247,7 @@ try_auth (CamelImapStore *store, const gchar *mech, CamelException *ex)
 		goto lose;
 	}
 
-	camel_object_unref (sasl);
+	g_object_unref (sasl);
 
 	return TRUE;
 
@@ -1272,7 +1263,7 @@ try_auth (CamelImapStore *store, const gchar *mech, CamelException *ex)
 				     _("Bad authentication response from server."));
 	}
 
-	camel_object_unref (sasl);
+	g_object_unref (sasl);
 
 	return FALSE;
 }
@@ -1585,19 +1576,19 @@ imap_disconnect (CamelService *service, gboolean clean, CamelException *ex)
 
 	if (store->istream) {
 		camel_stream_close(store->istream);
-		camel_object_unref(store->istream);
+		g_object_unref (store->istream);
 		store->istream = NULL;
 	}
 
 	if (store->ostream) {
 		camel_stream_close(store->ostream);
-		camel_object_unref(store->ostream);
+		g_object_unref (store->ostream);
 		store->ostream = NULL;
 	}
 
 	store->connected = FALSE;
 	if (store->current_folder) {
-		camel_object_unref (store->current_folder);
+		g_object_unref (store->current_folder);
 		store->current_folder = NULL;
 	}
 
@@ -1650,7 +1641,7 @@ imap_noop (CamelStore *store, CamelException *ex)
 	current_folder = imap_store->current_folder;
 	if (current_folder && imap_summary_is_dirty (current_folder->summary)) {
 		/* let's sync the flags instead.  NB: must avoid folder lock */
-		((CamelFolderClass *)((CamelObject *)current_folder)->klass)->sync(current_folder, FALSE, ex);
+		CAMEL_FOLDER_GET_CLASS (current_folder)->sync (current_folder, FALSE, ex);
 	} else {
 		response = camel_imap_command (imap_store, NULL, ex, "NOOP");
 		if (response)
@@ -1857,7 +1848,7 @@ get_folder (CamelStore *store, const gchar *folder_name, guint32 flags, CamelExc
 		folder_name = "INBOX";
 
 	if (imap_store->current_folder) {
-		camel_object_unref (imap_store->current_folder);
+		g_object_unref (imap_store->current_folder);
 		imap_store->current_folder = NULL;
 	}
 
@@ -2024,15 +2015,15 @@ get_folder (CamelStore *store, const gchar *folder_name, guint32 flags, CamelExc
 		CamelException local_ex;
 
 		imap_store->current_folder = new_folder;
-		camel_object_ref (new_folder);
+		g_object_ref (new_folder);
 		camel_exception_init (&local_ex);
 		camel_imap_folder_selected (new_folder, response, &local_ex);
 
 		if (camel_exception_is_set (&local_ex)) {
 			camel_exception_xfer (ex, &local_ex);
-			camel_object_unref (imap_store->current_folder);
+			g_object_unref (imap_store->current_folder);
 			imap_store->current_folder = NULL;
-			camel_object_unref (new_folder);
+			g_object_unref (new_folder);
 			new_folder = NULL;
 		}
 	}
@@ -2098,7 +2089,7 @@ delete_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
 
 	camel_imap_response_free_without_processing (imap_store, response);
 	if (imap_store->current_folder)
-		camel_object_unref (imap_store->current_folder);
+		g_object_unref (imap_store->current_folder);
 	/* no need to actually create a CamelFolder for INBOX */
 	imap_store->current_folder = NULL;
 
@@ -2200,7 +2191,7 @@ rename_folder (CamelStore *store, const gchar *old_name, const gchar *new_name_i
 
 	camel_imap_response_free_without_processing (imap_store, response);
 	if (imap_store->current_folder)
-		camel_object_unref (imap_store->current_folder);
+		g_object_unref (imap_store->current_folder);
 	/* no need to actually create a CamelFolder for INBOX */
 	imap_store->current_folder = NULL;
 
@@ -2681,8 +2672,8 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 		fi->total = ((CamelFolderSummary *)ims)->saved_count;
 
 		if (!folder->summary)
-			camel_object_unref (ims);
-		camel_object_unref(folder);
+			g_object_unref (ims);
+		g_object_unref (folder);
 	}
 }
 
@@ -2715,7 +2706,7 @@ refresh_free(CamelSession *session, CamelSessionThreadMsg *msg)
 {
 	struct _refresh_msg *m = (struct _refresh_msg *)msg;
 
-	camel_object_unref(m->store);
+	g_object_unref (m->store);
 	camel_exception_clear(&m->ex);
 }
 
@@ -2762,7 +2753,7 @@ get_folder_info (CamelStore *store, const gchar *top, guint32 flags, CamelExcept
 
 				m = camel_session_thread_msg_new(((CamelService *)store)->session, &refresh_ops, sizeof(*m));
 				m->store = store;
-				camel_object_ref(store);
+				g_object_ref (store);
 				camel_exception_init(&m->ex);
 				camel_session_thread_queue(((CamelService *)store)->session, &m->msg, 0);
 			}
diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h
index 03d8da8..e24c244 100644
--- a/camel/providers/imap/camel-imap-store.h
+++ b/camel/providers/imap/camel-imap-store.h
@@ -22,17 +22,18 @@
  */
 
 #ifndef CAMEL_IMAP_STORE_H
-#define CAMEL_IMAP_STORE_H 1
+#define CAMEL_IMAP_STORE_H
 
-#include "camel-imap-types.h"
-#include <camel/camel-msgport.h>
-#include <camel/camel-offline-store.h>
 #include <sys/time.h>
-
-#ifdef ENABLE_THREADS
+#include <camel/camel.h>
 
 G_BEGIN_DECLS
 
+typedef struct _CamelImapStore CamelImapStore;
+typedef struct _CamelImapStoreClass CamelImapStoreClass;
+
+#ifdef ENABLE_THREADS
+
 typedef struct _CamelImapMsg CamelImapMsg;
 
 struct _CamelImapMsg {
@@ -47,14 +48,28 @@ CamelImapMsg *camel_imap_msg_new(void (*receive)(CamelImapStore *store, struct _
 				 gsize size);
 void camel_imap_msg_queue(CamelImapStore *store, CamelImapMsg *msg);
 
-G_END_DECLS
-
 #endif
 
-#define CAMEL_IMAP_STORE_TYPE     (camel_imap_store_get_type ())
-#define CAMEL_IMAP_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_STORE_TYPE, CamelImapStore))
-#define CAMEL_IMAP_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_IMAP_STORE_TYPE, CamelImapStoreClass))
-#define CAMEL_IS_IMAP_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_STORE_TYPE))
+G_END_DECLS
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP_STORE \
+	(camel_imap_store_get_type ())
+#define CAMEL_IMAP_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_STORE, CamelImapStore))
+#define CAMEL_IMAP_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_STORE, CamelImapStoreClass))
+#define CAMEL_IS_IMAP_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_STORE))
+#define CAMEL_IS_IMAP_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_STORE))
+#define CAMEL_IMAP_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_STORE, CamelImapStoreClass))
 
 G_BEGIN_DECLS
 
@@ -114,7 +129,7 @@ typedef enum {
 #define IMAP_FETCH_MINIMAL_HEADERS 3
 
 struct _CamelImapStore {
-	CamelOfflineStore parent_object;
+	CamelOfflineStore parent;
 
 	CamelStream *istream;
 	CamelStream *ostream;
@@ -147,13 +162,11 @@ struct _CamelImapStore {
 	gchar *custom_headers;
 };
 
-typedef struct {
+struct _CamelImapStoreClass {
 	CamelOfflineStoreClass parent_class;
+};
 
-} CamelImapStoreClass;
-
-/* Standard Camel function */
-CamelType camel_imap_store_get_type (void);
+GType camel_imap_store_get_type (void);
 
 gboolean camel_imap_store_connected (CamelImapStore *store, CamelException *ex);
 
diff --git a/camel/providers/imap/camel-imap-summary.c b/camel/providers/imap/camel-imap-summary.c
index a8c2328..efeeadf 100644
--- a/camel/providers/imap/camel-imap-summary.c
+++ b/camel/providers/imap/camel-imap-summary.c
@@ -31,12 +31,6 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include "camel-db.h"
-#include "camel-folder.h"
-#include "camel-file-utils.h"
-#include "camel-string-utils.h"
-#include "camel-store.h"
-
 #include "camel-imap-summary.h"
 #include "camel-imap-utils.h"
 
@@ -63,29 +57,7 @@ static CamelMessageInfo * message_info_from_db (CamelFolderSummary *s, CamelMIRe
 static gint content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelMIRecord *mir);
 static CamelMessageContentInfo * content_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir);
 
-static void camel_imap_summary_class_init (CamelImapSummaryClass *klass);
-static void camel_imap_summary_init       (CamelImapSummary *obj);
-
-static CamelFolderSummaryClass *camel_imap_summary_parent;
-
-CamelType
-camel_imap_summary_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(
-			camel_folder_summary_get_type(), "CamelImapSummary",
-			sizeof (CamelImapSummary),
-			sizeof (CamelImapSummaryClass),
-			(CamelObjectClassInitFunc) camel_imap_summary_class_init,
-			NULL,
-			(CamelObjectInitFunc) camel_imap_summary_init,
-			NULL);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static CamelMessageInfo *
 imap_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
@@ -93,7 +65,7 @@ imap_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
 	CamelImapMessageInfo *to;
 	const CamelImapMessageInfo *from = (const CamelImapMessageInfo *)mi;
 
-	to = (CamelImapMessageInfo *)camel_imap_summary_parent->message_info_clone(s, mi);
+	to = (CamelImapMessageInfo *) CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_clone(s, mi);
 	to->server_flags = from->server_flags;
 
 	/* FIXME: parent clone should do this */
@@ -103,39 +75,55 @@ imap_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
 }
 
 static void
-camel_imap_summary_class_init (CamelImapSummaryClass *klass)
+imap_summary_class_init (CamelImapSummaryClass *class)
 {
-	CamelFolderSummaryClass *cfs_class = (CamelFolderSummaryClass *) klass;
-
-	camel_imap_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS (camel_type_get_global_classfuncs (camel_folder_summary_get_type()));
-
-	cfs_class->message_info_clone = imap_message_info_clone;
-
-	cfs_class->summary_header_load = summary_header_load;
-	cfs_class->summary_header_save = summary_header_save;
-	cfs_class->message_info_load = message_info_load;
-	cfs_class->message_info_save = message_info_save;
-	cfs_class->content_info_load = content_info_load;
-	cfs_class->content_info_save = content_info_save;
-
-	cfs_class->summary_header_to_db = summary_header_to_db;
-	cfs_class->summary_header_from_db = summary_header_from_db;
-	cfs_class->message_info_to_db = message_info_to_db;
-	cfs_class->message_info_from_db = message_info_from_db;
-	cfs_class->content_info_to_db = content_info_to_db;
-	cfs_class->content_info_from_db = content_info_from_db;
-
-	cfs_class->info_set_user_flag = info_set_user_flag;
+	CamelFolderSummaryClass *folder_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->message_info_clone = imap_message_info_clone;
+	folder_summary_class->summary_header_load = summary_header_load;
+	folder_summary_class->summary_header_save = summary_header_save;
+	folder_summary_class->message_info_load = message_info_load;
+	folder_summary_class->message_info_save = message_info_save;
+	folder_summary_class->content_info_load = content_info_load;
+	folder_summary_class->content_info_save = content_info_save;
+	folder_summary_class->summary_header_to_db = summary_header_to_db;
+	folder_summary_class->summary_header_from_db = summary_header_from_db;
+	folder_summary_class->message_info_to_db = message_info_to_db;
+	folder_summary_class->message_info_from_db = message_info_from_db;
+	folder_summary_class->content_info_to_db = content_info_to_db;
+	folder_summary_class->content_info_from_db = content_info_from_db;
+	folder_summary_class->info_set_user_flag = info_set_user_flag;
 }
 
 static void
-camel_imap_summary_init (CamelImapSummary *obj)
+imap_summary_init (CamelImapSummary *imap_summary)
 {
-	CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (imap_summary);
 
 	/* subclasses need to set the right instance data sizes */
-	s->message_info_size = sizeof(CamelImapMessageInfo);
-	s->content_info_size = sizeof(CamelImapMessageContentInfo);
+	summary->message_info_size = sizeof (CamelImapMessageInfo);
+	summary->content_info_size = sizeof (CamelImapMessageContentInfo);
+}
+
+GType
+camel_imap_summary_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER_SUMMARY,
+			"CamelImapSummary",
+			sizeof (CamelImapSummaryClass),
+			(GClassInitFunc) imap_summary_class_init,
+			sizeof (CamelImapSummary),
+			(GInstanceInitFunc) imap_summary_init,
+			0);
+
+	return type;
 }
 
 static gint
@@ -191,10 +179,11 @@ uid_compare (gconstpointer va, gconstpointer vb)
 CamelFolderSummary *
 camel_imap_summary_new (struct _CamelFolder *folder, const gchar *filename)
 {
-	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (camel_object_new (camel_imap_summary_get_type ()));
+	CamelFolderSummary *summary;
 	CamelException ex;
 	camel_exception_init (&ex);
 
+	summary = g_object_new (CAMEL_TYPE_IMAP_SUMMARY, NULL);
 	summary->folder = folder;
 	/* Don't do DB sort. Its pretty slow to load */
 	if (folder && 0) {
@@ -226,7 +215,7 @@ summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir)
 	CamelImapSummary *ims = CAMEL_IMAP_SUMMARY (s);
 	gchar *part;
 
-	if (camel_imap_summary_parent->summary_header_from_db (s, mir) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_from_db (s, mir) == -1)
 		return -1;
 
 	part = mir->bdata;
@@ -253,7 +242,7 @@ summary_header_load (CamelFolderSummary *s, FILE *in)
 {
 	CamelImapSummary *ims = CAMEL_IMAP_SUMMARY (s);
 
-	if (camel_imap_summary_parent->summary_header_load (s, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (s, in) == -1)
 		return -1;
 
 	/* Legacy version */
@@ -290,7 +279,7 @@ summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 	CamelImapSummary *ims = CAMEL_IMAP_SUMMARY(s);
 	struct _CamelFIRecord *fir;
 
-	fir = camel_imap_summary_parent->summary_header_to_db (s, ex);
+	fir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_to_db (s, ex);
 	if (!fir)
 		return NULL;
 	fir->bdata = g_strdup_printf ("%d %u", CAMEL_IMAP_SUMMARY_VERSION, ims->validity);
@@ -303,7 +292,7 @@ summary_header_save (CamelFolderSummary *s, FILE *out)
 {
 	CamelImapSummary *ims = CAMEL_IMAP_SUMMARY(s);
 
-	if (camel_imap_summary_parent->summary_header_save (s, out) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_save (s, out) == -1)
 		return -1;
 
 	camel_file_util_encode_fixed_int32(out, CAMEL_IMAP_SUMMARY_VERSION);
@@ -317,7 +306,7 @@ message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
 	CamelMessageInfo *info;
 	CamelImapMessageInfo *iinfo;
 
-	info = camel_imap_summary_parent->message_info_from_db (s, mir);
+	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_from_db (s, mir);
 	if (info) {
 		gchar *part = g_strdup (mir->bdata), *tmp;
 		tmp = part;
@@ -335,7 +324,7 @@ message_info_load (CamelFolderSummary *s, FILE *in)
 	CamelMessageInfo *info;
 	CamelImapMessageInfo *iinfo;
 
-	info = camel_imap_summary_parent->message_info_load (s, in);
+	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load (s, in);
 	if (info) {
 		iinfo = (CamelImapMessageInfo *)info;
 
@@ -355,7 +344,7 @@ message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info)
 	CamelImapMessageInfo *iinfo = (CamelImapMessageInfo *)info;
 	struct _CamelMIRecord *mir;
 
-	mir = camel_imap_summary_parent->message_info_to_db (s, info);
+	mir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_to_db (s, info);
 	if (mir)
 		mir->bdata = g_strdup_printf ("%u", iinfo->server_flags);
 
@@ -367,7 +356,7 @@ message_info_save (CamelFolderSummary *s, FILE *out, CamelMessageInfo *info)
 {
 	CamelImapMessageInfo *iinfo = (CamelImapMessageInfo *)info;
 
-	if (camel_imap_summary_parent->message_info_save (s, out, info) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_save (s, out, info) == -1)
 		return -1;
 
 	return camel_file_util_encode_uint32 (out, iinfo->server_flags);
@@ -378,7 +367,7 @@ info_set_user_flag (CamelMessageInfo *info, const gchar *id, gboolean state)
 {
 	gboolean res;
 
-	res = camel_imap_summary_parent->info_set_user_flag (info, id, state);
+	res = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->info_set_user_flag (info, id, state);
 
 	/* there was a change, so do not forget to store it to server */
 	if (res)
@@ -402,7 +391,7 @@ content_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
 	}
 	mir->cinfo = part;
 	if (type)
-		return camel_imap_summary_parent->content_info_from_db (s, mir);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_from_db (s, mir);
 	else
 		return camel_folder_summary_content_info_new (s);
 }
@@ -411,7 +400,7 @@ static CamelMessageContentInfo *
 content_info_load (CamelFolderSummary *s, FILE *in)
 {
 	if (fgetc (in))
-		return camel_imap_summary_parent->content_info_load (s, in);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_load (s, in);
 	else
 		return camel_folder_summary_content_info_new (s);
 }
@@ -424,7 +413,7 @@ content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelM
 		oldr = mir->cinfo;
 		mir->cinfo = oldr ? g_strdup_printf("%s 1", oldr) : g_strdup ("1");
 		g_free(oldr);
-		return camel_imap_summary_parent->content_info_to_db (s, info, mir);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_to_db (s, info, mir);
 	} else {
 		oldr = mir->cinfo;
 		mir->cinfo = oldr ? g_strdup_printf("%s 0", oldr) : g_strdup ("0");
@@ -439,7 +428,7 @@ content_info_save (CamelFolderSummary *s, FILE *out,
 {
 	if (info->type) {
 		fputc (1, out);
-		return camel_imap_summary_parent->content_info_save (s, out, info);
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_save (s, out, info);
 	} else
 		return fputc (0, out);
 }
diff --git a/camel/providers/imap/camel-imap-summary.h b/camel/providers/imap/camel-imap-summary.h
index 4145435..d7eefb1 100644
--- a/camel/providers/imap/camel-imap-summary.h
+++ b/camel/providers/imap/camel-imap-summary.h
@@ -20,16 +20,29 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_IMAP_SUMMARY_H
-#define _CAMEL_IMAP_SUMMARY_H
-
-#include "camel-imap-types.h"
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-exception.h>
-
-#define CAMEL_IMAP_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_imap_summary_get_type (), CamelImapSummary)
-#define CAMEL_IMAP_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_imap_summary_get_type (), CamelImapSummaryClass)
-#define CAMEL_IS_IMAP_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_imap_summary_get_type ())
+#ifndef CAMEL_IMAP_SUMMARY_H
+#define CAMEL_IMAP_SUMMARY_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP_SUMMARY \
+	(camel_imap_summary_get_type ())
+#define CAMEL_IMAP_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_SUMMARY, CamelImapSummary))
+#define CAMEL_IMAP_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_SUMMARY, CamelImapSummaryClass))
+#define CAMEL_IS_IMAP_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_SUMMARY))
+#define CAMEL_IS_IMAP_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_SUMMARY))
+#define CAMEL_IMAP_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_SUMMARY, CamelImapSummaryClass))
 
 #define CAMEL_IMAP_SERVER_FLAGS (CAMEL_MESSAGE_ANSWERED | \
 				 CAMEL_MESSAGE_DELETED | \
@@ -43,6 +56,7 @@ enum {
 	CAMEL_IMAP_MESSAGE_RECENT = 1<<17
 };
 
+typedef struct _CamelImapSummary CamelImapSummary;
 typedef struct _CamelImapSummaryClass CamelImapSummaryClass;
 
 typedef struct _CamelImapMessageContentInfo {
@@ -68,7 +82,7 @@ struct _CamelImapSummaryClass {
 
 };
 
-CamelType               camel_imap_summary_get_type     (void);
+GType               camel_imap_summary_get_type     (void);
 CamelFolderSummary *camel_imap_summary_new          (struct _CamelFolder *folder, const gchar *filename);
 
 void camel_imap_summary_add_offline (CamelFolderSummary *summary,
@@ -82,4 +96,4 @@ void camel_imap_summary_add_offline_uncached (CamelFolderSummary *summary,
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_IMAP_SUMMARY_H */
+#endif /* CAMEL_IMAP_SUMMARY_H */
diff --git a/camel/providers/imap/camel-imap-types.h b/camel/providers/imap/camel-imap-types.h
index 9a5526f..48d8ee6 100644
--- a/camel/providers/imap/camel-imap-types.h
+++ b/camel/providers/imap/camel-imap-types.h
@@ -20,9 +20,9 @@
  */
 
 #ifndef CAMEL_IMAP_TYPES_H
-#define CAMEL_IMAP_TYPES_H 1
+#define CAMEL_IMAP_TYPES_H
 
-#include "camel-types.h"
+#include <glib.h>
 
 G_BEGIN_DECLS
 
diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c
index e6f6a3c..d6e6d5e 100644
--- a/camel/providers/imap/camel-imap-utils.c
+++ b/camel/providers/imap/camel-imap-utils.c
@@ -33,13 +33,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
-#include "camel-folder.h"
-#include "camel-string-utils.h"
-#include "camel-utf8.h"
-
 #include "camel-imap-store.h"
 #include "camel-imap-summary.h"
 #include "camel-imap-store-summary.h"
diff --git a/camel/providers/imap/camel-imap-utils.h b/camel/providers/imap/camel-imap-utils.h
index 70c8ca8..d81c205 100644
--- a/camel/providers/imap/camel-imap-utils.h
+++ b/camel/providers/imap/camel-imap-utils.h
@@ -21,12 +21,12 @@
  */
 
 #ifndef CAMEL_IMAP_UTILS_H
-#define CAMEL_IMAP_UTILS_H 1
+#define CAMEL_IMAP_UTILS_H
 
 #include <sys/types.h>
+#include <camel/camel.h>
 
-#include "camel-folder-summary.h"
-#include "camel-imap-types.h"
+#include "camel-imap-store.h"
 
 G_BEGIN_DECLS
 
diff --git a/camel/providers/imap/camel-imap-wrapper.c b/camel/providers/imap/camel-imap-wrapper.c
index a0d9b9b..5088db2 100644
--- a/camel/providers/imap/camel-imap-wrapper.c
+++ b/camel/providers/imap/camel-imap-wrapper.c
@@ -28,16 +28,13 @@
 #include <errno.h>
 #include <string.h>
 
-#include "camel-exception.h"
-#include "camel-mime-filter-basic.h"
-#include "camel-mime-filter-charset.h"
-#include "camel-mime-filter-crlf.h"
-#include "camel-mime-part.h"
-#include "camel-stream-filter.h"
-
 #include "camel-imap-folder.h"
 #include "camel-imap-wrapper.h"
 
+#define CAMEL_IMAP_WRAPPER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_IMAP_WRAPPER, CamelImapWrapperPrivate))
+
 struct _CamelImapWrapperPrivate {
 	GMutex *lock;
 };
@@ -45,67 +42,76 @@ struct _CamelImapWrapperPrivate {
 #define CAMEL_IMAP_WRAPPER_LOCK(f, l) (g_mutex_lock(((CamelImapWrapper *)f)->priv->l))
 #define CAMEL_IMAP_WRAPPER_UNLOCK(f, l) (g_mutex_unlock(((CamelImapWrapper *)f)->priv->l))
 
-static CamelDataWrapperClass *parent_class = NULL;
-
-/* Returns the class for a CamelDataWrapper */
-#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static gssize write_to_stream (CamelDataWrapper *imap_wrapper, CamelStream *stream);
 
 static void
-camel_imap_wrapper_class_init (CamelImapWrapperClass *camel_imap_wrapper_class)
+imap_wrapper_dispose (GObject *object)
 {
-	CamelDataWrapperClass *camel_data_wrapper_class =
-		CAMEL_DATA_WRAPPER_CLASS (camel_imap_wrapper_class);
+	CamelImapWrapper *imap_wrapper = CAMEL_IMAP_WRAPPER (object);
 
-	parent_class = CAMEL_DATA_WRAPPER_CLASS (camel_type_get_global_classfuncs (camel_data_wrapper_get_type ()));
+	if (imap_wrapper->folder != NULL) {
+		g_object_unref (imap_wrapper->folder);
+		imap_wrapper->folder = NULL;
+	}
 
-	/* virtual method override */
-	camel_data_wrapper_class->write_to_stream = write_to_stream;
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_imap_wrapper_finalize (CamelObject *object)
+imap_wrapper_finalize (GObject *object)
 {
 	CamelImapWrapper *imap_wrapper = CAMEL_IMAP_WRAPPER (object);
 
-	if (imap_wrapper->folder)
-		camel_object_unref (CAMEL_OBJECT (imap_wrapper->folder));
-	if (imap_wrapper->uid)
-		g_free (imap_wrapper->uid);
-	if (imap_wrapper->part)
-		g_free (imap_wrapper->part_spec);
+	g_free (imap_wrapper->uid);
+	g_free (imap_wrapper->part_spec);
 
 	g_mutex_free (imap_wrapper->priv->lock);
 
-	g_free (imap_wrapper->priv);
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_imap_wrapper_init (gpointer object, gpointer klass)
+imap_wrapper_class_init (CamelImapWrapperClass *class)
 {
-	CamelImapWrapper *imap_wrapper = CAMEL_IMAP_WRAPPER (object);
+	GObjectClass *object_class;
+	CamelDataWrapperClass *data_wrapper_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelImapWrapperPrivate));
 
-	imap_wrapper->priv = g_new0 (struct _CamelImapWrapperPrivate, 1);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = imap_wrapper_dispose;
+	object_class->finalize = imap_wrapper_finalize;
+
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->write_to_stream = write_to_stream;
+}
+
+static void
+imap_wrapper_init (CamelImapWrapper *imap_wrapper)
+{
+	imap_wrapper->priv = CAMEL_IMAP_WRAPPER_GET_PRIVATE (imap_wrapper);
 	imap_wrapper->priv->lock = g_mutex_new ();
 }
 
-CamelType
+GType
 camel_imap_wrapper_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (
-			CAMEL_DATA_WRAPPER_TYPE,
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_DATA_WRAPPER,
 			"CamelImapWrapper",
-			sizeof (CamelImapWrapper),
 			sizeof (CamelImapWrapperClass),
-			(CamelObjectClassInitFunc) camel_imap_wrapper_class_init,
-			NULL,
-			(CamelObjectInitFunc) camel_imap_wrapper_init,
-			(CamelObjectFinalizeFunc) camel_imap_wrapper_finalize);
-	}
+			(GClassInitFunc) imap_wrapper_class_init,
+			sizeof (CamelImapWrapper),
+			(GInstanceInitFunc) imap_wrapper_init,
+			0);
 
 	return type;
 }
@@ -115,11 +121,11 @@ imap_wrapper_hydrate (CamelImapWrapper *imap_wrapper, CamelStream *stream)
 {
 	CamelDataWrapper *data_wrapper = (CamelDataWrapper *) imap_wrapper;
 
-	camel_object_ref (stream);
+	g_object_ref (stream);
 	data_wrapper->stream = stream;
 	data_wrapper->offline = FALSE;
 
-	camel_object_unref (imap_wrapper->folder);
+	g_object_unref (imap_wrapper->folder);
 	imap_wrapper->folder = NULL;
 	g_free (imap_wrapper->uid);
 	imap_wrapper->uid = NULL;
@@ -151,11 +157,12 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
 		}
 
 		imap_wrapper_hydrate (imap_wrapper, datastream);
-		camel_object_unref (datastream);
+		g_object_unref (datastream);
 	}
 	CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
 
-	return parent_class->write_to_stream (data_wrapper, stream);
+	return CAMEL_DATA_WRAPPER_CLASS (parent_class)->
+		write_to_stream (data_wrapper, stream);
 }
 
 CamelDataWrapper *
@@ -167,14 +174,14 @@ camel_imap_wrapper_new (CamelImapFolder *imap_folder,
 	CamelImapWrapper *imap_wrapper;
 	CamelStream *stream;
 
-	imap_wrapper = (CamelImapWrapper *)camel_object_new(camel_imap_wrapper_get_type());
+	imap_wrapper = g_object_new (CAMEL_TYPE_IMAP_WRAPPER, NULL);
 
 	camel_data_wrapper_set_mime_type_field (CAMEL_DATA_WRAPPER (imap_wrapper), type);
 	((CamelDataWrapper *)imap_wrapper)->offline = TRUE;
 	((CamelDataWrapper *)imap_wrapper)->encoding = encoding;
 
 	imap_wrapper->folder = imap_folder;
-	camel_object_ref (imap_folder);
+	g_object_ref (imap_folder);
 	imap_wrapper->uid = g_strdup (uid);
 	imap_wrapper->part_spec = g_strdup (part_spec);
 
@@ -186,7 +193,7 @@ camel_imap_wrapper_new (CamelImapFolder *imap_folder,
 					       TRUE, NULL);
 	if (stream) {
 		imap_wrapper_hydrate (imap_wrapper, stream);
-		camel_object_unref (stream);
+		g_object_unref (stream);
 	}
 
 	return (CamelDataWrapper *)imap_wrapper;
diff --git a/camel/providers/imap/camel-imap-wrapper.h b/camel/providers/imap/camel-imap-wrapper.h
index c746243..df46207 100644
--- a/camel/providers/imap/camel-imap-wrapper.h
+++ b/camel/providers/imap/camel-imap-wrapper.h
@@ -20,23 +20,37 @@
  */
 
 #ifndef CAMEL_IMAP_WRAPPER_H
-#define CAMEL_IMAP_WRAPPER_H 1
+#define CAMEL_IMAP_WRAPPER_H
 
-#include <camel/camel-data-wrapper.h>
-#include "camel-imap-types.h"
+#include <camel/camel.h>
 
-#define CAMEL_IMAP_WRAPPER_TYPE     (camel_imap_wrapper_get_type ())
-#define CAMEL_IMAP_WRAPPER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_WRAPPER_TYPE, CamelImapWrapper))
-#define CAMEL_IMAP_WRAPPER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_IMAP_WRAPPER_TYPE, CamelImapWrapperClass))
-#define CAMEL_IS_IMAP_WRAPPER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_WRAPPER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP_WRAPPER \
+	(camel_imap_wrapper_get_type ())
+#define CAMEL_IMAP_WRAPPER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP_WRAPPER, CamelImapWrapper))
+#define CAMEL_IMAP_WRAPPER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP_WRAPPER, CamelImapWrapperClass))
+#define CAMEL_IS_IMAP_WRAPPER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP_WRAPPER))
+#define CAMEL_IS_IMAP_WRAPPER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP_WRAPPER))
+#define CAMEL_IMAP_WRAPPER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP_WRAPPER, CamelImapWrapperClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelImapWrapper CamelImapWrapper;
 typedef struct _CamelImapWrapperClass CamelImapWrapperClass;
 typedef struct _CamelImapWrapperPrivate CamelImapWrapperPrivate;
 
 struct _CamelImapWrapper {
-	CamelDataWrapper parent_object;
+	CamelDataWrapper parent;
 
 	CamelImapWrapperPrivate *priv;
 
@@ -49,8 +63,7 @@ struct _CamelImapWrapperClass {
 	CamelDataWrapperClass parent_class;
 };
 
-/* Standard Camel function */
-CamelType camel_imap_wrapper_get_type (void);
+GType camel_imap_wrapper_get_type (void);
 
 /* Constructor */
 CamelDataWrapper *camel_imap_wrapper_new (CamelImapFolder *imap_folder,
diff --git a/camel/providers/imap4/camel-imap4-command.c b/camel/providers/imap4/camel-imap4-command.c
index 6cdca40..7a233cd 100644
--- a/camel/providers/imap4/camel-imap4-command.c
+++ b/camel/providers/imap4/camel-imap4-command.c
@@ -29,11 +29,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-debug.h>
-#include <camel/camel-mime-filter-crlf.h>
-#include <camel/camel-stream-filter.h>
-#include <camel/camel-stream-null.h>
-
 #include "camel-imap4-command.h"
 #include "camel-imap4-engine.h"
 #include "camel-imap4-folder.h"
@@ -98,9 +93,9 @@ camel_imap4_literal_length (CamelIMAP4Literal *literal)
 
 	null = camel_stream_null_new ();
 	crlf = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
-	stream = (CamelStream *) camel_stream_filter_new_with_stream (null);
+	stream = camel_stream_filter_new (null);
 	camel_stream_filter_add ((CamelStreamFilter *) stream, crlf);
-	camel_object_unref (crlf);
+	g_object_unref (crlf);
 
 	switch (literal->type) {
 	case CAMEL_IMAP4_LITERAL_STREAM:
@@ -117,8 +112,8 @@ camel_imap4_literal_length (CamelIMAP4Literal *literal)
 
 	len = ((CamelStreamNull *) null)->written;
 
-	camel_object_unref (stream);
-	camel_object_unref (null);
+	g_object_unref (stream);
+	g_object_unref (null);
 
 	return len;
 }
@@ -267,7 +262,7 @@ camel_imap4_command_newv (CamelIMAP4Engine *engine, CamelIMAP4Folder *imap4_fold
 					g_assert_not_reached ();
 				}
 
-				camel_object_ref (obj);
+				g_object_ref (obj);
 
 				/* FIXME: take advantage of LITERAL+? */
 				len = camel_imap4_literal_length (literal);
@@ -352,7 +347,7 @@ camel_imap4_command_newv (CamelIMAP4Engine *engine, CamelIMAP4Folder *imap4_fold
 	ic->user_data = NULL;
 
 	if (imap4_folder) {
-		camel_object_ref (imap4_folder);
+		g_object_ref (imap4_folder);
 		ic->folder = imap4_folder;
 	} else
 		ic->folder = NULL;
@@ -397,7 +392,7 @@ camel_imap4_command_unref (CamelIMAP4Command *ic)
 	ic->ref_count--;
 	if (ic->ref_count == 0) {
 		if (ic->folder)
-			camel_object_unref (ic->folder);
+			g_object_unref (ic->folder);
 
 		g_free (ic->tag);
 
@@ -423,10 +418,10 @@ camel_imap4_command_unref (CamelIMAP4Command *ic)
 					g_free (part->literal->literal.string);
 					break;
 				case CAMEL_IMAP4_LITERAL_STREAM:
-					camel_object_unref (part->literal->literal.stream);
+					g_object_unref (part->literal->literal.stream);
 					break;
 				case CAMEL_IMAP4_LITERAL_WRAPPER:
-					camel_object_unref (part->literal->literal.wrapper);
+					g_object_unref (part->literal->literal.wrapper);
 					break;
 				}
 
@@ -459,9 +454,9 @@ imap4_literal_write_to_stream (CamelIMAP4Literal *literal, CamelStream *stream)
 	}
 
 	crlf = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
-	ostream = (CamelStream *) camel_stream_filter_new_with_stream (stream);
+	ostream = camel_stream_filter_new (stream);
 	camel_stream_filter_add ((CamelStreamFilter *) ostream, crlf);
-	camel_object_unref (crlf);
+	g_object_unref (crlf);
 
 	/* write the literal */
 	switch (literal->type) {
@@ -477,7 +472,7 @@ imap4_literal_write_to_stream (CamelIMAP4Literal *literal, CamelStream *stream)
 		break;
 	}
 
-	camel_object_unref (ostream);
+	g_object_unref (ostream);
 	ostream = NULL;
 
 #if 0
@@ -489,7 +484,7 @@ imap4_literal_write_to_stream (CamelIMAP4Literal *literal, CamelStream *stream)
 
  exception:
 
-	camel_object_unref (ostream);
+	g_object_unref (ostream);
 
 	return -1;
 }
diff --git a/camel/providers/imap4/camel-imap4-command.h b/camel/providers/imap4/camel-imap4-command.h
index e072f38..318dfb0 100644
--- a/camel/providers/imap4/camel-imap4-command.h
+++ b/camel/providers/imap4/camel-imap4-command.h
@@ -19,17 +19,11 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_COMMAND_H__
-#define __CAMEL_IMAP4_COMMAND_H__
+#ifndef CAMEL_IMAP4_COMMAND_H
+#define CAMEL_IMAP4_COMMAND_H
 
 #include <stdarg.h>
-
-#include <glib.h>
-
-#include <camel/camel-stream.h>
-#include <camel/camel-exception.h>
-#include <camel/camel-list-utils.h>
-#include <camel/camel-data-wrapper.h>
+#include <camel/camel.h>
 
 G_BEGIN_DECLS
 
@@ -139,4 +133,4 @@ void camel_imap4_command_reset (CamelIMAP4Command *ic);
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_COMMAND_H__ */
+#endif /* CAMEL_IMAP4_COMMAND_H */
diff --git a/camel/providers/imap4/camel-imap4-engine.c b/camel/providers/imap4/camel-imap4-engine.c
index ab04e8e..bda04e8 100644
--- a/camel/providers/imap4/camel-imap4-engine.c
+++ b/camel/providers/imap4/camel-imap4-engine.c
@@ -29,9 +29,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-sasl.h>
-#include <camel/camel-stream-buffer.h>
-
 #include "camel-imap4-command.h"
 #include "camel-imap4-engine.h"
 #include "camel-imap4-folder.h"
@@ -41,44 +38,44 @@
 
 #define d(x)
 
-static void camel_imap4_engine_class_init (CamelIMAP4EngineClass *klass);
-static void camel_imap4_engine_init (CamelIMAP4Engine *engine, CamelIMAP4EngineClass *klass);
-static void camel_imap4_engine_finalize (CamelObject *object);
+static void camel_imap4_engine_class_init (CamelIMAP4EngineClass *class);
+static void camel_imap4_engine_init (CamelIMAP4Engine *engine, CamelIMAP4EngineClass *class);
+static void imap4_engine_finalize (CamelObject *object);
 
 static gint parse_xgwextensions (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, guint32 index,
 				camel_imap4_token_t *token, CamelException *ex);
 
-static CamelObjectClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
+GType
 camel_imap4_engine_get_type (void)
 {
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (camel_object_get_type (),
-					    "CamelIMAP4Engine",
-					    sizeof (CamelIMAP4Engine),
-					    sizeof (CamelIMAP4EngineClass),
-					    (CamelObjectClassInitFunc) camel_imap4_engine_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_engine_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_engine_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_TYPE_OBJECT,
+			"CamelIMAP4Engine",
+			sizeof (CamelIMAP4Engine),
+			sizeof (CamelIMAP4EngineClass),
+			(GClassInitFunc) camel_imap4_engine_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_engine_init,
+			(GObjectFinalizeFunc) imap4_engine_finalize);
 
 	return type;
 }
 
 static void
-camel_imap4_engine_class_init (CamelIMAP4EngineClass *klass)
+camel_imap4_engine_class_init (CamelIMAP4EngineClass *class)
 {
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
+	parent_class = g_type_class_peek_parent (class);
 
-	klass->tagprefix = 'A';
+	class->tagprefix = 'A';
 }
 
 static void
-camel_imap4_engine_init (CamelIMAP4Engine *engine, CamelIMAP4EngineClass *klass)
+camel_imap4_engine_init (CamelIMAP4Engine *engine, CamelIMAP4EngineClass *class)
 {
 	engine->state = CAMEL_IMAP4_ENGINE_DISCONNECTED;
 	engine->level = CAMEL_IMAP4_LEVEL_UNKNOWN;
@@ -102,10 +99,10 @@ camel_imap4_engine_init (CamelIMAP4Engine *engine, CamelIMAP4EngineClass *klass)
 	engine->namespaces.other = NULL;
 	engine->namespaces.shared = NULL;
 
-	if (klass->tagprefix > 'Z')
-		klass->tagprefix = 'A';
+	if (class->tagprefix > 'Z')
+		class->tagprefix = 'A';
 
-	engine->tagprefix = klass->tagprefix++;
+	engine->tagprefix = class->tagprefix++;
 	engine->tag = 0;
 
 	engine->nextid = 1;
@@ -116,16 +113,16 @@ camel_imap4_engine_init (CamelIMAP4Engine *engine, CamelIMAP4EngineClass *klass)
 }
 
 static void
-camel_imap4_engine_finalize (CamelObject *object)
+imap4_engine_finalize (CamelObject *object)
 {
 	CamelIMAP4Engine *engine = (CamelIMAP4Engine *) object;
 	CamelDListNode *node;
 
 	if (engine->istream)
-		camel_object_unref (engine->istream);
+		g_object_unref (engine->istream);
 
 	if (engine->ostream)
-		camel_object_unref (engine->ostream);
+		g_object_unref (engine->ostream);
 
 	g_hash_table_foreach (engine->authtypes, (GHFunc) g_free, NULL);
 	g_hash_table_destroy (engine->authtypes);
@@ -135,7 +132,7 @@ camel_imap4_engine_finalize (CamelObject *object)
 	camel_imap4_namespace_clear (&engine->namespaces.shared);
 
 	if (engine->folder)
-		camel_object_unref (engine->folder);
+		g_object_unref (engine->folder);
 
 	while ((node = camel_dlist_remhead (&engine->queue))) {
 		node->next = NULL;
@@ -159,7 +156,7 @@ camel_imap4_engine_new (CamelService *service, CamelIMAP4ReconnectFunc reconnect
 
 	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
 
-	engine = (CamelIMAP4Engine *) camel_object_new (CAMEL_TYPE_IMAP4_ENGINE);
+	engine = g_object_new (CAMEL_TYPE_IMAP4_ENGINE, NULL);
 	engine->session = service->session;
 	engine->url = service->url;
 	engine->service = service;
@@ -191,15 +188,15 @@ camel_imap4_engine_take_stream (CamelIMAP4Engine *engine, CamelStream *stream, C
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 
 	if (engine->istream)
-		camel_object_unref (engine->istream);
+		g_object_unref (engine->istream);
 
 	if (engine->ostream)
-		camel_object_unref (engine->ostream);
+		g_object_unref (engine->ostream);
 
 	engine->istream = (CamelIMAP4Stream *) camel_imap4_stream_new (stream);
 	engine->ostream = camel_stream_buffer_new (stream, CAMEL_STREAM_BUFFER_WRITE);
 	engine->state = CAMEL_IMAP4_ENGINE_CONNECTED;
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	if (camel_imap4_engine_next_token (engine, &token, ex) == -1)
 		goto exception;
@@ -239,12 +236,12 @@ camel_imap4_engine_disconnect (CamelIMAP4Engine *engine)
 	engine->state = CAMEL_IMAP4_ENGINE_DISCONNECTED;
 
 	if (engine->istream) {
-		camel_object_unref (engine->istream);
+		g_object_unref (engine->istream);
 		engine->istream = NULL;
 	}
 
 	if (engine->ostream) {
-		camel_object_unref (engine->ostream);
+		g_object_unref (engine->ostream);
 		engine->ostream = NULL;
 	}
 }
@@ -1306,9 +1303,9 @@ engine_state_change (CamelIMAP4Engine *engine, CamelIMAP4Command *ic)
 	if (!strncmp (cmd, "SELECT ", 7) || !strncmp (cmd, "EXAMINE ", 8)) {
 		if (ic->result == CAMEL_IMAP4_RESULT_OK) {
 			/* Update the selected folder */
-			camel_object_ref (ic->folder);
+			g_object_ref (ic->folder);
 			if (engine->folder)
-				camel_object_unref (engine->folder);
+				g_object_unref (engine->folder);
 			engine->folder = ic->folder;
 
 			engine->state = CAMEL_IMAP4_ENGINE_SELECTED;
diff --git a/camel/providers/imap4/camel-imap4-engine.h b/camel/providers/imap4/camel-imap4-engine.h
index 9390720..01287a8 100644
--- a/camel/providers/imap4/camel-imap4-engine.h
+++ b/camel/providers/imap4/camel-imap4-engine.h
@@ -19,24 +19,30 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_ENGINE_H__
-#define __CAMEL_IMAP4_ENGINE_H__
+#ifndef CAMEL_IMAP4_ENGINE_H
+#define CAMEL_IMAP4_ENGINE_H
 
 #include <stdarg.h>
-
-#include <glib.h>
-
-#include <camel/camel-stream.h>
-#include <camel/camel-folder.h>
-#include <camel/camel-session.h>
-#include <camel/camel-list-utils.h>
-
-#define CAMEL_TYPE_IMAP4_ENGINE            (camel_imap4_engine_get_type ())
-#define CAMEL_IMAP4_ENGINE(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP4_ENGINE, CamelIMAP4Engine))
-#define CAMEL_IMAP4_ENGINE_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_IMAP4_ENGINE, CamelIMAP4EngineClass))
-#define CAMEL_IS_IMAP4_ENGINE(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_IMAP4_ENGINE))
-#define CAMEL_IS_IMAP4_ENGINE_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_IMAP4_ENGINE))
-#define CAMEL_IMAP4_ENGINE_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_IMAP4_ENGINE, CamelIMAP4EngineClass))
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_ENGINE \
+	(camel_imap4_engine_get_type ())
+#define CAMEL_IMAP4_ENGINE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_ENGINE, CamelIMAP4Engine))
+#define CAMEL_IMAP4_ENGINE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_ENGINE, CamelIMAP4EngineClass))
+#define CAMEL_IS_IMAP4_ENGINE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_ENGINE))
+#define CAMEL_IS_IMAP4_ENGINE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_ENGINE))
+#define CAMEL_IMAP4_ENGINE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP4_ENGINE, CamelIMAP4EngineClass))
 
 G_BEGIN_DECLS
 
@@ -152,7 +158,7 @@ enum {
 typedef gboolean (* CamelIMAP4ReconnectFunc) (CamelIMAP4Engine *engine, CamelException *ex);
 
 struct _CamelIMAP4Engine {
-	CamelObject parent_object;
+	CamelObject parent;
 
 	CamelIMAP4ReconnectFunc reconnect;
 	gboolean reconnecting;
@@ -190,7 +196,7 @@ struct _CamelIMAP4EngineClass {
 	guchar tagprefix;
 };
 
-CamelType camel_imap4_engine_get_type (void);
+GType camel_imap4_engine_get_type (void);
 
 CamelIMAP4Engine *camel_imap4_engine_new (CamelService *service, CamelIMAP4ReconnectFunc reconnect);
 
@@ -230,4 +236,4 @@ void camel_imap4_resp_code_free (CamelIMAP4RespCode *rcode);
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_ENGINE_H__ */
+#endif /* CAMEL_IMAP4_ENGINE_H */
diff --git a/camel/providers/imap4/camel-imap4-folder.c b/camel/providers/imap4/camel-imap4-folder.c
index ecfd31c..518268a 100644
--- a/camel/providers/imap4/camel-imap4-folder.c
+++ b/camel/providers/imap4/camel-imap4-folder.c
@@ -34,19 +34,10 @@
 #include <errno.h>
 #include <time.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include <libedataserver/e-data-server-util.h>
 
-#include <camel/camel-private.h>
-#include <camel/camel-file-utils.h>
-#include <camel/camel-stream-filter.h>
-#include <camel/camel-mime-filter-crlf.h>
-#include <camel/camel-mime-message.h>
-#include <camel/camel-stream-mem.h>
-#include <camel/camel-utf8.h>
-
 #include "camel-imap4-utils.h"
 #include "camel-imap4-store.h"
 #include "camel-imap4-engine.h"
@@ -59,9 +50,9 @@
 
 #define d(x)
 
-static void camel_imap4_folder_class_init (CamelIMAP4FolderClass *klass);
-static void camel_imap4_folder_init (CamelIMAP4Folder *folder, CamelIMAP4FolderClass *klass);
-static void camel_imap4_folder_finalize (CamelObject *object);
+static void camel_imap4_folder_class_init (CamelIMAP4FolderClass *class);
+static void camel_imap4_folder_init (CamelIMAP4Folder *folder, CamelIMAP4FolderClass *class);
+static void imap4_folder_finalize (CamelObject *object);
 
 static gint imap4_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
 static gint imap4_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
@@ -79,7 +70,7 @@ static GPtrArray *imap4_search_by_uids (CamelFolder *folder, const gchar *expr,
 static void imap4_search_free (CamelFolder *folder, GPtrArray *uids);
 static gchar * imap4_get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex);
 
-static CamelOfflineFolderClass *parent_class = NULL;
+static gpointer parent_class;
 
 static GSList *imap4_folder_props = NULL;
 
@@ -89,33 +80,33 @@ static CamelProperty imap4_prop_list[] = {
 	{ CAMEL_IMAP4_FOLDER_EXPIRE_AGE, "expire-age", N_("Expire cached messages older than X seconds") },
 };
 
-CamelType
+GType
 camel_imap4_folder_get_type (void)
 {
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (camel_offline_folder_get_type (),
-					    "CamelIMAP4Folder",
-					    sizeof (CamelIMAP4Folder),
-					    sizeof (CamelIMAP4FolderClass),
-					    (CamelObjectClassInitFunc) camel_imap4_folder_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_folder_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_folder_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_TYPE_OFFLINE_FOLDER,
+			"CamelIMAP4Folder",
+			sizeof (CamelIMAP4Folder),
+			sizeof (CamelIMAP4FolderClass),
+			(GClassInitFunc) camel_imap4_folder_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_folder_init,
+			(GObjectFinalizeFunc) imap4_folder_finalize);
 
 	return type;
 }
 
 static void
-camel_imap4_folder_class_init (CamelIMAP4FolderClass *klass)
+camel_imap4_folder_class_init (CamelIMAP4FolderClass *class)
 {
-	CamelFolderClass *folder_class = (CamelFolderClass *) klass;
-	CamelObjectClass *object_class = (CamelObjectClass *) klass;
+	CamelFolderClass *folder_class = (CamelFolderClass *) class;
+	CamelObjectClass *object_class = (CamelObjectClass *) class;
 	gint i;
 
-	parent_class = (CamelOfflineFolderClass *) camel_type_get_global_classfuncs (CAMEL_OFFLINE_FOLDER_TYPE);
+	parent_class = g_type_class_peek_parent (class);
 
 	if (imap4_folder_props == NULL) {
 		for (i = 0; i < G_N_ELEMENTS (imap4_prop_list); i++) {
@@ -140,7 +131,7 @@ camel_imap4_folder_class_init (CamelIMAP4FolderClass *klass)
 }
 
 static void
-camel_imap4_folder_init (CamelIMAP4Folder *folder, CamelIMAP4FolderClass *klass)
+camel_imap4_folder_init (CamelIMAP4Folder *folder, CamelIMAP4FolderClass *class)
 {
 	((CamelFolder *) folder)->folder_flags |= CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
 
@@ -151,17 +142,17 @@ camel_imap4_folder_init (CamelIMAP4Folder *folder, CamelIMAP4FolderClass *klass)
 }
 
 static void
-camel_imap4_folder_finalize (CamelObject *object)
+imap4_folder_finalize (CamelObject *object)
 {
 	CamelIMAP4Folder *folder = (CamelIMAP4Folder *) object;
 
-	camel_object_unref (folder->search);
+	g_object_unref (folder->search);
 
-	camel_object_unref (folder->cache);
+	g_object_unref (folder->cache);
 
 	if (folder->journal) {
 		camel_offline_journal_write (folder->journal, NULL);
-		camel_object_unref (folder->journal);
+		g_object_unref (folder->journal);
 	}
 
 	g_free (folder->utf7_name);
@@ -368,7 +359,7 @@ camel_imap4_folder_new (CamelStore *store, const gchar *full_name, CamelExceptio
 
 	utf7_name = camel_utf8_utf7 (utf7_name);
 
-	folder = (CamelFolder *) (imap4_folder = (CamelIMAP4Folder *) camel_object_new (CAMEL_TYPE_IMAP4_FOLDER));
+	folder = g_object_new (CAMEL_TYPE_IMAP4_FOLDER, NULL);
 	camel_folder_construct (folder, store, full_name, name);
 	imap4_folder->utf7_name = utf7_name;
 
@@ -376,7 +367,7 @@ camel_imap4_folder_new (CamelStore *store, const gchar *full_name, CamelExceptio
 	imap4_folder->cachedir = imap4_store_build_filename (store, folder->full_name);
 	g_mkdir_with_parents (imap4_folder->cachedir, 0777);
 
-	imap4_folder->cache = camel_data_cache_new (imap4_folder->cachedir, 0, NULL);
+	imap4_folder->cache = camel_data_cache_new (imap4_folder->cachedir, NULL);
 
 	path = imap4_get_summary_filename (imap4_folder->cachedir);
 	camel_folder_summary_set_filename (folder->summary, path);
@@ -412,12 +403,12 @@ camel_imap4_folder_new (CamelStore *store, const gchar *full_name, CamelExceptio
 		camel_folder_summary_load (folder->summary);
 
 		if (camel_imap4_engine_select_folder (((CamelIMAP4Store *) store)->engine, folder, ex) == -1) {
-			camel_object_unref (folder);
+			g_object_unref (folder);
 			folder = NULL;
 		}
 
 		if (folder && camel_imap4_summary_flush_updates (folder->summary, ex) == -1) {
-			camel_object_unref (folder);
+			g_object_unref (folder);
 			folder = NULL;
 		}
 	} else {
@@ -427,7 +418,7 @@ camel_imap4_folder_new (CamelStore *store, const gchar *full_name, CamelExceptio
 					      _("Cannot access folder '%s': %s"),
 					      full_name, g_strerror (ENOENT));
 
-			camel_object_unref (folder);
+			g_object_unref (folder);
 			folder = NULL;
 		}
 	}
@@ -738,14 +729,14 @@ untagged_fetch (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, guint32 index,
 			if (token->token != CAMEL_IMAP4_TOKEN_LITERAL)
 				goto unexpected;
 
-			fstream = (CamelStream *) camel_stream_filter_new_with_stream (stream);
+			fstream = camel_stream_filter_new (stream);
 			crlf = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_DECODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
 			camel_stream_filter_add ((CamelStreamFilter *) fstream, crlf);
-			camel_object_unref (crlf);
+			g_object_unref (crlf);
 
 			camel_stream_write_to_stream ((CamelStream *) engine->istream, fstream);
 			camel_stream_flush (fstream);
-			camel_object_unref (fstream);
+			g_object_unref (fstream);
 		} else if (!strcmp (token->v.atom, "UID")) {
 			if (camel_imap4_engine_next_token (engine, token, ex) == -1)
 				goto exception;
@@ -812,18 +803,18 @@ imap4_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 			if (errno == EINTR) {
 				CAMEL_SERVICE_REC_UNLOCK (folder->parent_store, connect_lock);
 				camel_exception_setv (ex, CAMEL_EXCEPTION_USER_CANCEL, _("User canceled"));
-				camel_object_unref (message);
-				camel_object_unref (stream);
+				g_object_unref (message);
+				g_object_unref (stream);
 				return NULL;
 			} else {
 				camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get message %s: %s"),
 						      uid, g_strerror (errno));
-				camel_object_unref (message);
+				g_object_unref (message);
 				message = NULL;
 			}
 		}
 
-		camel_object_unref (stream);
+		g_object_unref (stream);
 	}
 
 	if (message != NULL) {
@@ -865,7 +856,7 @@ imap4_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 	if (id == -1 || ic->status != CAMEL_IMAP4_COMMAND_COMPLETE) {
 		camel_exception_xfer (ex, &ic->ex);
 		camel_imap4_command_unref (ic);
-		camel_object_unref (stream);
+		g_object_unref (stream);
 		goto done;
 	}
 
@@ -881,7 +872,7 @@ imap4_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 			if (camel_stream_write_to_stream (stream, cache) == -1
 			    || camel_stream_flush (cache) == -1)
 				camel_data_cache_remove (imap4_folder->cache, "cache", uid, NULL);
-			camel_object_unref (cache);
+			g_object_unref (cache);
 		}
 
 		break;
@@ -900,7 +891,7 @@ imap4_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 
 	camel_imap4_command_unref (ic);
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
  done:
 
@@ -1139,7 +1130,7 @@ imap4_transfer_messages_to (CamelFolder *src, GPtrArray *uids, CamelFolder *dest
 				break;
 
 			camel_imap4_journal_append (journal, message, info, NULL, ex);
-			camel_object_unref (message);
+			g_object_unref (message);
 
 			if (camel_exception_is_set (ex))
 				break;
diff --git a/camel/providers/imap4/camel-imap4-folder.h b/camel/providers/imap4/camel-imap4-folder.h
index 8d1a614..abd0230 100644
--- a/camel/providers/imap4/camel-imap4-folder.h
+++ b/camel/providers/imap4/camel-imap4-folder.h
@@ -19,21 +19,29 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_FOLDER_H__
-#define __CAMEL_IMAP4_FOLDER_H__
-
-#include <camel/camel-store.h>
-#include <camel/camel-folder.h>
-#include <camel/camel-data-cache.h>
-#include <camel/camel-offline-folder.h>
-#include <camel/camel-offline-journal.h>
-
-#define CAMEL_TYPE_IMAP4_FOLDER            (camel_imap4_folder_get_type ())
-#define CAMEL_IMAP4_FOLDER(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP4_FOLDER, CamelIMAP4Folder))
-#define CAMEL_IMAP4_FOLDER_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_IMAP4_FOLDER, CamelIMAP4FolderClass))
-#define CAMEL_IS_IMAP4_FOLDER(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_IMAP4_FOLDER))
-#define CAMEL_IS_IMAP4_FOLDER_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_IMAP4_FOLDER))
-#define CAMEL_IMAP4_FOLDER_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_IMAP4_FOLDER, CamelIMAP4FolderClass))
+#ifndef CAMEL_IMAP4_FOLDER_H
+#define CAMEL_IMAP4_FOLDER_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_FOLDER \
+	(camel_imap4_folder_get_type ())
+#define CAMEL_IMAP4_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_FOLDER, CamelIMAP4Folder))
+#define CAMEL_IMAP4_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_FOLDER, CamelIMAP4FolderClass))
+#define CAMEL_IS_IMAP4_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_FOLDER))
+#define CAMEL_IS_IMAP4_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_FOLDER))
+#define CAMEL_IMAP4_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP4_FOLDER, CamelIMAP4FolderClass))
 
 G_BEGIN_DECLS
 
@@ -56,7 +64,7 @@ enum {
 };
 
 struct _CamelIMAP4Folder {
-	CamelOfflineFolder parent_object;
+	CamelOfflineFolder parent;
 
 	CamelFolderSearch *search;
 
@@ -75,7 +83,7 @@ struct _CamelIMAP4FolderClass {
 
 };
 
-CamelType camel_imap4_folder_get_type (void);
+GType camel_imap4_folder_get_type (void);
 
 CamelFolder *camel_imap4_folder_new (CamelStore *store, const gchar *full_name, CamelException *ex);
 
@@ -83,4 +91,4 @@ const gchar *camel_imap4_folder_utf7_name (CamelIMAP4Folder *folder);
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_FOLDER_H__ */
+#endif /* CAMEL_IMAP4_FOLDER_H */
diff --git a/camel/providers/imap4/camel-imap4-journal.c b/camel/providers/imap4/camel-imap4-journal.c
index 6985f8f..fdec918 100644
--- a/camel/providers/imap4/camel-imap4-journal.c
+++ b/camel/providers/imap4/camel-imap4-journal.c
@@ -34,52 +34,47 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-data-cache.h>
-#include <camel/camel-file-utils.h>
-#include <camel/camel-folder.h>
-
 #include "camel-imap4-folder.h"
 #include "camel-imap4-journal.h"
 
 #define d(x)
 
-static void camel_imap4_journal_class_init (CamelIMAP4JournalClass *klass);
-static void camel_imap4_journal_init (CamelIMAP4Journal *journal, CamelIMAP4JournalClass *klass);
-static void camel_imap4_journal_finalize (CamelObject *object);
+static void camel_imap4_journal_class_init (CamelIMAP4JournalClass *class);
+static void camel_imap4_journal_init (CamelIMAP4Journal *journal, CamelIMAP4JournalClass *class);
+static void imap4_journal_finalize (CamelObject *object);
 
 static void imap4_entry_free (CamelOfflineJournal *journal, CamelDListNode *entry);
 static CamelDListNode *imap4_entry_load (CamelOfflineJournal *journal, FILE *in);
 static gint imap4_entry_write (CamelOfflineJournal *journal, CamelDListNode *entry, FILE *out);
 static gint imap4_entry_play (CamelOfflineJournal *journal, CamelDListNode *entry, CamelException *ex);
 
-static CamelOfflineJournalClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
+GType
 camel_imap4_journal_get_type (void)
 {
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (camel_offline_journal_get_type (),
-					    "CamelIMAP4Journal",
-					    sizeof (CamelIMAP4Journal),
-					    sizeof (CamelIMAP4JournalClass),
-					    (CamelObjectClassInitFunc) camel_imap4_journal_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_journal_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_journal_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_TYPE_OFFLINE_JOURNAL,
+			"CamelIMAP4Journal",
+			sizeof (CamelIMAP4Journal),
+			sizeof (CamelIMAP4JournalClass),
+			(GClassInitFunc) camel_imap4_journal_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_journal_init,
+			(GObjectFinalizeFunc) imap4_journal_finalize);
 
 	return type;
 }
 
 static void
-camel_imap4_journal_class_init (CamelIMAP4JournalClass *klass)
+camel_imap4_journal_class_init (CamelIMAP4JournalClass *class)
 {
-	CamelOfflineJournalClass *journal_class = (CamelOfflineJournalClass *) klass;
+	CamelOfflineJournalClass *journal_class = (CamelOfflineJournalClass *) class;
 
-	parent_class = (CamelOfflineJournalClass *) camel_type_get_global_classfuncs (CAMEL_TYPE_OFFLINE_JOURNAL);
+	parent_class = g_type_class_peek_parent (class);
 
 	journal_class->entry_free = imap4_entry_free;
 	journal_class->entry_load = imap4_entry_load;
@@ -88,13 +83,13 @@ camel_imap4_journal_class_init (CamelIMAP4JournalClass *klass)
 }
 
 static void
-camel_imap4_journal_init (CamelIMAP4Journal *journal, CamelIMAP4JournalClass *klass)
+camel_imap4_journal_init (CamelIMAP4Journal *journal, CamelIMAP4JournalClass *class)
 {
 	journal->failed = g_ptr_array_new ();
 }
 
 static void
-camel_imap4_journal_finalize (CamelObject *object)
+imap4_journal_finalize (CamelObject *object)
 {
 	CamelIMAP4Journal *journal = (CamelIMAP4Journal *) object;
 	gint i;
@@ -201,12 +196,12 @@ imap4_entry_play_append (CamelOfflineJournal *journal, CamelIMAP4JournalEntry *e
 
 	message = camel_mime_message_new ();
 	if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream) == -1) {
-		camel_object_unref (message);
-		camel_object_unref (stream);
+		g_object_unref (message);
+		g_object_unref (stream);
 		goto done;
 	}
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	if (!(info = camel_folder_summary_uid (folder->summary, entry->v.append_uid))) {
 		/* info not in the summary, either because the summary
@@ -217,7 +212,7 @@ imap4_entry_play_append (CamelOfflineJournal *journal, CamelIMAP4JournalEntry *e
 
 	camel_exception_init (&lex);
 	camel_folder_append_message (folder, message, info, &uid, &lex);
-	camel_object_unref (message);
+	g_object_unref (message);
 
 	if (camel_exception_is_set (&lex)) {
 		/* Remove the message-info from the summary even if we fail or the next
@@ -275,7 +270,7 @@ camel_imap4_journal_new (CamelIMAP4Folder *folder, const gchar *filename)
 
 	g_return_val_if_fail (CAMEL_IS_IMAP4_FOLDER (folder), NULL);
 
-	journal = (CamelOfflineJournal *) camel_object_new (camel_imap4_journal_get_type ());
+	journal = g_object_new (CAMEL_TYPE_IMAP4_JOURNAL, NULL);
 	camel_offline_journal_construct (journal, (CamelFolder *) folder, filename);
 
 	return journal;
@@ -328,12 +323,12 @@ camel_imap4_journal_append (CamelIMAP4Journal *imap4_journal, CamelMimeMessage *
 				      g_strerror (errno));
 		camel_data_cache_remove (imap4_folder->cache, "cache", uid, NULL);
 		folder->summary->nextuid--;
-		camel_object_unref (cache);
+		g_object_unref (cache);
 		g_free (uid);
 		return;
 	}
 
-	camel_object_unref (cache);
+	g_object_unref (cache);
 
 	entry = g_new (CamelIMAP4JournalEntry, 1);
 	entry->type = CAMEL_IMAP4_JOURNAL_ENTRY_APPEND;
diff --git a/camel/providers/imap4/camel-imap4-journal.h b/camel/providers/imap4/camel-imap4-journal.h
index 3b204cf..80765bf 100644
--- a/camel/providers/imap4/camel-imap4-journal.h
+++ b/camel/providers/imap4/camel-imap4-journal.h
@@ -19,22 +19,30 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_JOURNAL_H__
-#define __CAMEL_IMAP4_JOURNAL_H__
+#ifndef CAMEL_IMAP4_JOURNAL_H
+#define CAMEL_IMAP4_JOURNAL_H
 
 #include <stdarg.h>
-
-#include <glib.h>
-
-#include <camel/camel-offline-journal.h>
-#include <camel/camel-mime-message.h>
-
-#define CAMEL_TYPE_IMAP4_JOURNAL            (camel_imap4_journal_get_type ())
-#define CAMEL_IMAP4_JOURNAL(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP4_JOURNAL, CamelIMAP4Journal))
-#define CAMEL_IMAP4_JOURNAL_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_IMAP4_JOURNAL, CamelIMAP4JournalClass))
-#define CAMEL_IS_IMAP4_JOURNAL(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_IMAP4_JOURNAL))
-#define CAMEL_IS_IMAP4_JOURNAL_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_IMAP4_JOURNAL))
-#define CAMEL_IMAP4_JOURNAL_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_IMAP4_JOURNAL, CamelIMAP4JournalClass))
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_JOURNAL \
+	(camel_imap4_journal_get_type ())
+#define CAMEL_IMAP4_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_JOURNAL, CamelIMAP4Journal))
+#define CAMEL_IMAP4_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_JOURNAL, CamelIMAP4JournalClass))
+#define CAMEL_IS_IMAP4_JOURNAL(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_JOURNAL))
+#define CAMEL_IS_IMAP4_JOURNAL_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_JOURNAL))
+#define CAMEL_IMAP4_JOURNAL_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP4_JOURNAL, CamelIMAP4JournalClass))
 
 G_BEGIN_DECLS
 
@@ -59,7 +67,7 @@ struct _CamelIMAP4JournalEntry {
 };
 
 struct _CamelIMAP4Journal {
-	CamelOfflineJournal parent_object;
+	CamelOfflineJournal parent;
 
 	GPtrArray *failed;
 };
@@ -69,7 +77,7 @@ struct _CamelIMAP4JournalClass {
 
 };
 
-CamelType camel_imap4_journal_get_type (void);
+GType camel_imap4_journal_get_type (void);
 
 CamelOfflineJournal *camel_imap4_journal_new (struct _CamelIMAP4Folder *folder, const gchar *filename);
 
@@ -81,4 +89,4 @@ void camel_imap4_journal_append (CamelIMAP4Journal *journal, CamelMimeMessage *m
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_JOURNAL_H__ */
+#endif /* CAMEL_IMAP4_JOURNAL_H */
diff --git a/camel/providers/imap4/camel-imap4-provider.c b/camel/providers/imap4/camel-imap4-provider.c
index 7c5f90c..f294aa0 100644
--- a/camel/providers/imap4/camel-imap4-provider.c
+++ b/camel/providers/imap4/camel-imap4-provider.c
@@ -27,9 +27,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-provider.h>
-#include <camel/camel-sasl.h>
-
 #include "camel-imap4-store.h"
 
 /* FIXME: Add options for cache expiration */
diff --git a/camel/providers/imap4/camel-imap4-search.c b/camel/providers/imap4/camel-imap4-search.c
index 2590cd5..7375cdc 100644
--- a/camel/providers/imap4/camel-imap4-search.c
+++ b/camel/providers/imap4/camel-imap4-search.c
@@ -27,59 +27,57 @@
 #include <string.h>
 #include <ctype.h>
 
-#include <camel/camel-offline-store.h>
-
 #include "camel-imap4-command.h"
 #include "camel-imap4-engine.h"
 #include "camel-imap4-search.h"
 #include "camel-imap4-stream.h"
 #include "camel-imap4-utils.h"
 
-static void camel_imap4_search_class_init (CamelIMAP4SearchClass *klass);
-static void camel_imap4_search_init (CamelIMAP4Search *search, CamelIMAP4SearchClass *klass);
-static void camel_imap4_search_finalize (CamelObject *object);
+static void camel_imap4_search_class_init (CamelIMAP4SearchClass *class);
+static void camel_imap4_search_init (CamelIMAP4Search *search, CamelIMAP4SearchClass *class);
+static void imap4_search_finalize (CamelObject *object);
 
 static ESExpResult *imap4_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
 
-static CamelFolderSearchClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
+GType
 camel_imap4_search_get_type (void)
 {
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (camel_folder_search_get_type (),
-					    "CamelIMAP4Search",
-					    sizeof (CamelIMAP4Search),
-					    sizeof (CamelIMAP4SearchClass),
-					    (CamelObjectClassInitFunc) camel_imap4_search_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_search_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_search_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_TYPE_FOLDER_SEARCH,
+			"CamelIMAP4Search",
+			sizeof (CamelIMAP4Search),
+			sizeof (CamelIMAP4SearchClass),
+			(GClassInitFunc) camel_imap4_search_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_search_init,
+			(GObjectFinalizeFunc) imap4_search_finalize);
 
 	return type;
 }
 
 static void
-camel_imap4_search_class_init (CamelIMAP4SearchClass *klass)
+camel_imap4_search_class_init (CamelIMAP4SearchClass *class)
 {
-	CamelFolderSearchClass *search_class = (CamelFolderSearchClass *) klass;
+	CamelFolderSearchClass *search_class = (CamelFolderSearchClass *) class;
 
-	parent_class = (CamelFolderSearchClass *) camel_type_get_global_classfuncs (CAMEL_FOLDER_SEARCH_TYPE);
+	parent_class = g_type_class_peek_parent (class);
 
 	search_class->body_contains = imap4_body_contains;
 }
 
 static void
-camel_imap4_search_init (CamelIMAP4Search *search, CamelIMAP4SearchClass *klass)
+camel_imap4_search_init (CamelIMAP4Search *search, CamelIMAP4SearchClass *class)
 {
 	search->engine = NULL;
 }
 
 static void
-camel_imap4_search_finalize (CamelObject *object)
+imap4_search_finalize (CamelObject *object)
 {
 	;
 }
@@ -89,7 +87,7 @@ camel_imap4_search_new (CamelIMAP4Engine *engine, const gchar *cachedir)
 {
 	CamelIMAP4Search *search;
 
-	search = (CamelIMAP4Search *) camel_object_new (camel_imap4_search_get_type ());
+	search = g_object_new (CAMEL_TYPE_IMAP4_SEARCH, NULL);
 	camel_folder_search_construct ((CamelFolderSearch *) search);
 	search->engine = engine;
 
diff --git a/camel/providers/imap4/camel-imap4-search.h b/camel/providers/imap4/camel-imap4-search.h
index 75f7e18..af3e385 100644
--- a/camel/providers/imap4/camel-imap4-search.h
+++ b/camel/providers/imap4/camel-imap4-search.h
@@ -20,17 +20,29 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_SEARCH_H__
-#define __CAMEL_IMAP4_SEARCH_H__
-
-#include <camel/camel-data-cache.h>
-#include <camel/camel-folder-search.h>
-#include <camel/camel-list-utils.h>
-
-#define CAMEL_IMAP4_SEARCH_TYPE         (camel_imap4_search_get_type ())
-#define CAMEL_IMAP4_SEARCH(obj)         CAMEL_CHECK_CAST (obj, camel_imap4_search_get_type (), CamelIMAP4Search)
-#define CAMEL_IMAP4_SEARCH_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_imap4_search_get_type (), CamelIMAP4SearchClass)
-#define CAMEL_IS_IMAP4_SEARCH(obj)      CAMEL_CHECK_TYPE (obj, camel_imap4_search_get_type ())
+#ifndef CAMEL_IMAP4_SEARCH_H
+#define CAMEL_IMAP4_SEARCH_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_SEARCH \
+	(camel_imap4_search_get_type ())
+#define CAMEL_IMAP4_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_SEARCH, CamelIMAP4Search))
+#define CAMEL_IMAP4_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_SEARCH, CamelIMAP4SearchClass))
+#define CAMEL_IS_IMAP4_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_SEARCH))
+#define CAMEL_IS_IMAP4_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_SEARCH))
+#define CAMEL_IMAP4_SEARCH_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP4_SEARCH, CamelIMAP4SearchClass))
 
 G_BEGIN_DECLS
 
@@ -40,7 +52,7 @@ typedef struct _CamelIMAP4SearchClass CamelIMAP4SearchClass;
 struct _CamelIMAP4Engine;
 
 struct _CamelIMAP4Search {
-	CamelFolderSearch parent_object;
+	CamelFolderSearch parent;
 
 	struct _CamelIMAP4Engine *engine;
 
@@ -60,10 +72,10 @@ struct _CamelIMAP4SearchClass {
 
 };
 
-CamelType camel_imap4_search_get_type (void);
+GType camel_imap4_search_get_type (void);
 
 CamelFolderSearch *camel_imap4_search_new (struct _CamelIMAP4Engine *engine, const gchar *cachedir);
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_SEARCH_H__ */
+#endif /* CAMEL_IMAP4_SEARCH_H */
diff --git a/camel/providers/imap4/camel-imap4-specials.h b/camel/providers/imap4/camel-imap4-specials.h
index 02e87ad..3672ca1 100644
--- a/camel/providers/imap4/camel-imap4-specials.h
+++ b/camel/providers/imap4/camel-imap4-specials.h
@@ -19,8 +19,8 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_SPECIALS_H__
-#define __CAMEL_IMAP4_SPECIALS_H__
+#ifndef CAMEL_IMAP4_SPECIALS_H
+#define CAMEL_IMAP4_SPECIALS_H
 
 #include <glib.h>
 
@@ -48,4 +48,4 @@ void camel_imap4_specials_init (void);
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_SPECIALS_H__ */
+#endif /* CAMEL_IMAP4_SPECIALS_H */
diff --git a/camel/providers/imap4/camel-imap4-store-summary.c b/camel/providers/imap4/camel-imap4-store-summary.c
index 00b12f0..d87c197 100644
--- a/camel/providers/imap4/camel-imap4-store-summary.c
+++ b/camel/providers/imap4/camel-imap4-store-summary.c
@@ -31,18 +31,15 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-file-utils.h>
-#include <camel/camel-store.h>
-
 #include "camel-imap4-store-summary.h"
 #include "camel-imap4-utils.h"
 
 #define CAMEL_IMAP4_STORE_SUMMARY_VERSION_0 (0)
 #define CAMEL_IMAP4_STORE_SUMMARY_VERSION (0)
 
-static void camel_imap4_store_summary_class_init (CamelIMAP4StoreSummaryClass *klass);
+static void camel_imap4_store_summary_class_init (CamelIMAP4StoreSummaryClass *class);
 static void camel_imap4_store_summary_init (CamelIMAP4StoreSummary *obj);
-static void camel_imap4_store_summary_finalize (CamelObject *obj);
+static void imap4_store_summary_finalize (CamelObject *obj);
 
 static gint summary_header_load (CamelStoreSummary *s, FILE *in);
 static gint summary_header_save (CamelStoreSummary *s, FILE *out);
@@ -51,40 +48,40 @@ static CamelStoreInfo *store_info_load (CamelStoreSummary *s, FILE *in);
 static gint store_info_save (CamelStoreSummary *s, FILE *out, CamelStoreInfo *info);
 static void store_info_free (CamelStoreSummary *s, CamelStoreInfo *info);
 
-static CamelStoreSummaryClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
+GType
 camel_imap4_store_summary_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_store_summary_get_type (),
-					    "CamelIMAP4StoreSummary",
-					    sizeof (CamelIMAP4StoreSummary),
-					    sizeof (CamelIMAP4StoreSummaryClass),
-					    (CamelObjectClassInitFunc) camel_imap4_store_summary_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_store_summary_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_store_summary_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_TYPE_STORE_SUMMARY,
+			"CamelIMAP4StoreSummary",
+			sizeof (CamelIMAP4StoreSummary),
+			sizeof (CamelIMAP4StoreSummaryClass),
+			(GClassInitFunc) camel_imap4_store_summary_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_store_summary_init,
+			(GObjectFinalizeFunc) imap4_store_summary_finalize);
 
 	return type;
 }
 
 static void
-camel_imap4_store_summary_class_init (CamelIMAP4StoreSummaryClass *klass)
+camel_imap4_store_summary_class_init (CamelIMAP4StoreSummaryClass *class)
 {
-	CamelStoreSummaryClass *ssklass = (CamelStoreSummaryClass *) klass;
+	CamelStoreSummaryClass *ssclass = (CamelStoreSummaryClass *) class;
 
-	parent_class = (CamelStoreSummaryClass *) camel_store_summary_get_type ();
+	parent_class = g_type_class_peek_parent (class);
 
-	ssklass->summary_header_load = summary_header_load;
-	ssklass->summary_header_save = summary_header_save;
+	ssclass->summary_header_load = summary_header_load;
+	ssclass->summary_header_save = summary_header_save;
 
-	ssklass->store_info_load = store_info_load;
-	ssklass->store_info_save = store_info_save;
-	ssklass->store_info_free = store_info_free;
+	ssclass->store_info_load = store_info_load;
+	ssclass->store_info_save = store_info_save;
+	ssclass->store_info_free = store_info_free;
 }
 
 static void
@@ -96,7 +93,7 @@ camel_imap4_store_summary_init (CamelIMAP4StoreSummary *s)
 }
 
 static void
-camel_imap4_store_summary_finalize (CamelObject *obj)
+imap4_store_summary_finalize (CamelObject *obj)
 {
 	CamelIMAP4StoreSummary *s = (CamelIMAP4StoreSummary *) obj;
 
@@ -279,7 +276,7 @@ store_info_free (CamelStoreSummary *s, CamelStoreInfo *info)
 CamelIMAP4StoreSummary *
 camel_imap4_store_summary_new (void)
 {
-	return (CamelIMAP4StoreSummary *) camel_object_new (camel_imap4_store_summary_get_type ());
+	return g_object_new (CAMEL_TYPE_IMAP4_STORE_SUMMARY, NULL);
 }
 
 void
@@ -352,7 +349,7 @@ store_info_to_folder_info (CamelStoreSummary *s, CamelStoreInfo *si)
 
 	name = camel_store_info_name (s, si);
 	if (!g_ascii_strcasecmp (fi->full_name, "INBOX")) {
-		fi->flags |= CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_INBOX;
+		fi->flags |= CAMEL_FOLDER_SYSTEM | CAMEL_TYPE_FOLDER_INBOX;
 		fi->name = g_strdup (_("Inbox"));
 	} else {
 		fi->name = g_strdup (name);
diff --git a/camel/providers/imap4/camel-imap4-store-summary.h b/camel/providers/imap4/camel-imap4-store-summary.h
index 21a32e5..5f04128 100644
--- a/camel/providers/imap4/camel-imap4-store-summary.h
+++ b/camel/providers/imap4/camel-imap4-store-summary.h
@@ -19,20 +19,37 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP_STORE_SUMMARY_H__
-#define __CAMEL_IMAP_STORE_SUMMARY_H__
+#ifndef CAMEL_IMAP_STORE_SUMMARY_H
+#define CAMEL_IMAP_STORE_SUMMARY_H
+
+#include <camel/camel.h>
 
-#include <camel/camel-store-summary.h>
 #include "camel-imap4-engine.h"
 
-#define CAMEL_IMAP4_STORE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_imap4_store_summary_get_type (), CamelIMAP4StoreSummary)
-#define CAMEL_IMAP4_STORE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_imap4_store_summary_get_type (), CamelIMAP4StoreSummaryClass)
-#define CAMEL_IS_IMAP4_STORE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_imap4_store_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_STORE_SUMMARY \
+	(camel_imap4_store_summary_get_type ())
+#define CAMEL_IMAP4_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_STORE_SUMMARY, CamelIMAP4StoreSummary))
+#define CAMEL_IMAP4_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_STORE_SUMMARY, CamelIMAP4StoreSummaryClass))
+#define CAMEL_IS_IMAP4_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_STORE_SUMMARY))
+#define CAMEL_IS_IMAP4_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_STORE_SUMMARY))
+#define CAMEL_IMAP4_STORE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP4_STORE_SUMMARY, CamelIMAP4StoreSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelIMAP4StoreSummary      CamelIMAP4StoreSummary;
+typedef struct _CamelIMAP4StoreSummary CamelIMAP4StoreSummary;
 typedef struct _CamelIMAP4StoreSummaryClass CamelIMAP4StoreSummaryClass;
+typedef struct _CamelIMAP4StoreSummaryPrivate CamelIMAP4StoreSummaryPrivate;
 
 typedef struct _CamelIMAP4StoreInfo CamelIMAP4StoreInfo;
 
@@ -49,8 +66,7 @@ struct _CamelIMAP4StoreInfo {
 
 struct _CamelIMAP4StoreSummary {
 	CamelStoreSummary summary;
-
-	struct _CamelIMAP4StoreSummaryPrivate *priv;
+	CamelIMAP4StoreSummaryPrivate *priv;
 
 	/* header info */
 	guint32 version;
@@ -63,7 +79,7 @@ struct _CamelIMAP4StoreSummaryClass {
 	CamelStoreSummaryClass summary_class;
 };
 
-CamelType camel_imap4_store_summary_get_type (void);
+GType camel_imap4_store_summary_get_type (void);
 
 CamelIMAP4StoreSummary *camel_imap4_store_summary_new (void);
 
@@ -79,4 +95,4 @@ struct _CamelFolderInfo *camel_imap4_store_summary_get_folder_info (CamelIMAP4St
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_STORE_SUMMARY_H__ */
+#endif /* CAMEL_IMAP4_STORE_SUMMARY_H */
diff --git a/camel/providers/imap4/camel-imap4-store.c b/camel/providers/imap4/camel-imap4-store.c
index d7f35e6..ecb04b9 100644
--- a/camel/providers/imap4/camel-imap4-store.c
+++ b/camel/providers/imap4/camel-imap4-store.c
@@ -30,16 +30,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-private.h>
-#include <camel/camel-net-utils.h>
-#include <camel/camel-tcp-stream-raw.h>
-#include <camel/camel-sasl.h>
-#include <camel/camel-utf8.h>
-
-#ifdef HAVE_SSL
-#include <camel/camel-tcp-stream-ssl.h>
-#endif
-
 #include "camel-imap4-command.h"
 #include "camel-imap4-engine.h"
 #include "camel-imap4-folder.h"
@@ -51,9 +41,9 @@
 
 #define d(x)
 
-static void camel_imap4_store_class_init (CamelIMAP4StoreClass *klass);
-static void camel_imap4_store_init (CamelIMAP4Store *store, CamelIMAP4StoreClass *klass);
-static void camel_imap4_store_finalize (CamelObject *object);
+static void camel_imap4_store_class_init (CamelIMAP4StoreClass *class);
+static void camel_imap4_store_init (CamelIMAP4Store *store, CamelIMAP4StoreClass *class);
+static void imap4_store_finalize (CamelObject *object);
 
 /* service methods */
 static void imap4_construct (CamelService *service, CamelSession *session,
@@ -77,23 +67,23 @@ static void imap4_unsubscribe_folder (CamelStore *store, const gchar *folder_nam
 static gboolean imap4_folder_subscribed (CamelStore *store, const gchar *folder_name);
 static void imap4_noop (CamelStore *store, CamelException *ex);
 
-static CamelOfflineStoreClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
+GType
 camel_imap4_store_get_type (void)
 {
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (camel_offline_store_get_type (),
-					    "CamelIMAP4Store",
-					    sizeof (CamelIMAP4Store),
-					    sizeof (CamelIMAP4StoreClass),
-					    (CamelObjectClassInitFunc) camel_imap4_store_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_store_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_store_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_TYPE_OFFLINE_STORE,
+			"CamelIMAP4Store",
+			sizeof (CamelIMAP4Store),
+			sizeof (CamelIMAP4StoreClass),
+			(GClassInitFunc) camel_imap4_store_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_store_init,
+			(GObjectFinalizeFunc) imap4_store_finalize);
 
 	return type;
 }
@@ -121,12 +111,12 @@ imap4_compare_folder_name (gconstpointer a, gconstpointer b)
 }
 
 static void
-camel_imap4_store_class_init (CamelIMAP4StoreClass *klass)
+camel_imap4_store_class_init (CamelIMAP4StoreClass *class)
 {
-	CamelServiceClass *service_class = (CamelServiceClass *) klass;
-	CamelStoreClass *store_class = (CamelStoreClass *) klass;
+	CamelServiceClass *service_class = (CamelServiceClass *) class;
+	CamelStoreClass *store_class = (CamelStoreClass *) class;
 
-	parent_class = (CamelOfflineStoreClass *) camel_type_get_global_classfuncs (CAMEL_TYPE_OFFLINE_STORE);
+	parent_class = g_type_class_peek_parent (class);
 
 	service_class->construct = imap4_construct;
 	service_class->get_name = imap4_get_name;
@@ -150,24 +140,24 @@ camel_imap4_store_class_init (CamelIMAP4StoreClass *klass)
 }
 
 static void
-camel_imap4_store_init (CamelIMAP4Store *store, CamelIMAP4StoreClass *klass)
+camel_imap4_store_init (CamelIMAP4Store *store, CamelIMAP4StoreClass *class)
 {
 	store->engine = NULL;
 	store->summary = NULL;
 }
 
 static void
-camel_imap4_store_finalize (CamelObject *object)
+imap4_store_finalize (CamelObject *object)
 {
 	CamelIMAP4Store *store = (CamelIMAP4Store *) object;
 
 	if (store->summary) {
 		camel_store_summary_save ((CamelStoreSummary *) store->summary);
-		camel_object_unref (store->summary);
+		g_object_unref (store->summary);
 	}
 
 	if (store->engine)
-		camel_object_unref (store->engine);
+		g_object_unref (store->engine);
 
 	g_free (store->storage_path);
 }
@@ -263,7 +253,7 @@ connect_to_server (CamelIMAP4Engine *engine, struct addrinfo *ai, gint ssl_mode,
 					      service->url->host,
 					      g_strerror (errno));
 
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 
 		return FALSE;
 	}
@@ -492,7 +482,7 @@ imap4_try_authenticate (CamelIMAP4Engine *engine, gboolean reprompt, const gchar
 		;
 
 	if (sasl != NULL)
-		camel_object_unref (sasl);
+		g_object_unref (sasl);
 
 	if (id == -1 || ic->status == CAMEL_IMAP4_COMMAND_ERROR) {
 		/* unrecoverable error */
@@ -1382,7 +1372,7 @@ imap4_build_folder_info (CamelStore *store, const gchar *top, guint32 flags, GPt
 		fi->total = -1;
 
 		if (!g_ascii_strcasecmp (fi->full_name, "INBOX"))
-			fi->flags |= CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_INBOX;
+			fi->flags |= CAMEL_FOLDER_SYSTEM | CAMEL_TYPE_FOLDER_INBOX;
 
 		/* SELECTED folder, just get it from the folder */
 		if (folder && !strcmp (folder->full_name, fi->full_name)) {
diff --git a/camel/providers/imap4/camel-imap4-store.h b/camel/providers/imap4/camel-imap4-store.h
index 3773574..cb6cd02 100644
--- a/camel/providers/imap4/camel-imap4-store.h
+++ b/camel/providers/imap4/camel-imap4-store.h
@@ -19,17 +19,29 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_STORE_H__
-#define __CAMEL_IMAP4_STORE_H__
+#ifndef CAMEL_IMAP4_STORE_H
+#define CAMEL_IMAP4_STORE_H
 
-#include <camel/camel-offline-store.h>
+#include <camel/camel.h>
 
-#define CAMEL_TYPE_IMAP4_STORE            (camel_imap4_store_get_type ())
-#define CAMEL_IMAP4_STORE(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP4_STORE, CamelIMAP4Store))
-#define CAMEL_IMAP4_STORE_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_IMAP4_STORE, CamelIMAP4StoreClass))
-#define CAMEL_IS_IMAP4_STORE(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_IMAP4_STORE))
-#define CAMEL_IS_IMAP4_STORE_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_IMAP4_STORE))
-#define CAMEL_IMAP4_STORE_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_IMAP4_STORE, CamelIMAP4StoreClass))
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_STORE \
+	(camel_imap4_store_get_type ())
+#define CAMEL_IMAP4_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_STORE, CamelIMAP4Store))
+#define CAMEL_IMAP4_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_STORE, CamelIMAP4StoreClass))
+#define CAMEL_IS_IMAP4_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_STORE))
+#define CAMEL_IS_IMAP4_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_STORE))
+#define CAMEL_IMAP4_STORE_GET_CLASS(obj) \
+	(CAMEL_CHECK_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP4_STORE, CamelIMAP4StoreClass))
 
 G_BEGIN_DECLS
 
@@ -39,7 +51,7 @@ typedef struct _CamelIMAP4StoreClass CamelIMAP4StoreClass;
 struct _CamelIMAP4Engine;
 
 struct _CamelIMAP4Store {
-	CamelOfflineStore parent_object;
+	CamelOfflineStore parent;
 
 	struct _CamelIMAP4StoreSummary *summary;
 	struct _CamelIMAP4Engine *engine;
@@ -48,11 +60,10 @@ struct _CamelIMAP4Store {
 
 struct _CamelIMAP4StoreClass {
 	CamelOfflineStoreClass parent_class;
-
 };
 
-CamelType camel_imap4_store_get_type (void);
+GType camel_imap4_store_get_type (void);
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_STORE_H__ */
+#endif /* CAMEL_IMAP4_STORE_H */
diff --git a/camel/providers/imap4/camel-imap4-stream.c b/camel/providers/imap4/camel-imap4-stream.c
index a460455..713ec7e 100644
--- a/camel/providers/imap4/camel-imap4-stream.c
+++ b/camel/providers/imap4/camel-imap4-stream.c
@@ -29,8 +29,6 @@
 #include <errno.h>
 #include <ctype.h>
 
-#include <camel/camel-debug.h>
-
 #include "camel-imap4-specials.h"
 #include "camel-imap4-stream.h"
 
@@ -38,9 +36,9 @@
 
 #define IMAP4_TOKEN_LEN  128
 
-static void camel_imap4_stream_class_init (CamelIMAP4StreamClass *klass);
-static void camel_imap4_stream_init (CamelIMAP4Stream *stream, CamelIMAP4StreamClass *klass);
-static void camel_imap4_stream_finalize (CamelObject *object);
+static void camel_imap4_stream_class_init (CamelIMAP4StreamClass *class);
+static void camel_imap4_stream_init (CamelIMAP4Stream *stream, CamelIMAP4StreamClass *class);
+static void imap4_stream_finalize (CamelObject *object);
 
 static gssize stream_read (CamelStream *stream, gchar *buffer, gsize n);
 static gssize stream_write (CamelStream *stream, const gchar *buffer, gsize n);
@@ -48,35 +46,34 @@ static gint stream_flush  (CamelStream *stream);
 static gint stream_close  (CamelStream *stream);
 static gboolean stream_eos (CamelStream *stream);
 
-static CamelStreamClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
+GType
 camel_imap4_stream_get_type (void)
 {
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (CAMEL_STREAM_TYPE,
-					    "CamelIMAP4Stream",
-					    sizeof (CamelIMAP4Stream),
-					    sizeof (CamelIMAP4StreamClass),
-					    (CamelObjectClassInitFunc) camel_imap4_stream_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_stream_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_stream_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_TYPE_STREAM,
+			"CamelIMAP4Stream",
+			sizeof (CamelIMAP4Stream),
+			sizeof (CamelIMAP4StreamClass),
+			(GClassInitFunc) camel_imap4_stream_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_stream_init,
+			(GObjectFinalizeFunc) imap4_stream_finalize);
 
 	return type;
 }
 
 static void
-camel_imap4_stream_class_init (CamelIMAP4StreamClass *klass)
+camel_imap4_stream_class_init (CamelIMAP4StreamClass *class)
 {
-	CamelStreamClass *stream_class = (CamelStreamClass *) klass;
+	CamelStreamClass *stream_class = (CamelStreamClass *) class;
 
-	parent_class = (CamelStreamClass *) camel_type_get_global_classfuncs (CAMEL_STREAM_TYPE);
+	parent_class = g_type_class_peek_parent (class);
 
-	/* virtual method overload */
 	stream_class->read = stream_read;
 	stream_class->write = stream_write;
 	stream_class->flush = stream_flush;
@@ -85,7 +82,7 @@ camel_imap4_stream_class_init (CamelIMAP4StreamClass *klass)
 }
 
 static void
-camel_imap4_stream_init (CamelIMAP4Stream *imap4, CamelIMAP4StreamClass *klass)
+camel_imap4_stream_init (CamelIMAP4Stream *imap4, CamelIMAP4StreamClass *class)
 {
 	imap4->stream = NULL;
 
@@ -106,12 +103,12 @@ camel_imap4_stream_init (CamelIMAP4Stream *imap4, CamelIMAP4StreamClass *klass)
 }
 
 static void
-camel_imap4_stream_finalize (CamelObject *object)
+imap4_stream_finalize (CamelObject *object)
 {
 	CamelIMAP4Stream *imap4 = (CamelIMAP4Stream *) object;
 
 	if (imap4->stream)
-		camel_object_unref (imap4->stream);
+		g_object_unref (imap4->stream);
 
 	g_free (imap4->tokenbuf);
 }
@@ -239,7 +236,7 @@ stream_close (CamelStream *stream)
 	if (camel_stream_close (imap4->stream) == -1)
 		return -1;
 
-	camel_object_unref (imap4->stream);
+	g_object_unref (imap4->stream);
 	imap4->stream = NULL;
 
 	imap4->disconnected = TRUE;
@@ -277,9 +274,8 @@ camel_imap4_stream_new (CamelStream *stream)
 
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), NULL);
 
-	imap4 = (CamelIMAP4Stream *) camel_object_new (CAMEL_TYPE_IMAP4_STREAM);
-	camel_object_ref (stream);
-	imap4->stream = stream;
+	imap4 = g_object_new (CAMEL_TYPE_IMAP4_STREAM, NULL);
+	imap4->stream = g_object_ref (stream);
 
 	return (CamelStream *) imap4;
 }
diff --git a/camel/providers/imap4/camel-imap4-stream.h b/camel/providers/imap4/camel-imap4-stream.h
index 350acca..4514cd5 100644
--- a/camel/providers/imap4/camel-imap4-stream.h
+++ b/camel/providers/imap4/camel-imap4-stream.h
@@ -19,15 +19,29 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_STREAM_H__
-#define __CAMEL_IMAP4_STREAM_H__
-
-#include <camel/camel-stream.h>
-
-#define CAMEL_TYPE_IMAP4_STREAM     (camel_imap4_stream_get_type ())
-#define CAMEL_IMAP4_STREAM(obj)     (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP4_STREAM, CamelIMAP4Stream))
-#define CAMEL_IMAP4_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TYPE_IMAP4_STREAM, CamelIMAP4StreamClass))
-#define CAMEL_IS_IMAP4_STREAM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TYPE_IMAP4_STREAM))
+#ifndef CAMEL_IMAP4_STREAM_H
+#define CAMEL_IMAP4_STREAM_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_STREAM \
+	(camel_imap4_stream_get_type ())
+#define CAMEL_IMAP4_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_STREAM, CamelIMAP4Stream))
+#define CAMEL_IMAP4_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_STREAM, CamelIMAP4StreamClass))
+#define CAMEL_IS_IMAP4_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_STREAM))
+#define CAMEL_IS_IMAP4_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_STREAM))
+#define CAMEL_IMAP4_STREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_IMAP4_STREAM, CamelIMAP4StreamClass))
 
 #define IMAP4_READ_PRELEN   128
 #define IMAP4_READ_BUFLEN   4096
@@ -73,7 +87,7 @@ enum {
 };
 
 struct _CamelIMAP4Stream {
-	CamelStream parent_object;
+	CamelStream parent;
 
 	CamelStream *stream;
 
@@ -104,8 +118,7 @@ struct _CamelIMAP4StreamClass {
 	/* Virtual methods */
 };
 
-/* Standard Camel function */
-CamelType camel_imap4_stream_get_type (void);
+GType camel_imap4_stream_get_type (void);
 
 CamelStream *camel_imap4_stream_new (CamelStream *stream);
 
@@ -117,4 +130,4 @@ gint camel_imap4_stream_literal (CamelIMAP4Stream *stream, guchar **literal, gsi
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_STREAM_H__ */
+#endif /* CAMEL_IMAP4_STREAM_H */
diff --git a/camel/providers/imap4/camel-imap4-summary.c b/camel/providers/imap4/camel-imap4-summary.c
index 9ab9202..5d9035f 100644
--- a/camel/providers/imap4/camel-imap4-summary.c
+++ b/camel/providers/imap4/camel-imap4-summary.c
@@ -38,10 +38,6 @@
 
 #include <libedataserver/md5-utils.h>
 
-#include <camel/camel-file-utils.h>
-#include <camel/camel-string-utils.h>
-#include <camel/camel-offline-journal.h>
-
 #include "camel-imap4-command.h"
 #include "camel-imap4-engine.h"
 #include "camel-imap4-folder.h"
@@ -57,9 +53,9 @@
 
 #define IMAP_SAVE_INCREMENT 1024
 
-static void camel_imap4_summary_class_init (CamelIMAP4SummaryClass *klass);
-static void camel_imap4_summary_init (CamelIMAP4Summary *summary, CamelIMAP4SummaryClass *klass);
-static void camel_imap4_summary_finalize (CamelObject *object);
+static void camel_imap4_summary_class_init (CamelIMAP4SummaryClass *class);
+static void camel_imap4_summary_init (CamelIMAP4Summary *summary, CamelIMAP4SummaryClass *class);
+static void imap4_summary_finalize (CamelObject *object);
 
 static gint imap4_header_load (CamelFolderSummary *summary, FILE *fin);
 static gint imap4_header_save (CamelFolderSummary *summary, FILE *fout);
@@ -70,33 +66,33 @@ static CamelMessageInfo *imap4_message_info_clone (CamelFolderSummary *summary,
 static CamelMessageContentInfo *imap4_content_info_load (CamelFolderSummary *summary, FILE *in);
 static gint imap4_content_info_save (CamelFolderSummary *summary, FILE *out, CamelMessageContentInfo *info);
 
-static CamelFolderSummaryClass *parent_class = NULL;
+static gpointer parent_class;
 
-CamelType
+GType
 camel_imap4_summary_get_type (void)
 {
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (CAMEL_FOLDER_SUMMARY_TYPE,
-					    "CamelIMAP4Summary",
-					    sizeof (CamelIMAP4Summary),
-					    sizeof (CamelIMAP4SummaryClass),
-					    (CamelObjectClassInitFunc) camel_imap4_summary_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_imap4_summary_init,
-					    (CamelObjectFinalizeFunc) camel_imap4_summary_finalize);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = camel_type_register (
+			CAMEL_FOLDER_SUMMARY_TYPE,
+			"CamelIMAP4Summary",
+			sizeof (CamelIMAP4Summary),
+			sizeof (CamelIMAP4SummaryClass),
+			(GClassInitFunc) camel_imap4_summary_class_init,
+			NULL,
+			(GInstanceInitFunc) camel_imap4_summary_init,
+			(GObjectFinalizeFunc) imap4_summary_finalize);
 
 	return type;
 }
 
 static void
-camel_imap4_summary_class_init (CamelIMAP4SummaryClass *klass)
+camel_imap4_summary_class_init (CamelIMAP4SummaryClass *class)
 {
-	CamelFolderSummaryClass *summary_class = (CamelFolderSummaryClass *) klass;
+	CamelFolderSummaryClass *summary_class = (CamelFolderSummaryClass *) class;
 
-	parent_class = (CamelFolderSummaryClass *) camel_type_get_global_classfuncs (camel_folder_summary_get_type ());
+	parent_class = g_type_class_peek_parent (class);
 
 	summary_class->summary_header_load = imap4_header_load;
 	summary_class->summary_header_save = imap4_header_save;
@@ -109,7 +105,7 @@ camel_imap4_summary_class_init (CamelIMAP4SummaryClass *klass)
 }
 
 static void
-camel_imap4_summary_init (CamelIMAP4Summary *summary, CamelIMAP4SummaryClass *klass)
+camel_imap4_summary_init (CamelIMAP4Summary *summary, CamelIMAP4SummaryClass *class)
 {
 	CamelFolderSummary *folder_summary = (CamelFolderSummary *) summary;
 
@@ -124,7 +120,7 @@ camel_imap4_summary_init (CamelIMAP4Summary *summary, CamelIMAP4SummaryClass *kl
 }
 
 static void
-camel_imap4_summary_finalize (CamelObject *object)
+imap4_summary_finalize (CamelObject *object)
 {
 }
 
@@ -133,7 +129,7 @@ camel_imap4_summary_new (CamelFolder *folder)
 {
 	CamelFolderSummary *summary;
 
-	summary = (CamelFolderSummary *) camel_object_new (CAMEL_TYPE_IMAP4_SUMMARY);
+	summary = g_object_new (CAMEL_TYPE_IMAP4_SUMMARY, NULL);
 	summary->folder = folder;
 
 	return summary;
@@ -1098,7 +1094,7 @@ untagged_fetch_all (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, guint32 ind
 				goto unexpected;
 
 			parser = camel_mime_parser_new ();
-			camel_mime_parser_init_with_stream (parser, (CamelStream *) engine->istream);
+			mime_parser_init_with_stream (parser, (CamelStream *) engine->istream);
 
 			switch (camel_mime_parser_step (parser, NULL, NULL)) {
 			case CAMEL_MIME_PARSER_STATE_HEADER:
@@ -1129,7 +1125,7 @@ untagged_fetch_all (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, guint32 ind
 				break;
 			}
 
-			camel_object_unref (parser);
+			g_object_unref (parser);
 		} else {
 			/* wtf? */
 			d(fprintf (stderr, "huh? %s?...\n", token->v.atom));
diff --git a/camel/providers/imap4/camel-imap4-summary.h b/camel/providers/imap4/camel-imap4-summary.h
index 6514557..ed40485 100644
--- a/camel/providers/imap4/camel-imap4-summary.h
+++ b/camel/providers/imap4/camel-imap4-summary.h
@@ -19,20 +19,30 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_SUMMARY_H__
-#define __CAMEL_IMAP4_SUMMARY_H__
+#ifndef CAMEL_IMAP4_SUMMARY_H
+#define CAMEL_IMAP4_SUMMARY_H
 
 #include <sys/types.h>
-
-#include <camel/camel-folder.h>
-#include <camel/camel-folder-summary.h>
-
-#define CAMEL_TYPE_IMAP4_SUMMARY            (camel_imap4_summary_get_type ())
-#define CAMEL_IMAP4_SUMMARY(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_IMAP4_SUMMARY, CamelIMAP4Summary))
-#define CAMEL_IMAP4_SUMMARY_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_IMAP4_SUMMARY, CamelIMAP4SummaryClass))
-#define CAMEL_IS_IMAP4_SUMMARY(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_IMAP4_SUMMARY))
-#define CAMEL_IS_IMAP4_SUMMARY_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_IMAP4_SUMMARY))
-#define CAMEL_IMAP4_SUMMARY_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_FOLDER_SUMMARY, CamelIMAP4SummaryClass))
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_IMAP4_SUMMARY \
+	(camel_imap4_summary_get_type ())
+#define CAMEL_IMAP4_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_IMAP4_SUMMARY, CamelIMAP4Summary))
+#define CAMEL_IMAP4_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_IMAP4_SUMMARY, CamelIMAP4SummaryClass))
+#define CAMEL_IS_IMAP4_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_IMAP4_SUMMARY))
+#define CAMEL_IS_IMAP4_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_IMAP4_SUMMARY))
+#define CAMEL_IMAP4_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_FOLDER_SUMMARY, CamelIMAP4SummaryClass))
 
 G_BEGIN_DECLS
 
@@ -60,7 +70,7 @@ struct _CamelIMAP4MessageContentInfo {
 };
 
 struct _CamelIMAP4Summary {
-	CamelFolderSummary parent_object;
+	CamelFolderSummary parent;
 
 	guint32 version;
 
@@ -79,7 +89,7 @@ struct _CamelIMAP4SummaryClass {
 
 };
 
-CamelType camel_imap4_summary_get_type (void);
+GType camel_imap4_summary_get_type (void);
 
 CamelFolderSummary *camel_imap4_summary_new (CamelFolder *folder);
 
@@ -96,4 +106,4 @@ gint camel_imap4_summary_flush_updates (CamelFolderSummary *summary, CamelExcept
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_SUMMARY_H__ */
+#endif /* CAMEL_IMAP4_SUMMARY_H */
diff --git a/camel/providers/imap4/camel-imap4-utils.c b/camel/providers/imap4/camel-imap4-utils.c
index c668115..5669e66 100644
--- a/camel/providers/imap4/camel-imap4-utils.c
+++ b/camel/providers/imap4/camel-imap4-utils.c
@@ -30,9 +30,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <camel/camel-net-utils.h>
-#include <camel/camel-store.h>
-
 #include "camel-imap4-command.h"
 #include "camel-imap4-engine.h"
 #include "camel-imap4-store-summary.h"
diff --git a/camel/providers/imap4/camel-imap4-utils.h b/camel/providers/imap4/camel-imap4-utils.h
index 5f44951..41bfea5 100644
--- a/camel/providers/imap4/camel-imap4-utils.h
+++ b/camel/providers/imap4/camel-imap4-utils.h
@@ -19,12 +19,10 @@
  *  Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef __CAMEL_IMAP4_UTILS_H__
-#define __CAMEL_IMAP4_UTILS_H__
+#ifndef CAMEL_IMAP4_UTILS_H
+#define CAMEL_IMAP4_UTILS_H
 
-#include <glib.h>
-
-#include <camel/camel-exception.h>
+#include <camel/camel.h>
 
 G_BEGIN_DECLS
 
@@ -101,4 +99,4 @@ gint camel_imap4_untagged_status (struct _CamelIMAP4Engine *engine, struct _Came
 
 G_END_DECLS
 
-#endif /* __CAMEL_IMAP4_UTILS_H__ */
+#endif /* CAMEL_IMAP4_UTILS_H */
diff --git a/camel/providers/imapx/camel-imapx-exception.h b/camel/providers/imapx/camel-imapx-exception.h
index a27183f..dcaff91 100644
--- a/camel/providers/imapx/camel-imapx-exception.h
+++ b/camel/providers/imapx/camel-imapx-exception.h
@@ -7,7 +7,7 @@
 #define __CAMEL_IMAPX_EXCEPTION_H
 
 #include <setjmp.h>
-#include "camel/camel-exception.h"
+#include <camel/camel.h>
 
 struct _CamelExceptionEnv {
 	struct _CamelExceptionEnv *parent;
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index de5d2d7..435fc73 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -2518,7 +2518,7 @@ camel_imapx_server_append_message(CamelIMAPXServer *is, CamelFolder *folder, Cam
 		goto fail;
 	}
 
-	filter = (CamelStream *)camel_stream_filter_new_with_stream(stream);
+	filter = camel_stream_filter_new (stream);
 	camel_object_unref(stream);
 	canon = camel_mime_filter_canon_new(CAMEL_MIME_FILTER_CANON_CRLF);
 	camel_stream_filter_add((CamelStreamFilter *)filter, canon);
diff --git a/camel/providers/imapx/camel-imapx-store-summary.c b/camel/providers/imapx/camel-imapx-store-summary.c
index 9cc9147..63feec7 100644
--- a/camel/providers/imapx/camel-imapx-store-summary.c
+++ b/camel/providers/imapx/camel-imapx-store-summary.c
@@ -65,18 +65,20 @@ static CamelStoreSummaryClass *camel_imapx_store_summary_parent;
 static void
 camel_imapx_store_summary_class_init (CamelIMAPXStoreSummaryClass *klass)
 {
-	CamelStoreSummaryClass *ssklass = (CamelStoreSummaryClass *)klass;
+	CamelStoreSummaryClass *ssclass = (CamelStoreSummaryClass *)class;
 
-	ssklass->summary_header_load = summary_header_load;
-	ssklass->summary_header_save = summary_header_save;
+	parent_class = (CamelStoreSummaryClass *)CAMEL_TYPE_STORE_SUMMARY;
 
-	/*ssklass->store_info_new  = store_info_new;*/
-	ssklass->store_info_load = store_info_load;
-	ssklass->store_info_save = store_info_save;
-	ssklass->store_info_free = store_info_free;
+	ssclass->summary_header_load = summary_header_load;
+	ssclass->summary_header_save = summary_header_save;
 
-	ssklass->store_info_string = store_info_string;
-	ssklass->store_info_set_string = store_info_set_string;
+	/*ssclass->store_info_new  = store_info_new;*/
+	ssclass->store_info_load = store_info_load;
+	ssclass->store_info_save = store_info_save;
+	ssclass->store_info_free = store_info_free;
+
+	ssclass->store_info_string = store_info_string;
+	ssclass->store_info_set_string = store_info_set_string;
 }
 
 static void
diff --git a/camel/providers/imapx/camel-imapx-stream.c b/camel/providers/imapx/camel-imapx-stream.c
index b76e9ab..0abe7ce 100644
--- a/camel/providers/imapx/camel-imapx-stream.c
+++ b/camel/providers/imapx/camel-imapx-stream.c
@@ -147,15 +147,16 @@ 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 = g_type_class_peek_parent (class);
 
-	/* virtual method definition */
 	camel_stream_class->read = stream_read;
 	camel_stream_class->write = stream_write;
 	camel_stream_class->close = stream_close;
 	camel_stream_class->flush = stream_flush;
 	camel_stream_class->eos = stream_eos;
 	camel_stream_class->reset = stream_reset;
+
+	setup_table();
 }
 
 static void
@@ -172,7 +173,7 @@ camel_imapx_stream_finalise(CamelIMAPXStream *is)
 {
 	g_free(is->buf);
 	if (is->source)
-		camel_object_unref((CamelObject *)is->source);
+		g_object_unref (is->source);
 }
 
 CamelType
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 7273a15..7aee53e 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -1024,11 +1024,11 @@ imap_free_fetch(struct _fetch_info *finfo)
 		return;
 
 	if (finfo->body)
-		camel_object_unref((CamelObject *)finfo->body);
+		g_object_unref (finfo->body);
 	if (finfo->text)
-		camel_object_unref((CamelObject *)finfo->text);
+		g_object_unref (finfo->text);
 	if (finfo->header)
-		camel_object_unref((CamelObject *)finfo->header);
+		g_object_unref (finfo->header);
 	if (finfo->minfo)
 		camel_message_info_free(finfo->minfo);
 	if (finfo->cinfo)
@@ -1094,7 +1094,7 @@ imap_dump_fetch(struct _fetch_info *finfo)
 		camel_stream_printf(sout, "Section: '%s'\n", finfo->section);
 	if (finfo->date)
 		camel_stream_printf(sout, "UID: '%s'\n", finfo->uid);
-	camel_object_unref((CamelObject *)sout);
+	g_object_unref (sout);
 }
 
 struct _fetch_info *
diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c
index 5b2890c..d1568af 100644
--- a/camel/providers/local/camel-local-folder.c
+++ b/camel/providers/local/camel-local-folder.c
@@ -33,7 +33,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -41,14 +40,7 @@
 #include <posix1_lim.h>
 #endif
 
-#include "camel-data-wrapper.h"
-#include "camel-exception.h"
-#include "camel-mime-filter-from.h"
-#include "camel-mime-message.h"
 #include "camel-private.h"
-#include "camel-stream-filter.h"
-#include "camel-stream-fs.h"
-#include "camel-text-index.h"
 
 #include "camel-local-folder.h"
 #include "camel-local-private.h"
@@ -61,13 +53,12 @@
 #define PATH_MAX _POSIX_PATH_MAX
 #endif
 
-static CamelFolderClass *parent_class;
-static GSList *local_folder_properties;
+#define CAMEL_LOCAL_FOLDER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_LOCAL_FOLDER, CamelLocalFolderPrivate))
 
-/* Returns the class for a CamelLocalFolder */
-#define CLOCALF_CLASS(so) CAMEL_LOCAL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CLOCALS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
+static GSList *local_folder_properties;
 
 static gint local_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args);
 static gint local_setv(CamelObject *object, CamelException *ex, CamelArgV *args);
@@ -89,119 +80,142 @@ static GPtrArray * local_get_uncached_uids (CamelFolder *folder, GPtrArray * uid
 static void local_delete(CamelFolder *folder);
 static void local_rename(CamelFolder *folder, const gchar *newname);
 
-static void local_finalize(CamelObject * object);
+static CamelProperty local_property_list[] = {
+	{ CAMEL_LOCAL_FOLDER_INDEX_BODY, "index_body", N_("Index message body data") },
+};
 
 static void
-camel_local_folder_class_init(CamelLocalFolderClass * camel_local_folder_class)
+local_folder_dispose (GObject *object)
 {
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS(camel_local_folder_class);
-	CamelObjectClass *oklass = (CamelObjectClass *)camel_local_folder_class;
-
-	/* virtual method definition */
+	CamelFolder *folder;
+	CamelLocalFolder *local_folder;
 
-	/* virtual method overload */
-	oklass->getv = local_getv;
-	oklass->setv = local_setv;
+	folder = CAMEL_FOLDER (object);
+	local_folder = CAMEL_LOCAL_FOLDER (object);
 
-	camel_folder_class->refresh_info = local_refresh_info;
-	camel_folder_class->sync = local_sync;
-	camel_folder_class->expunge = local_expunge;
-	camel_folder_class->get_uncached_uids = local_get_uncached_uids;
+	if (folder->summary != NULL) {
+		camel_local_summary_sync (
+			CAMEL_LOCAL_SUMMARY (folder->summary),
+			FALSE, local_folder->changes, NULL);
+		g_object_unref (folder->summary);
+		folder->summary = NULL;
+	}
 
-	camel_folder_class->search_by_expression = local_search_by_expression;
-	camel_folder_class->count_by_expression = local_count_by_expression;
-	camel_folder_class->search_by_uids = local_search_by_uids;
-	camel_folder_class->search_free = local_search_free;
+	if (local_folder->search != NULL) {
+		g_object_unref (local_folder->search);
+		local_folder->search = NULL;
+	}
 
-	camel_folder_class->delete = local_delete;
-	camel_folder_class->rename = local_rename;
+	if (local_folder->index != NULL) {
+		g_object_unref (local_folder->index);
+		local_folder->index = NULL;
+	}
 
-	camel_local_folder_class->lock = local_lock;
-	camel_local_folder_class->unlock = local_unlock;
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-local_init(gpointer object, gpointer klass)
+local_folder_finalize (GObject *object)
 {
-	CamelFolder *folder = object;
-	CamelLocalFolder *local_folder = object;
+	CamelLocalFolder *local_folder;
 
-	folder->folder_flags |= (CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY |
-				 CAMEL_FOLDER_HAS_SEARCH_CAPABILITY);
+	local_folder = CAMEL_LOCAL_FOLDER (object);
 
-	folder->permanent_flags = CAMEL_MESSAGE_ANSWERED |
-	    CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_DRAFT |
-	    CAMEL_MESSAGE_FLAGGED | CAMEL_MESSAGE_SEEN |
-	    CAMEL_MESSAGE_ANSWERED_ALL | CAMEL_MESSAGE_USER;
+	while (local_folder->locked > 0)
+		camel_local_folder_unlock (local_folder);
 
-	folder->summary = NULL;
-	local_folder->search = NULL;
+	g_free (local_folder->base_path);
+	g_free (local_folder->folder_path);
+	g_free (local_folder->summary_path);
+	g_free (local_folder->index_path);
 
-	local_folder->priv = g_malloc0(sizeof(*local_folder->priv));
-	local_folder->priv->search_lock = g_mutex_new();
+	camel_folder_change_info_free (local_folder->changes);
+
+	g_mutex_free (local_folder->priv->search_lock);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-local_finalize(CamelObject * object)
+local_folder_class_init (CamelLocalFolderClass *class)
 {
-	CamelLocalFolder *local_folder = CAMEL_LOCAL_FOLDER(object);
-	CamelFolder *folder = (CamelFolder *)object;
-
-	if (folder->summary) {
-		camel_local_summary_sync((CamelLocalSummary *)folder->summary, FALSE, local_folder->changes, NULL);
-		camel_object_unref((CamelObject *)folder->summary);
-		folder->summary = NULL;
+	GObjectClass *object_class;
+	CamelObjectClass *camel_object_class;
+	CamelFolderClass *folder_class;
+	gint ii;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelLocalFolderPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = local_folder_dispose;
+	object_class->finalize = local_folder_finalize;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = local_getv;
+	camel_object_class->setv = local_setv;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->refresh_info = local_refresh_info;
+	folder_class->sync = local_sync;
+	folder_class->expunge = local_expunge;
+	folder_class->get_uncached_uids = local_get_uncached_uids;
+	folder_class->search_by_expression = local_search_by_expression;
+	folder_class->count_by_expression = local_count_by_expression;
+	folder_class->search_by_uids = local_search_by_uids;
+	folder_class->search_free = local_search_free;
+	folder_class->delete = local_delete;
+	folder_class->rename = local_rename;
+
+	class->lock = local_lock;
+	class->unlock = local_unlock;
+
+	for (ii = 0; ii < G_N_ELEMENTS (local_property_list); ii++) {
+		local_property_list[ii].description =
+			_(local_property_list[ii].description);
+		local_folder_properties = g_slist_prepend (
+			local_folder_properties, &local_property_list[ii]);
 	}
+}
 
-	if (local_folder->search)
-		camel_object_unref((CamelObject *)local_folder->search);
-
-	if (local_folder->index)
-		camel_object_unref((CamelObject *)local_folder->index);
-
-	while (local_folder->locked> 0)
-		camel_local_folder_unlock(local_folder);
+static void
+local_folder_init (CamelLocalFolder *local_folder)
+{
+	CamelFolder *folder = CAMEL_FOLDER (local_folder);
 
-	g_free(local_folder->base_path);
-	g_free(local_folder->folder_path);
-	g_free(local_folder->summary_path);
-	g_free(local_folder->index_path);
+	local_folder->priv = CAMEL_LOCAL_FOLDER_GET_PRIVATE (local_folder);
+	local_folder->priv->search_lock = g_mutex_new();
 
-	camel_folder_change_info_free(local_folder->changes);
+	folder->folder_flags |= (CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY |
+				 CAMEL_FOLDER_HAS_SEARCH_CAPABILITY);
 
-	g_mutex_free(local_folder->priv->search_lock);
+	folder->permanent_flags = CAMEL_MESSAGE_ANSWERED |
+	    CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_DRAFT |
+	    CAMEL_MESSAGE_FLAGGED | CAMEL_MESSAGE_SEEN |
+	    CAMEL_MESSAGE_ANSWERED_ALL | CAMEL_MESSAGE_USER;
 
-	g_free(local_folder->priv);
+	folder->summary = NULL;
+	local_folder->search = NULL;
 }
 
-static CamelProperty local_property_list[] = {
-	{ CAMEL_LOCAL_FOLDER_INDEX_BODY, "index_body", N_("Index message body data") },
-};
-
-CamelType
-camel_local_folder_get_type(void)
+GType
+camel_local_folder_get_type (void)
 {
-	static CamelType camel_local_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_local_folder_type == CAMEL_INVALID_TYPE) {
-		gint i;
-
-		parent_class = (CamelFolderClass *)camel_folder_get_type();
-		camel_local_folder_type = camel_type_register(camel_folder_get_type(), "CamelLocalFolder",
-							     sizeof(CamelLocalFolder),
-							     sizeof(CamelLocalFolderClass),
-							     (CamelObjectClassInitFunc) camel_local_folder_class_init,
-							     NULL,
-							     (CamelObjectInitFunc) local_init,
-							     (CamelObjectFinalizeFunc) local_finalize);
-
-		for (i = 0; i < G_N_ELEMENTS (local_property_list); i++) {
-			local_property_list[i].description = _(local_property_list[i].description);
-			local_folder_properties = g_slist_prepend(local_folder_properties, &local_property_list[i]);
-		}
-	}
-
-	return camel_local_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER,
+			"CamelLocalFolder",
+			sizeof (CamelLocalFolderClass),
+			(GClassInitFunc) local_folder_class_init,
+			sizeof (CamelLocalFolder),
+			(GInstanceInitFunc) local_folder_init,
+			0);
+
+	return type;
 }
 
 CamelLocalFolder *
@@ -290,13 +304,13 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con
 		forceindex = FALSE;
 	}
 
-	folder->summary = (CamelFolderSummary *)CLOCALF_CLASS(lf)->create_summary(lf, lf->summary_path, lf->folder_path, lf->index);
+	folder->summary = (CamelFolderSummary *)CAMEL_LOCAL_FOLDER_GET_CLASS(lf)->create_summary(lf, lf->summary_path, lf->folder_path, lf->index);
 	if (!(flags & CAMEL_STORE_IS_MIGRATING) && camel_local_summary_load((CamelLocalSummary *)folder->summary, forceindex, NULL) == -1) {
 		/* ? */
 		if (camel_local_summary_check((CamelLocalSummary *)folder->summary, lf->changes, ex) == 0) {
 			/* we sync here so that any hard work setting up the folder isn't lost */
 			if (camel_local_summary_sync((CamelLocalSummary *)folder->summary, FALSE, lf->changes, ex) == -1) {
-				camel_object_unref (CAMEL_OBJECT (folder));
+				g_object_unref (CAMEL_OBJECT (folder));
 				g_free(name);
 				return NULL;
 			}
@@ -308,7 +322,7 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con
 	/*if (camel_local_summary_check((CamelLocalSummary *)folder->summary, lf->changes, ex) == -1) {*/
 	/* we sync here so that any hard work setting up the folder isn't lost */
 	/*if (camel_local_summary_sync((CamelLocalSummary *)folder->summary, FALSE, lf->changes, ex) == -1) {
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 		g_free(name);
 		return NULL;
 		}*/
@@ -343,7 +357,7 @@ gint camel_local_folder_lock(CamelLocalFolder *lf, CamelLockType type, CamelExce
 		/* lets be anal here - its important the code knows what its doing */
 		g_assert(lf->locktype == type || lf->locktype == CAMEL_LOCK_WRITE);
 	} else {
-		if (CLOCALF_CLASS(lf)->lock(lf, type, ex) == -1)
+		if (CAMEL_LOCAL_FOLDER_GET_CLASS(lf)->lock(lf, type, ex) == -1)
 			return -1;
 		lf->locktype = type;
 	}
@@ -359,7 +373,7 @@ gint camel_local_folder_unlock(CamelLocalFolder *lf)
 	g_assert(lf->locked>0);
 	lf->locked--;
 	if (lf->locked == 0)
-		CLOCALF_CLASS(lf)->unlock(lf);
+		CAMEL_LOCAL_FOLDER_GET_CLASS(lf)->unlock(lf);
 
 	return 0;
 }
@@ -488,6 +502,7 @@ local_refresh_info(CamelFolder *folder, CamelException *ex)
 		return;
 	}
 
+	CAMEL_FOLDER_REC_UNLOCK(folder, lock);
 	if (camel_folder_change_info_changed(lf->changes)) {
 		camel_object_trigger_event((CamelObject *)folder, "folder_changed", lf->changes);
 		camel_folder_change_info_clear(lf->changes);
@@ -532,7 +547,7 @@ local_expunge(CamelFolder *folder, CamelException *ex)
 
 	/* Just do a sync with expunge, serves the same purpose */
 	/* call the callback directly, to avoid locking problems */
-	CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(folder))->sync(folder, TRUE, ex);
+	CAMEL_FOLDER_GET_CLASS (folder)->sync (folder, TRUE, ex);
 }
 
 static void
@@ -543,7 +558,7 @@ local_delete(CamelFolder *folder)
 	if (lf->index)
 		camel_index_delete(lf->index);
 
-	parent_class->delete(folder);
+	CAMEL_FOLDER_CLASS (parent_class)->delete (folder);
 }
 
 static void
@@ -573,7 +588,7 @@ local_rename(CamelFolder *folder, const gchar *newname)
 	g_free(((CamelLocalSummary *)folder->summary)->folder_path);
 	((CamelLocalSummary *)folder->summary)->folder_path = g_strdup(lf->folder_path);
 
-	parent_class->rename(folder, newname);
+	CAMEL_FOLDER_CLASS (parent_class)->rename (folder, newname);
 }
 
 static GPtrArray *
diff --git a/camel/providers/local/camel-local-folder.h b/camel/providers/local/camel-local-folder.h
index f8cdbb7..5395a21 100644
--- a/camel/providers/local/camel-local-folder.h
+++ b/camel/providers/local/camel-local-folder.h
@@ -20,20 +20,30 @@
  */
 
 #ifndef CAMEL_LOCAL_FOLDER_H
-#define CAMEL_LOCAL_FOLDER_H 1
+#define CAMEL_LOCAL_FOLDER_H
 
-#include <camel/camel-folder.h>
-#include <camel/camel-folder-search.h>
-#include <camel/camel-index.h>
-#include "camel-local-summary.h"
-#include "camel-lock.h"
+#include <camel/camel.h>
 
-/*  #include "camel-store.h" */
+#include "camel-local-summary.h"
 
-#define CAMEL_LOCAL_FOLDER_TYPE     (camel_local_folder_get_type ())
-#define CAMEL_LOCAL_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_LOCAL_FOLDER_TYPE, CamelLocalFolder))
-#define CAMEL_LOCAL_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_LOCAL_FOLDER_TYPE, CamelLocalFolderClass))
-#define CAMEL_IS_LOCAL_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_LOCAL_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_LOCAL_FOLDER \
+	(camel_local_folder_get_type ())
+#define CAMEL_LOCAL_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_LOCAL_FOLDER, CamelLocalFolder))
+#define CAMEL_LOCAL_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_LOCAL_FOLDER, CamelLocalFolderClass))
+#define CAMEL_IS_LOCAL_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_LOCAL_FOLDER))
+#define CAMEL_IS_LOCAL_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_LOCAL_FOLDER))
+#define CAMEL_LOCAL_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_LOCAL_FOLDER, CamelLocalFolderClass))
 
 G_BEGIN_DECLS
 
@@ -52,7 +62,7 @@ typedef struct _CamelLocalFolderClass CamelLocalFolderClass;
 typedef struct _CamelLocalFolderPrivate CamelLocalFolderPrivate;
 
 struct _CamelLocalFolder {
-	CamelFolder parent_object;
+	CamelFolder parent;
 	CamelLocalFolderPrivate *priv;
 
 	guint32 flags;		/* open mode flags */
@@ -90,8 +100,7 @@ struct _CamelLocalFolderClass {
 CamelLocalFolder *camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store,
 					       const gchar *full_name, guint32 flags, CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_local_folder_get_type(void);
+GType camel_local_folder_get_type(void);
 
 /* Lock the folder for internal use.  May be called repeatedly */
 /* UNIMPLEMENTED */
diff --git a/camel/providers/local/camel-local-private.h b/camel/providers/local/camel-local-private.h
index 68f2503..c958e92 100644
--- a/camel/providers/local/camel-local-private.h
+++ b/camel/providers/local/camel-local-private.h
@@ -21,7 +21,7 @@
  */
 
 #ifndef CAMEL_LOCAL_PRIVATE_H
-#define CAMEL_LOCAL_PRIVATE_H 1
+#define CAMEL_LOCAL_PRIVATE_H
 
 /* need a way to configure and save this data, if this header is to
    be installed.  For now, dont install it */
diff --git a/camel/providers/local/camel-local-provider.c b/camel/providers/local/camel-local-provider.c
index b5d85e1..c853d84 100644
--- a/camel/providers/local/camel-local-provider.c
+++ b/camel/providers/local/camel-local-provider.c
@@ -28,10 +28,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-provider.h"
-#include "camel-session.h"
-#include "camel-url.h"
-
 #include "camel-maildir-store.h"
 #include "camel-mbox-store.h"
 #include "camel-mh-store.h"
@@ -211,7 +207,8 @@ local_url_equal(gconstpointer v, gconstpointer v2)
 		&& check_equal(u1->protocol, u2->protocol);
 }
 
-void camel_provider_module_init(void)
+void
+camel_provider_module_init(void)
 {
 #ifndef G_OS_WIN32
 	gchar *path;
@@ -238,7 +235,7 @@ void camel_provider_module_init(void)
 #else
 	mbox_conf_entries[0].value = "";  /* default path */
 #endif
-	mbox_provider.object_types[CAMEL_PROVIDER_STORE] = camel_mbox_store_get_type ();
+	mbox_provider.object_types[CAMEL_PROVIDER_STORE] = CAMEL_TYPE_MBOX_STORE;
 	mbox_provider.url_hash = local_url_hash;
 	mbox_provider.url_equal = local_url_equal;
 	mbox_provider.translation_domain = GETTEXT_PACKAGE;
diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c
index f98cdf4..faa79a6 100644
--- a/camel/providers/local/camel-local-store.c
+++ b/camel/providers/local/camel-local-store.c
@@ -29,28 +29,16 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
 #include <libedataserver/e-data-server-util.h>
 
-#include "camel/camel-exception.h"
-#include "camel/camel-file-utils.h"
-#include "camel/camel-private.h"
-#include "camel/camel-text-index.h"
-#include "camel/camel-url.h"
-#include "camel/camel-vtrash-folder.h"
-
 #include "camel-local-folder.h"
 #include "camel-local-store.h"
 
 #define d(x)
 
-/* Returns the class for a CamelLocalStore */
-#define CLOCALS_CLASS(so) CAMEL_LOCAL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
 static void construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex);
 static CamelFolder *get_folder(CamelStore * store, const gchar *folder_name, guint32 flags, CamelException * ex);
 static gchar *get_name(CamelService *service, gboolean brief);
@@ -66,64 +54,67 @@ static gboolean local_can_refresh_folder (CamelStore *store, CamelFolderInfo *in
 static gchar *local_get_full_path(CamelLocalStore *lf, const gchar *full_name);
 static gchar *local_get_meta_path(CamelLocalStore *lf, const gchar *full_name, const gchar *ext);
 
-static CamelStoreClass *parent_class = NULL;
+static gpointer parent_class;
 
 static void
-camel_local_store_class_init (CamelLocalStoreClass *camel_local_store_class)
+local_store_finalize (GObject *object)
 {
-	CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_local_store_class);
-	CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS (camel_local_store_class);
-
-	parent_class = CAMEL_STORE_CLASS (camel_type_get_global_classfuncs (camel_store_get_type ()));
-
-	/* virtual method overload */
-	camel_service_class->construct = construct;
-	camel_service_class->get_name = get_name;
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->get_inbox = local_get_inbox;
-	camel_store_class->get_trash = local_get_trash;
-	camel_store_class->get_junk = local_get_junk;
-	camel_store_class->get_folder_info = get_folder_info;
-	camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-
-	camel_store_class->create_folder = create_folder;
-	camel_store_class->delete_folder = delete_folder;
-	camel_store_class->rename_folder = rename_folder;
-	camel_store_class->can_refresh_folder = local_can_refresh_folder;
-
-	camel_local_store_class->get_full_path = local_get_full_path;
-	camel_local_store_class->get_meta_path = local_get_meta_path;
+	CamelLocalStore *local_store = CAMEL_LOCAL_STORE (object);
+
+	g_free (local_store->toplevel_dir);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_local_store_finalize (CamelLocalStore *local_store)
+local_store_class_init (CamelLocalStoreClass *class)
 {
-	CamelStore *store;
-
-	if (local_store->toplevel_dir)
-		g_free (local_store->toplevel_dir);
-
-	store = ((CamelStore *)local_store);
-	d(printf ("\n\aLocal Store Finalize \n\a"));
-
+	GObjectClass *object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = local_store_finalize;
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = construct;
+	service_class->get_name = get_name;
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_folder = get_folder;
+	store_class->get_inbox = local_get_inbox;
+	store_class->get_trash = local_get_trash;
+	store_class->get_junk = local_get_junk;
+	store_class->get_folder_info = get_folder_info;
+	store_class->free_folder_info = camel_store_free_folder_info_full;
+	store_class->create_folder = create_folder;
+	store_class->delete_folder = delete_folder;
+	store_class->rename_folder = rename_folder;
+	store_class->can_refresh_folder = local_can_refresh_folder;
+
+	class->get_full_path = local_get_full_path;
+	class->get_meta_path = local_get_meta_path;
 }
 
-CamelType
+GType
 camel_local_store_get_type (void)
 {
-	static CamelType camel_local_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_local_store_type == CAMEL_INVALID_TYPE)	{
-		camel_local_store_type = camel_type_register (CAMEL_STORE_TYPE, "CamelLocalStore",
-							     sizeof (CamelLocalStore),
-							     sizeof (CamelLocalStoreClass),
-							     (CamelObjectClassInitFunc) camel_local_store_class_init,
-							     NULL,
-							     NULL,
-							     (CamelObjectFinalizeFunc) camel_local_store_finalize);
-	}
-
-	return camel_local_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE,
+			"CamelLocalStore",
+			sizeof (CamelLocalStoreClass),
+			(GClassInitFunc) local_store_class_init,
+			sizeof (CamelLocalStore),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 static void
@@ -297,10 +288,10 @@ create_folder(CamelStore *store, const gchar *parent_name, const gchar *folder_n
 	else
 		name = g_strdup_printf("%s", folder_name);
 
-	folder = ((CamelStoreClass *)((CamelObject *)store)->klass)->get_folder(store, name, CAMEL_STORE_FOLDER_CREATE, ex);
+	folder = CAMEL_STORE_GET_CLASS (store)->get_folder (store, name, CAMEL_STORE_FOLDER_CREATE, ex);
 	if (folder) {
-		camel_object_unref((CamelObject *)folder);
-		info = ((CamelStoreClass *)((CamelObject *)store)->klass)->get_folder_info(store, name, 0, ex);
+		g_object_unref (folder);
+		info = CAMEL_STORE_GET_CLASS (store)->get_folder_info (store, name, 0, ex);
 
 		/* get_folder(CREATE) will emit a folder_created event for us */
 		/*if (info)
@@ -387,7 +378,7 @@ rename_folder(CamelStore *store, const gchar *old, const gchar *new, CamelExcept
 	g_free(oldibex);
 
 	if (folder)
-		camel_object_unref (folder);
+		g_object_unref (folder);
 
 	return;
 
@@ -414,7 +405,7 @@ ibex_failed:
 	g_free(oldibex);
 
 	if (folder)
-		camel_object_unref(folder);
+		g_object_unref (folder);
 }
 
 /* default implementation, only delete metadata */
@@ -445,7 +436,7 @@ delete_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
 	if ((lf = camel_store_get_folder (store, folder_name, 0, &lex))) {
 		camel_object_get (lf, NULL, CAMEL_OBJECT_STATE_FILE, &str, NULL);
 		camel_object_set (lf, NULL, CAMEL_OBJECT_STATE_FILE, NULL, NULL);
-		camel_object_unref (lf);
+		g_object_unref (lf);
 	} else {
 		camel_exception_clear (&lex);
 	}
diff --git a/camel/providers/local/camel-local-store.h b/camel/providers/local/camel-local-store.h
index 410c80b..93f66c0 100644
--- a/camel/providers/local/camel-local-store.h
+++ b/camel/providers/local/camel-local-store.h
@@ -21,37 +21,57 @@
  */
 
 #ifndef CAMEL_LOCAL_STORE_H
-#define CAMEL_LOCAL_STORE_H 1
+#define CAMEL_LOCAL_STORE_H
 
-#include "camel-store.h"
+#include <camel/camel.h>
 
-#define CAMEL_LOCAL_STORE_TYPE     (camel_local_store_get_type ())
-#define CAMEL_LOCAL_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_LOCAL_STORE_TYPE, CamelLocalStore))
-#define CAMEL_LOCAL_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_LOCAL_STORE_TYPE, CamelLocalStoreClass))
-#define CAMEL_IS_LOCAL_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_LOCAL_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_LOCAL_STORE \
+	(camel_local_store_get_type ())
+#define CAMEL_LOCAL_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_LOCAL_STORE, CamelLocalStore))
+#define CAMEL_LOCAL_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_LOCAL_STORE, CamelLocalStoreClass))
+#define CAMEL_IS_LOCAL_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_LOCAL_STORE))
+#define CAMEL_IS_LOCAL_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_LOCAL_STORE))
+#define CAMEL_LOCAL_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_LOCAL_STORE, CamelLocalStoreClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelStore parent_object;
+typedef struct _CamelLocalStore CamelLocalStore;
+typedef struct _CamelLocalStoreClass CamelLocalStoreClass;
+
+struct _CamelLocalStore {
+	CamelStore parent;
 
 	gchar *toplevel_dir;
-} CamelLocalStore;
+};
 
-typedef struct {
+struct _CamelLocalStoreClass {
 	CamelStoreClass parent_class;
 
 	gchar *(*get_full_path)(CamelLocalStore *ls, const gchar *full_name);
 	gchar *(*get_meta_path)(CamelLocalStore *ls, const gchar *full_name, const gchar *ext);
-} CamelLocalStoreClass;
+};
 
-/* Standard Camel function */
-CamelType camel_local_store_get_type (void);
+GType camel_local_store_get_type (void);
 
 const gchar *camel_local_store_get_toplevel_dir (CamelLocalStore *store);
 
-#define camel_local_store_get_full_path(ls, name) ((CamelLocalStoreClass *)((CamelObject *)ls)->klass)->get_full_path((CamelLocalStore *)ls, name)
-#define camel_local_store_get_meta_path(ls, name, ext) ((CamelLocalStoreClass *)((CamelObject *)ls)->klass)->get_meta_path((CamelLocalStore *)ls, name, ext)
+#define camel_local_store_get_full_path(ls, name) \
+	(CAMEL_LOCAL_STORE_GET_CLASS (ls)->get_full_path \
+	(CAMEL_LOCAL_STORE (ls), (name)))
+#define camel_local_store_get_meta_path(ls, name, ext) \
+	(CAMEL_LOCAL_STORE_GET_CLASS (ls)->get_meta_path \
+	(CAMEL_LOCAL_STORE (ls), (name), (ext)))
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-local-summary.c b/camel/providers/local/camel-local-summary.c
index c146d8f..5a4fa70 100644
--- a/camel/providers/local/camel-local-summary.c
+++ b/camel/providers/local/camel-local-summary.c
@@ -30,16 +30,9 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "camel-db.h"
-#include "camel-file-utils.h"
-#include "camel-mime-message.h"
-#include "camel-stream-null.h"
-#include "camel-string-utils.h"
-
 #include "camel-local-summary.h"
 
 #define w(x)
@@ -67,75 +60,96 @@ static gint local_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFo
 static CamelMessageInfo *local_summary_add(CamelLocalSummary *cls, CamelMimeMessage *msg, const CamelMessageInfo *info, CamelFolderChangeInfo *, CamelException *ex);
 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 CamelFolderSummaryClass *camel_local_summary_parent;
+static gpointer parent_class;
 
-CamelType
-camel_local_summary_get_type(void)
+static void
+local_summary_dispose (GObject *object)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_folder_summary_get_type(), "CamelLocalSummary",
-					   sizeof (CamelLocalSummary),
-					   sizeof (CamelLocalSummaryClass),
-					   (CamelObjectClassInitFunc) camel_local_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_local_summary_init,
-					   (CamelObjectFinalizeFunc) camel_local_summary_finalise);
+	CamelLocalSummary *local_summary;
+
+	local_summary = CAMEL_LOCAL_SUMMARY (object);
+
+	if (local_summary->index != NULL) {
+		g_object_unref (local_summary->index);
+		local_summary->index = NULL;
 	}
 
-	return type;
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_local_summary_class_init(CamelLocalSummaryClass *klass)
+local_summary_finalize (GObject *object)
 {
-	CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) klass;
-
-	camel_local_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS(camel_type_get_global_classfuncs(camel_folder_summary_get_type()));
+	CamelLocalSummary *local_summary;
 
-	sklass->summary_header_load = summary_header_load;
-	sklass->summary_header_save = summary_header_save;
+	local_summary = CAMEL_LOCAL_SUMMARY (object);
 
-	sklass->summary_header_from_db = summary_header_from_db;
-	sklass->summary_header_to_db = summary_header_to_db;
+	g_free (local_summary->folder_path);
 
-	sklass->message_info_new_from_header  = message_info_new_from_header;
-
-	klass->load = local_summary_load;
-	klass->check = local_summary_check;
-	klass->sync = local_summary_sync;
-	klass->add = local_summary_add;
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
 
-	klass->encode_x_evolution = local_summary_encode_x_evolution;
-	klass->decode_x_evolution = local_summary_decode_x_evolution;
-	klass->need_index = local_summary_need_index;
+static void
+local_summary_class_init (CamelLocalSummaryClass *class)
+{
+	GObjectClass *object_class;
+	CamelFolderSummaryClass *folder_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = local_summary_dispose;
+	object_class->finalize = local_summary_finalize;
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->summary_header_load = summary_header_load;
+	folder_summary_class->summary_header_save = summary_header_save;
+	folder_summary_class->summary_header_from_db = summary_header_from_db;
+	folder_summary_class->summary_header_to_db = summary_header_to_db;
+	folder_summary_class->message_info_new_from_header  = message_info_new_from_header;
+
+	class->load = local_summary_load;
+	class->check = local_summary_check;
+	class->sync = local_summary_sync;
+	class->add = local_summary_add;
+	class->encode_x_evolution = local_summary_encode_x_evolution;
+	class->decode_x_evolution = local_summary_decode_x_evolution;
+	class->need_index = local_summary_need_index;
 }
 
 static void
-camel_local_summary_init(CamelLocalSummary *obj)
+local_summary_init (CamelLocalSummary *local_summary)
 {
-	struct _CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *folder_summary;
+
+	folder_summary = CAMEL_FOLDER_SUMMARY (local_summary);
 
 	/* subclasses need to set the right instance data sizes */
-	s->message_info_size = sizeof(CamelLocalMessageInfo);
-	s->content_info_size = sizeof(CamelMessageContentInfo);
+	folder_summary->message_info_size = sizeof (CamelLocalMessageInfo);
+	folder_summary->content_info_size = sizeof (CamelMessageContentInfo);
 
 	/* and a unique file version */
-	s->version += CAMEL_LOCAL_SUMMARY_VERSION;
+	folder_summary->version += CAMEL_LOCAL_SUMMARY_VERSION;
 }
 
-static void
-camel_local_summary_finalise(CamelObject *obj)
+GType
+camel_local_summary_get_type(void)
 {
-	CamelLocalSummary *mbs = CAMEL_LOCAL_SUMMARY(obj);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER_SUMMARY,
+			"CamelLocalSummary",
+			sizeof (CamelLocalSummaryClass),
+			(GClassInitFunc) local_summary_class_init,
+			sizeof (CamelLocalSummary),
+			(GInstanceInitFunc) local_summary_init,
+			0);
 
-	if (mbs->index)
-		camel_object_unref((CamelObject *)mbs->index);
-	g_free(mbs->folder_path);
+	return type;
 }
 
 void
@@ -146,7 +160,7 @@ camel_local_summary_construct(CamelLocalSummary *new, const gchar *filename, con
 	new->folder_path = g_strdup(local_name);
 	new->index = index;
 	if (index)
-		camel_object_ref((CamelObject *)index);
+		g_object_ref (index);
 }
 
 static gint
@@ -160,10 +174,14 @@ local_summary_load(CamelLocalSummary *cls, gint forceindex, CamelException *ex)
 gint
 camel_local_summary_load(CamelLocalSummary *cls, gint forceindex, CamelException *ex)
 {
+	CamelLocalSummaryClass *class;
+
 	d(printf("Loading summary ...\n"));
 
-	if ((forceindex && ((CamelLocalSummaryClass *)(CAMEL_OBJECT_GET_CLASS(cls)))->need_index())
-	    || ((CamelLocalSummaryClass *)(CAMEL_OBJECT_GET_CLASS(cls)))->load(cls, forceindex, ex) == -1) {
+	class = CAMEL_LOCAL_SUMMARY_GET_CLASS (cls);
+
+	if ((forceindex && class->need_index())
+	    || class->load(cls, forceindex, ex) == -1) {
 		w(g_warning("Could not load summary: flags may be reset"));
 		camel_folder_summary_clear((CamelFolderSummary *)cls);
 		return -1;
@@ -180,13 +198,13 @@ void camel_local_summary_check_force(CamelLocalSummary *cls)
 gchar *
 camel_local_summary_encode_x_evolution(CamelLocalSummary *cls, const CamelLocalMessageInfo *info)
 {
-	return ((CamelLocalSummaryClass *)(CAMEL_OBJECT_GET_CLASS(cls)))->encode_x_evolution(cls, info);
+	return CAMEL_LOCAL_SUMMARY_GET_CLASS (cls)->encode_x_evolution (cls, info);
 }
 
 gint
 camel_local_summary_decode_x_evolution(CamelLocalSummary *cls, const gchar *xev, CamelLocalMessageInfo *info)
 {
-	return ((CamelLocalSummaryClass *)(CAMEL_OBJECT_GET_CLASS(cls)))->decode_x_evolution(cls, xev, info);
+	return CAMEL_LOCAL_SUMMARY_GET_CLASS (cls)->decode_x_evolution (cls, xev, info);
 }
 
 /*#define DOSTATS*/
@@ -274,7 +292,7 @@ camel_local_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changei
 {
 	gint ret;
 
-	ret = ((CamelLocalSummaryClass *)(CAMEL_OBJECT_GET_CLASS(cls)))->check(cls, changeinfo, ex);
+	ret = CAMEL_LOCAL_SUMMARY_GET_CLASS (cls)->check (cls, changeinfo, ex);
 
 #ifdef DOSTATS
 	if (ret != -1) {
@@ -303,13 +321,13 @@ camel_local_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changei
 gint
 camel_local_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex)
 {
-	return ((CamelLocalSummaryClass *)(CAMEL_OBJECT_GET_CLASS(cls)))->sync(cls, expunge, changeinfo, ex);
+	return CAMEL_LOCAL_SUMMARY_GET_CLASS (cls)->sync (cls, expunge, changeinfo, ex);
 }
 
 CamelMessageInfo *
 camel_local_summary_add(CamelLocalSummary *cls, CamelMimeMessage *msg, const CamelMessageInfo *info, CamelFolderChangeInfo *ci, CamelException *ex)
 {
-	return ((CamelLocalSummaryClass *)(CAMEL_OBJECT_GET_CLASS(cls)))->add(cls, msg, info, ci, ex);
+	return CAMEL_LOCAL_SUMMARY_GET_CLASS (cls)->add (cls, msg, info, ci, ex);
 }
 
 /**
@@ -501,7 +519,7 @@ local_summary_add(CamelLocalSummary *cls, CamelMimeMessage *msg, const CamelMess
 
 			camel_data_wrapper_write_to_stream((CamelDataWrapper *)msg, (CamelStream *)sn);
 			mi->info.size = sn->written;
-			camel_object_unref((CamelObject *)sn);
+			g_object_unref (sn);
 		}
 
 		mi->info.flags &= ~(CAMEL_MESSAGE_FOLDER_NOXEV|CAMEL_MESSAGE_FOLDER_FLAGGED);
@@ -645,7 +663,7 @@ summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *fir)
 
 	/* We dont actually add our own headers, but version that we don't anyway */
 
-	if (((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_from_db(s, fir) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_from_db(s, fir) == -1)
 		return -1;
 
 	part = fir->bdata;
@@ -668,7 +686,7 @@ summary_header_load(CamelFolderSummary *s, FILE *in)
 
 	/* We dont actually add our own headers, but version that we don't anyway */
 
-	if (((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_load(s, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load(s, in) == -1)
 		return -1;
 
 	/* Legacy version, version is in summary only */
@@ -684,7 +702,7 @@ summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 {
 	struct _CamelFIRecord *fir;
 
-	fir = ((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_to_db (s, ex);
+	fir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_to_db (s, ex);
 	if (fir)
 		fir->bdata = g_strdup_printf ("%d", CAMEL_LOCAL_SUMMARY_VERSION);
 
@@ -696,7 +714,7 @@ summary_header_save(CamelFolderSummary *s, FILE *out)
 {
 	/*CamelLocalSummary *cls = (CamelLocalSummary *)s;*/
 
-	if (((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_save(s, out) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_save(s, out) == -1)
 		return -1;
 
 	return camel_file_util_encode_fixed_int32(out, CAMEL_LOCAL_SUMMARY_VERSION);
@@ -708,7 +726,7 @@ message_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
 	CamelLocalMessageInfo *mi;
 	CamelLocalSummary *cls = (CamelLocalSummary *)s;
 
-	mi = (CamelLocalMessageInfo *)((CamelFolderSummaryClass *)camel_local_summary_parent)->message_info_new_from_header(s, h);
+	mi = (CamelLocalMessageInfo *)CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_new_from_header(s, h);
 	if (mi) {
 		const gchar *xev;
 		gint doindex = FALSE;
diff --git a/camel/providers/local/camel-local-summary.h b/camel/providers/local/camel-local-summary.h
index f9cdcd1..204ff1c 100644
--- a/camel/providers/local/camel-local-summary.h
+++ b/camel/providers/local/camel-local-summary.h
@@ -18,17 +18,29 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_LOCAL_SUMMARY_H
-#define _CAMEL_LOCAL_SUMMARY_H
-
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-folder.h>
-#include <camel/camel-exception.h>
-#include <camel/camel-index.h>
-
-#define CAMEL_LOCAL_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_local_summary_get_type (), CamelLocalSummary)
-#define CAMEL_LOCAL_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_local_summary_get_type (), CamelLocalSummaryClass)
-#define CAMEL_IS_LOCAL_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_local_summary_get_type ())
+#ifndef CAMEL_LOCAL_SUMMARY_H
+#define CAMEL_LOCAL_SUMMARY_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_LOCAL_SUMMARY \
+	(camel_local_summary_get_type ())
+#define CAMEL_LOCAL_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_LOCAL_SUMMARY, CamelLocalSummary))
+#define CAMEL_LOCAL_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_LOCAL_SUMMARY, CamelLocalSummaryClass))
+#define CAMEL_IS_LOCAL_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_LOCAL_SUMMARY))
+#define CAMEL_IS_LOCAL_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_LOCAL_SUMMARY))
+#define CAMEL_LOCAL_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_LOCAL_SUMMARY, CamelLocalSummaryClass))
 
 G_BEGIN_DECLS
 
@@ -73,7 +85,7 @@ struct _CamelLocalSummaryClass {
 	gint (*need_index)(void);
 };
 
-CamelType	camel_local_summary_get_type	(void);
+GType	camel_local_summary_get_type	(void);
 void	camel_local_summary_construct	(CamelLocalSummary *new, const gchar *filename, const gchar *local_name, CamelIndex *index);
 
 /* load/check the summary */
@@ -97,4 +109,4 @@ gint camel_local_summary_write_headers(gint fd, struct _camel_header_raw *header
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_LOCAL_SUMMARY_H */
+#endif /* CAMEL_LOCAL_SUMMARY_H */
diff --git a/camel/providers/local/camel-maildir-folder.c b/camel/providers/local/camel-maildir-folder.c
index 81d5553..b24381e 100644
--- a/camel/providers/local/camel-maildir-folder.c
+++ b/camel/providers/local/camel-maildir-folder.c
@@ -35,23 +35,13 @@
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "camel-data-wrapper.h"
-#include "camel-exception.h"
-#include "camel-mime-message.h"
-#include "camel-stream-fs.h"
-
 #include "camel-maildir-folder.h"
 #include "camel-maildir-store.h"
 #include "camel-maildir-summary.h"
 
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
 
-static CamelLocalFolderClass *parent_class = NULL;
-
-/* Returns the class for a CamelMaildirFolder */
-#define CMAILDIRF_CLASS(so) CAMEL_MAILDIR_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CMAILDIRS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static CamelLocalSummary *maildir_create_summary(CamelLocalFolder *lf, const gchar *path, const gchar *folder, CamelIndex *index);
 
@@ -60,8 +50,6 @@ static CamelMimeMessage *maildir_get_message(CamelFolder * folder, const gchar *
 static gchar * maildir_get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex);
 static gint maildir_cmp_uids (CamelFolder *folder, const gchar *uid1, const gchar *uid2);
 static void maildir_sort_uids (CamelFolder *folder, GPtrArray *uids);
-static void maildir_transfer_messages_to (CamelFolder *source, GPtrArray *uids, CamelFolder *dest, GPtrArray **transferred_uids, gboolean delete_originals, CamelException *ex);
-static void maildir_finalize(CamelObject * object);
 
 static gint
 maildir_folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
@@ -92,54 +80,45 @@ maildir_folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 	return ((CamelObjectClass *)parent_class)->getv(object, ex, args);
 }
 
-static void camel_maildir_folder_class_init(CamelObjectClass * camel_maildir_folder_class)
+static void
+maildir_folder_class_init (CamelObjectClass *class)
 {
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS(camel_maildir_folder_class);
-	CamelLocalFolderClass *lclass = (CamelLocalFolderClass *)camel_maildir_folder_class;
-
-	parent_class = CAMEL_LOCAL_FOLDER_CLASS (camel_type_get_global_classfuncs(camel_local_folder_get_type()));
-
-	/* virtual method definition */
-
-	/* virtual method overload */
-	((CamelObjectClass *)camel_folder_class)->getv = maildir_folder_getv;
+	CamelObjectClass *camel_object_class;
+	CamelFolderClass *folder_class;
+	CamelLocalFolderClass *local_folder_class;
 
-	camel_folder_class->append_message = maildir_append_message;
-	camel_folder_class->get_message = maildir_get_message;
-	camel_folder_class->get_filename = maildir_get_filename;
-	camel_folder_class->cmp_uids = maildir_cmp_uids;
-	camel_folder_class->sort_uids = maildir_sort_uids;
-	camel_folder_class->transfer_messages_to = maildir_transfer_messages_to;
+	parent_class = g_type_class_peek_parent (class);
 
-	lclass->create_summary = maildir_create_summary;
-}
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->getv = maildir_folder_getv;
 
-static void maildir_init(gpointer object, gpointer klass)
-{
-	/*CamelFolder *folder = object;
-	  CamelMaildirFolder *maildir_folder = object;*/
-}
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->append_message = maildir_append_message;
+	folder_class->get_message = maildir_get_message;
+	folder_class->get_filename = maildir_get_filename;
+	folder_class->cmp_uids = maildir_cmp_uids;
+	folder_class->sort_uids = maildir_sort_uids;
 
-static void maildir_finalize(CamelObject * object)
-{
-	/*CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER(object);*/
+	local_folder_class = CAMEL_LOCAL_FOLDER_CLASS (class);
+	local_folder_class->create_summary = maildir_create_summary;
 }
 
-CamelType camel_maildir_folder_get_type(void)
+GType
+camel_maildir_folder_get_type (void)
 {
-	static CamelType camel_maildir_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_maildir_folder_type == CAMEL_INVALID_TYPE) {
-		camel_maildir_folder_type = camel_type_register(CAMEL_LOCAL_FOLDER_TYPE, "CamelMaildirFolder",
-							   sizeof(CamelMaildirFolder),
-							   sizeof(CamelMaildirFolderClass),
-							   (CamelObjectClassInitFunc) camel_maildir_folder_class_init,
-							   NULL,
-							   (CamelObjectInitFunc) maildir_init,
-							   (CamelObjectFinalizeFunc) maildir_finalize);
-	}
-
-	return camel_maildir_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_FOLDER,
+			"CamelMaildirFolder",
+			sizeof (CamelMaildirFolderClass),
+			(GClassInitFunc) maildir_folder_class_init,
+			sizeof (CamelMaildirFolder),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 CamelFolder *
@@ -149,7 +128,7 @@ camel_maildir_folder_new(CamelStore *parent_store, const gchar *full_name, guint
 
 	d(printf("Creating maildir folder: %s\n", full_name));
 
-	folder = (CamelFolder *)camel_object_new(CAMEL_MAILDIR_FOLDER_TYPE);
+	folder = g_object_new (CAMEL_TYPE_MAILDIR_FOLDER, NULL);
 
 	if (parent_store->flags & CAMEL_STORE_FILTER_INBOX
 	    && strcmp(full_name, ".") == 0)
@@ -215,7 +194,7 @@ maildir_append_message (CamelFolder *folder, CamelMimeMessage *message, const Ca
 		*appended_uid = g_strdup(camel_message_info_uid(mi));
 
 	if (output_stream)
-		camel_object_unref (output_stream);
+		g_object_unref (output_stream);
 
 	goto check_changed;
 
@@ -234,7 +213,7 @@ maildir_append_message (CamelFolder *folder, CamelMimeMessage *message, const Ca
 				      name, g_strerror (errno));
 
 	if (output_stream) {
-		camel_object_unref (CAMEL_OBJECT (output_stream));
+		g_object_unref (CAMEL_OBJECT (output_stream));
 		unlink (name);
 	}
 
@@ -313,11 +292,11 @@ maildir_get_message(CamelFolder * folder, const gchar * uid, CamelException * ex
 		camel_exception_setv(ex, (errno==EINTR)?CAMEL_EXCEPTION_USER_CANCEL:CAMEL_EXCEPTION_SYSTEM,
 				     _("Cannot get message: %s from folder %s\n  %s"),
 				     uid, lf->folder_path, _("Invalid message contents"));
-		camel_object_unref((CamelObject *)message);
+		g_object_unref (message);
 		message = NULL;
 
 	}
-	camel_object_unref((CamelObject *)message_stream);
+	g_object_unref (message_stream);
  fail:
 	g_free (name);
 
diff --git a/camel/providers/local/camel-maildir-folder.h b/camel/providers/local/camel-maildir-folder.h
index 86aa707..2165756 100644
--- a/camel/providers/local/camel-maildir-folder.h
+++ b/camel/providers/local/camel-maildir-folder.h
@@ -21,34 +21,46 @@
  */
 
 #ifndef CAMEL_MAILDIR_FOLDER_H
-#define CAMEL_MAILDIR_FOLDER_H 1
+#define CAMEL_MAILDIR_FOLDER_H
 
 #include "camel-local-folder.h"
 
-#define CAMEL_MAILDIR_FOLDER_TYPE     (camel_maildir_folder_get_type ())
-#define CAMEL_MAILDIR_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MAILDIR_FOLDER_TYPE, CamelMaildirFolder))
-#define CAMEL_MAILDIR_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MAILDIR_FOLDER_TYPE, CamelMaildirFolderClass))
-#define CAMEL_IS_MAILDIR_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MAILDIR_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MAILDIR_FOLDER \
+	(camel_maildir_folder_get_type ())
+#define CAMEL_MAILDIR_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MAILDIR_FOLDER, CamelMaildirFolder))
+#define CAMEL_MAILDIR_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MAILDIR_FOLDER, CamelMaildirFolderClass))
+#define CAMEL_IS_MAILDIR_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MAILDIR_FOLDER))
+#define CAMEL_IS_MAILDIR_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MAILDIR_FOLDER))
+#define CAMEL_MAILDIR_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MAILDIR_FOLDER, CamelMaildirFolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelLocalFolder parent_object;
+typedef struct _CamelMaildirFolder CamelMaildirFolder;
+typedef struct _CamelMaildirFolderClass CamelMaildirFolderClass;
 
-} CamelMaildirFolder;
+struct _CamelMaildirFolder {
+	CamelLocalFolder parent;
+};
 
-typedef struct {
+struct _CamelMaildirFolderClass {
 	CamelLocalFolderClass parent_class;
-
-	/* Virtual methods */
-
-} CamelMaildirFolderClass;
+};
 
 /* public methods */
 CamelFolder *camel_maildir_folder_new(CamelStore *parent_store, const gchar *full_name, guint32 flags, CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_maildir_folder_get_type(void);
+GType camel_maildir_folder_get_type(void);
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c
index 4921794..66e4cde 100644
--- a/camel/providers/local/camel-maildir-store.c
+++ b/camel/providers/local/camel-maildir-store.c
@@ -32,23 +32,13 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-exception.h"
-#include "camel-list-utils.h"
-#include "camel-private.h"
-#include "camel-url.h"
-
 #include "camel-maildir-folder.h"
 #include "camel-maildir-store.h"
 #include "camel-maildir-summary.h"
 
 #define d(x)
 
-static CamelLocalStoreClass *parent_class = NULL;
-
-/* Returns the class for a CamelMaildirStore */
-#define CMAILDIRS_CLASS(so) CAMEL_MAILDIR_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CMAILDIRF_CLASS(so) CAMEL_MAILDIR_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static CamelFolder *get_folder(CamelStore * store, const gchar *folder_name, guint32 flags, CamelException * ex);
 static CamelFolder *get_inbox (CamelStore *store, CamelException *ex);
@@ -60,40 +50,40 @@ static CamelFolderInfo * get_folder_info (CamelStore *store, const gchar *top, g
 static gboolean maildir_compare_folder_name(gconstpointer a, gconstpointer b);
 static guint maildir_hash_folder_name(gconstpointer a);
 
-static void camel_maildir_store_class_init(CamelObjectClass * camel_maildir_store_class)
+static void
+maildir_store_class_init (CamelObjectClass *class)
 {
-	CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS(camel_maildir_store_class);
-	/*CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS(camel_maildir_store_class);*/
-
-	parent_class = (CamelLocalStoreClass *)camel_type_get_global_classfuncs(camel_local_store_get_type());
-
-	/* virtual method overload, use defaults for most */
-	camel_store_class->hash_folder_name = maildir_hash_folder_name;
-	camel_store_class->compare_folder_name = maildir_compare_folder_name;
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->get_inbox = get_inbox;
-	camel_store_class->delete_folder = delete_folder;
-	camel_store_class->rename_folder = maildir_rename_folder;
-
-	camel_store_class->get_folder_info = get_folder_info;
-	camel_store_class->free_folder_info = camel_store_free_folder_info_full;
+	CamelStoreClass *store_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->hash_folder_name = maildir_hash_folder_name;
+	store_class->compare_folder_name = maildir_compare_folder_name;
+	store_class->get_folder = get_folder;
+	store_class->get_inbox = get_inbox;
+	store_class->delete_folder = delete_folder;
+	store_class->rename_folder = maildir_rename_folder;
+	store_class->get_folder_info = get_folder_info;
+	store_class->free_folder_info = camel_store_free_folder_info_full;
 }
 
-CamelType camel_maildir_store_get_type(void)
+GType
+camel_maildir_store_get_type (void)
 {
-	static CamelType camel_maildir_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_maildir_store_type == CAMEL_INVALID_TYPE) {
-		camel_maildir_store_type = camel_type_register(CAMEL_LOCAL_STORE_TYPE, "CamelMaildirStore",
-							  sizeof(CamelMaildirStore),
-							  sizeof(CamelMaildirStoreClass),
-							  (CamelObjectClassInitFunc) camel_maildir_store_class_init,
-							  NULL,
-							  NULL,
-							  NULL);
-	}
-
-	return camel_maildir_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_STORE,
+			"CamelMaildirStore",
+			sizeof (CamelMaildirStoreClass),
+			(GClassInitFunc) maildir_store_class_init,
+			sizeof (CamelMaildirStore),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 /* This fixes up some historical cruft of names starting with "./" */
@@ -311,7 +301,7 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 			camel_folder_refresh_info(folder, NULL);
 		fi->unread = camel_folder_get_unread_message_count(folder);
 		fi->total = camel_folder_get_message_count(folder);
-		camel_object_unref(folder);
+		g_object_unref (folder);
 	} else {
 		gchar *path, *folderpath;
 		CamelFolderSummary *s;
@@ -326,7 +316,7 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 			fi->unread = s->unread_count;
 			fi->total = s->saved_count;
 		}
-		camel_object_unref(s);
+		g_object_unref (s);
 		g_free(folderpath);
 		g_free(path);
 	}
diff --git a/camel/providers/local/camel-maildir-store.h b/camel/providers/local/camel-maildir-store.h
index e4f4647..b62a90c 100644
--- a/camel/providers/local/camel-maildir-store.h
+++ b/camel/providers/local/camel-maildir-store.h
@@ -20,31 +20,43 @@
  */
 
 #ifndef CAMEL_MAILDIR_STORE_H
-#define CAMEL_MAILDIR_STORE_H 1
+#define CAMEL_MAILDIR_STORE_H
 
 #include "camel-local-store.h"
 
-#define CAMEL_MAILDIR_STORE_TYPE     (camel_maildir_store_get_type ())
-#define CAMEL_MAILDIR_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MAILDIR_STORE_TYPE, CamelMaildirStore))
-#define CAMEL_MAILDIR_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MAILDIR_STORE_TYPE, CamelMaildirStoreClass))
-#define CAMEL_IS_MAILDIR_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MAILDIR_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MAILDIR_STORE \
+	(camel_maildir_store_get_type ())
+#define CAMEL_MAILDIR_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MAILDIR_STORE, CamelMaildirStore))
+#define CAMEL_MAILDIR_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MAILDIR_STORE, CamelMaildirStoreClass))
+#define CAMEL_IS_MAILDIR_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MAILDIR_STORE))
+#define CAMEL_IS_MAILDIR_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MAILDIR_STORE))
+#define CAMEL_MAILDIR_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MAILDIR_STORE, CamelMaildirStoreClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelLocalStore parent_object;
+typedef struct _CamelMaildirStore CamelMaildirStore;
+typedef struct _CamelMaildirStoreClass CamelMaildirStoreClass;
 
-} CamelMaildirStore;
+struct _CamelMaildirStore {
+	CamelLocalStore parent;
+};
 
-typedef struct {
+struct _CamelMaildirStoreClass {
 	CamelLocalStoreClass parent_class;
+};
 
-} CamelMaildirStoreClass;
-
-/* public methods */
-
-/* Standard Camel function */
-CamelType camel_maildir_store_get_type(void);
+GType camel_maildir_store_get_type(void);
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-maildir-summary.c b/camel/providers/local/camel-maildir-summary.c
index 8cc0c9e..e1599c9 100644
--- a/camel/providers/local/camel-maildir-summary.c
+++ b/camel/providers/local/camel-maildir-summary.c
@@ -38,18 +38,16 @@
 
 #include <libedataserver/e-memory.h>
 
-#include "camel-db.h"
-#include "camel-mime-message.h"
-#include "camel-operation.h"
-#include "camel-private.h"
-#include "camel-store.h"
-#include "camel-string-utils.h"
 #include "camel-maildir-summary.h"
 
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
 
 #define CAMEL_MAILDIR_SUMMARY_VERSION (0x2000)
 
+#define CAMEL_MAILDIR_SUMMARY_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MAILDIR_SUMMARY, CamelMaildirSummaryPrivate))
+
 static CamelMessageInfo *message_info_load(CamelFolderSummary *s, FILE *in);
 static CamelMessageInfo *message_info_new_from_header(CamelFolderSummary *, struct _camel_header_raw *);
 static void message_info_free(CamelFolderSummary *, CamelMessageInfo *mi);
@@ -63,12 +61,6 @@ static gchar *maildir_summary_next_uid_string(CamelFolderSummary *s);
 static gint maildir_summary_decode_x_evolution(CamelLocalSummary *cls, const gchar *xev, CamelLocalMessageInfo *mi);
 static gchar *maildir_summary_encode_x_evolution(CamelLocalSummary *cls, const CamelLocalMessageInfo *mi);
 
-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);
-
-#define _PRIVATE(x) (((CamelMaildirSummary *)(x))->priv)
-
 struct _CamelMaildirSummaryPrivate {
 	gchar *current_file;
 	gchar *hostname;
@@ -77,77 +69,91 @@ struct _CamelMaildirSummaryPrivate {
 	GMutex *summary_lock;
 };
 
-static CamelLocalSummaryClass *parent_class;
+static gpointer parent_class;
 
-CamelType
-camel_maildir_summary_get_type (void)
+static void
+maildir_summary_finalize (GObject *object)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_local_summary_get_type (), "CamelMaildirSummary",
-					   sizeof(CamelMaildirSummary),
-					   sizeof(CamelMaildirSummaryClass),
-					   (CamelObjectClassInitFunc)camel_maildir_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc)camel_maildir_summary_init,
-					   (CamelObjectFinalizeFunc)camel_maildir_summary_finalise);
-	}
+	CamelMaildirSummaryPrivate *priv;
 
-	return type;
+	priv = CAMEL_MAILDIR_SUMMARY_GET_PRIVATE (object);
+
+	g_free (priv->hostname);
+	g_mutex_free (priv->summary_lock);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_maildir_summary_class_init (CamelMaildirSummaryClass *class)
+maildir_summary_class_init (CamelMaildirSummaryClass *class)
 {
-	CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) class;
-	CamelLocalSummaryClass *lklass = (CamelLocalSummaryClass *)class;
-
-	parent_class = (CamelLocalSummaryClass *)camel_type_get_global_classfuncs(camel_local_summary_get_type ());
-
-	/* override methods */
-	sklass->message_info_load = message_info_load;
-	sklass->message_info_new_from_header = message_info_new_from_header;
-	sklass->message_info_free = message_info_free;
-	sklass->next_uid_string = maildir_summary_next_uid_string;
-
-	lklass->load = maildir_summary_load;
-	lklass->check = maildir_summary_check;
-	lklass->sync = maildir_summary_sync;
-	lklass->add = maildir_summary_add;
-	lklass->encode_x_evolution = maildir_summary_encode_x_evolution;
-	lklass->decode_x_evolution = maildir_summary_decode_x_evolution;
+	GObjectClass *object_class;
+	CamelFolderSummaryClass *folder_summary_class;
+	CamelLocalSummaryClass *local_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelMaildirSummaryPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = maildir_summary_finalize;
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->message_info_load = message_info_load;
+	folder_summary_class->message_info_new_from_header = message_info_new_from_header;
+	folder_summary_class->message_info_free = message_info_free;
+	folder_summary_class->next_uid_string = maildir_summary_next_uid_string;
+
+	local_summary_class = CAMEL_LOCAL_SUMMARY_CLASS (class);
+	local_summary_class->load = maildir_summary_load;
+	local_summary_class->check = maildir_summary_check;
+	local_summary_class->sync = maildir_summary_sync;
+	local_summary_class->add = maildir_summary_add;
+	local_summary_class->encode_x_evolution = maildir_summary_encode_x_evolution;
+	local_summary_class->decode_x_evolution = maildir_summary_decode_x_evolution;
 }
 
 static void
-camel_maildir_summary_init (CamelMaildirSummary *o)
+maildir_summary_init (CamelMaildirSummary *maildir_summary)
 {
-	struct _CamelFolderSummary *s = (CamelFolderSummary *) o;
+	CamelFolderSummary *folder_summary;
 	gchar hostname[256];
 
-	o->priv = g_malloc0(sizeof(*o->priv));
+	folder_summary = CAMEL_FOLDER_SUMMARY (maildir_summary);
+
+	maildir_summary->priv =
+		CAMEL_MAILDIR_SUMMARY_GET_PRIVATE (maildir_summary);
+
 	/* set unique file version */
-	s->version += CAMEL_MAILDIR_SUMMARY_VERSION;
+	folder_summary->version += CAMEL_MAILDIR_SUMMARY_VERSION;
 
-	s->message_info_size = sizeof(CamelMaildirMessageInfo);
-	s->content_info_size = sizeof(CamelMaildirMessageContentInfo);
+	folder_summary->message_info_size = sizeof (CamelMaildirMessageInfo);
+	folder_summary->content_info_size = sizeof (CamelMaildirMessageContentInfo);
 
 	if (gethostname(hostname, 256) == 0) {
-		o->priv->hostname = g_strdup(hostname);
+		maildir_summary->priv->hostname = g_strdup(hostname);
 	} else {
-		o->priv->hostname = g_strdup("localhost");
+		maildir_summary->priv->hostname = g_strdup("localhost");
 	}
-	o->priv->summary_lock = g_mutex_new ();
+	maildir_summary->priv->summary_lock = g_mutex_new ();
 }
 
-static void
-camel_maildir_summary_finalise(CamelObject *obj)
+GType
+camel_maildir_summary_get_type (void)
 {
-	CamelMaildirSummary *o = (CamelMaildirSummary *)obj;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_SUMMARY,
+			"CamelMaildirSummary",
+			sizeof (CamelMaildirSummaryClass),
+			(GClassInitFunc) maildir_summary_class_init,
+			sizeof (CamelMaildirSummary),
+			(GInstanceInitFunc) maildir_summary_init,
+			0);
 
-	g_free(o->priv->hostname);
-	g_mutex_free (o->priv->summary_lock);
-	g_free(o->priv);
+	return type;
 }
 
 /**
@@ -163,8 +169,9 @@ camel_maildir_summary_finalise(CamelObject *obj)
 CamelMaildirSummary
 *camel_maildir_summary_new(struct _CamelFolder *folder, const gchar *filename, const gchar *maildirdir, CamelIndex *index)
 {
-	CamelMaildirSummary *o = (CamelMaildirSummary *)camel_object_new(camel_maildir_summary_get_type ());
+	CamelMaildirSummary *o;
 
+	o = g_object_new (CAMEL_TYPE_MAILDIR_SUMMARY, NULL);
 	((CamelFolderSummary *)o)->folder = folder;
 	if (folder) {
 		camel_db_set_collate (folder->parent_store->cdb_r, "dreceived", NULL, NULL);
@@ -494,7 +501,7 @@ camel_maildir_summary_add (CamelLocalSummary *cls, const gchar *name, gint force
 	}
 	maildirs->priv->current_file = (gchar *)name;
 	camel_folder_summary_add_from_parser((CamelFolderSummary *)maildirs, mp);
-	camel_object_unref((CamelObject *)mp);
+	g_object_unref (mp);
 	maildirs->priv->current_file = NULL;
 	camel_folder_summary_set_index((CamelFolderSummary *)maildirs, NULL);
 	g_free(filename);
diff --git a/camel/providers/local/camel-maildir-summary.h b/camel/providers/local/camel-maildir-summary.h
index 223769e..3faf340 100644
--- a/camel/providers/local/camel-maildir-summary.h
+++ b/camel/providers/local/camel-maildir-summary.h
@@ -18,22 +18,37 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MAILDIR_SUMMARY_H
-#define _CAMEL_MAILDIR_SUMMARY_H
+#ifndef CAMEL_MAILDIR_SUMMARY_H
+#define CAMEL_MAILDIR_SUMMARY_H
+
+#include <camel/camel.h>
 
 #include "camel-local-summary.h"
-#include <camel/camel-folder.h>
-#include <camel/camel-exception.h>
-#include <camel/camel-index.h>
 
-#define CAMEL_MAILDIR_SUMMARY(obj)	CAMEL_CHECK_CAST (obj, camel_maildir_summary_get_type (), CamelMaildirSummary)
-#define CAMEL_MAILDIR_SUMMARY_CLASS(klass)	CAMEL_CHECK_CLASS_CAST (klass, camel_maildir_summary_get_type (), CamelMaildirSummaryClass)
-#define CAMEL_IS_MAILDIR_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_maildir_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MAILDIR_SUMMARY \
+	(camel_maildir_summary_get_type ())
+#define CAMEL_MAILDIR_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MAILDIR_SUMMARY, CamelMaildirSummary))
+#define CAMEL_MAILDIR_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MAILDIR_SUMMARY, CamelMaildirSummaryClass))
+#define CAMEL_IS_MAILDIR_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MAILDIR_SUMMARY))
+#define CAMEL_IS_MAILDIR_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MAILDIR_SUMMARY))
+#define CAMEL_MAILDIR_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MAILDIR_SUMMARY, CamelMaildirSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMaildirSummary	CamelMaildirSummary;
-typedef struct _CamelMaildirSummaryClass	CamelMaildirSummaryClass;
+typedef struct _CamelMaildirSummary CamelMaildirSummary;
+typedef struct _CamelMaildirSummaryClass CamelMaildirSummaryClass;
+typedef struct _CamelMaildirSummaryPrivate CamelMaildirSummaryPrivate;
 
 typedef struct _CamelMaildirMessageContentInfo {
 	CamelMessageContentInfo info;
@@ -52,18 +67,14 @@ typedef struct _CamelMaildirMessageInfo {
 
 struct _CamelMaildirSummary {
 	CamelLocalSummary parent;
-	struct _CamelMaildirSummaryPrivate *priv;
+	CamelMaildirSummaryPrivate *priv;
 };
 
 struct _CamelMaildirSummaryClass {
 	CamelLocalSummaryClass parent_class;
-
-	/* virtual methods */
-
-	/* signals */
 };
 
-CamelType	 camel_maildir_summary_get_type	(void);
+GType	 camel_maildir_summary_get_type	(void);
 CamelMaildirSummary	*camel_maildir_summary_new	(struct _CamelFolder *folder, const gchar *filename, const gchar *maildirdir, CamelIndex *index);
 
 /* convert some info->flags to/from the messageinfo */
@@ -76,4 +87,4 @@ gint camel_maildir_summary_name_to_info(CamelMaildirMessageInfo *info, const gch
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MAILDIR_SUMMARY_H */
+#endif /* CAMEL_MAILDIR_SUMMARY_H */
diff --git a/camel/providers/local/camel-mbox-folder.c b/camel/providers/local/camel-mbox-folder.c
index c6f28cb..149114c 100644
--- a/camel/providers/local/camel-mbox-folder.c
+++ b/camel/providers/local/camel-mbox-folder.c
@@ -33,22 +33,9 @@
 #include <sys/types.h>
 #include <inttypes.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "camel/camel-data-wrapper.h"
-#include "camel/camel-exception.h"
-#include "camel/camel-mime-filter-from.h"
-#include "camel/camel-mime-message.h"
-#include "camel/camel-mime-part-utils.h"
-#include "camel/camel-private.h"
-#include "camel/camel-stream-filter.h"
-#include "camel/camel-stream-fs.h"
-#include <camel/camel-stream-mem.h>
-#include <camel/camel-stream-buffer.h>
-#include <camel/camel-multipart.h>
-
 #include "camel-mbox-folder.h"
 #include "camel-mbox-store.h"
 #include "camel-mbox-summary.h"
@@ -59,12 +46,7 @@
 
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
 
-static CamelLocalFolderClass *parent_class = NULL;
-
-/* Returns the class for a CamelMboxFolder */
-#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CMBOXS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static gint mbox_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex);
 static void mbox_unlock(CamelLocalFolder *lf);
@@ -76,62 +58,49 @@ 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
-camel_mbox_folder_class_init(CamelMboxFolderClass * camel_mbox_folder_class)
+mbox_folder_class_init (CamelMboxFolderClass *class)
 {
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS(camel_mbox_folder_class);
-	CamelLocalFolderClass *lclass = (CamelLocalFolderClass *)camel_mbox_folder_class;
-
-	parent_class = (CamelLocalFolderClass *)camel_type_get_global_classfuncs(camel_local_folder_get_type());
-
-	/* virtual method definition */
-
-	/* virtual method overload */
-	camel_folder_class->append_message = mbox_append_message;
-	camel_folder_class->get_message = mbox_get_message;
-	camel_folder_class->get_filename = mbox_get_filename;
-	camel_folder_class->cmp_uids = mbox_cmp_uids;
-	camel_folder_class->sort_uids = mbox_sort_uids;
-
-	lclass->create_summary = mbox_create_summary;
-	lclass->lock = mbox_lock;
-	lclass->unlock = mbox_unlock;
+	CamelFolderClass *folder_class;
+	CamelLocalFolderClass *local_folder_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->append_message = mbox_append_message;
+	folder_class->get_message = mbox_get_message;
+	folder_class->get_filename = mbox_get_filename;
+	folder_class->cmp_uids = mbox_cmp_uids;
+	folder_class->sort_uids = mbox_sort_uids;
+
+	local_folder_class = CAMEL_LOCAL_FOLDER_CLASS (class);
+	local_folder_class->create_summary = mbox_create_summary;
+	local_folder_class->lock = mbox_lock;
+	local_folder_class->unlock = mbox_unlock;
 }
 
 static void
-mbox_init(gpointer object, gpointer klass)
+mbox_folder_init (CamelMboxFolder *mbox_folder)
 {
-	/*CamelFolder *folder = object;*/
-	CamelMboxFolder *mbox_folder = object;
-
 	mbox_folder->lockfd = -1;
 }
 
-static void
-mbox_finalise(CamelObject * object)
+GType
+camel_mbox_folder_get_type (void)
 {
-	CamelMboxFolder *mbox_folder = (CamelMboxFolder *)object;
-
-	g_assert(mbox_folder->lockfd == -1);
-}
-
-CamelType camel_mbox_folder_get_type(void)
-{
-	static CamelType camel_mbox_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_mbox_folder_type == CAMEL_INVALID_TYPE) {
-		camel_mbox_folder_type = camel_type_register(CAMEL_LOCAL_FOLDER_TYPE, "CamelMboxFolder",
-							     sizeof(CamelMboxFolder),
-							     sizeof(CamelMboxFolderClass),
-							     (CamelObjectClassInitFunc) camel_mbox_folder_class_init,
-							     NULL,
-							     (CamelObjectInitFunc) mbox_init,
-							     (CamelObjectFinalizeFunc) mbox_finalise);
-	}
-
-	return camel_mbox_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_FOLDER,
+			"CamelMboxFolder",
+			sizeof (CamelMboxFolderClass),
+			(GClassInitFunc) mbox_folder_class_init,
+			sizeof (CamelMboxFolder),
+			(GInstanceInitFunc) mbox_folder_init,
+			0);
+
+	return type;
 }
 
 CamelFolder *
@@ -141,7 +110,7 @@ camel_mbox_folder_new(CamelStore *parent_store, const gchar *full_name, guint32
 
 	d(printf("Creating mbox folder: %s in %s\n", full_name, camel_local_store_get_toplevel_dir((CamelLocalStore *)parent_store)));
 
-	folder = (CamelFolder *)camel_object_new(CAMEL_MBOX_FOLDER_TYPE);
+	folder = g_object_new (CAMEL_TYPE_MBOX_FOLDER, NULL);
 	folder = (CamelFolder *)camel_local_folder_construct((CamelLocalFolder *)folder,
 							     parent_store, full_name, flags, ex);
 
@@ -251,10 +220,10 @@ mbox_append_message(CamelFolder *folder, CamelMimeMessage * message, const Camel
 		goto fail_write;
 
 	/* and write the content to the filtering stream, that translates '\nFrom' into '\n>From' */
-	filter_stream = (CamelStream *) camel_stream_filter_new_with_stream(output_stream);
-	filter_from = (CamelMimeFilter *) camel_mime_filter_from_new();
+	filter_stream = camel_stream_filter_new (output_stream);
+	filter_from = camel_mime_filter_from_new();
 	camel_stream_filter_add((CamelStreamFilter *) filter_stream, filter_from);
-	camel_object_unref (filter_from);
+	g_object_unref (filter_from);
 
 	if (camel_data_wrapper_write_to_stream ((CamelDataWrapper *) message, filter_stream) == -1 ||
 	    camel_stream_write (filter_stream, "\n", 1) == -1 ||
@@ -262,8 +231,8 @@ mbox_append_message(CamelFolder *folder, CamelMimeMessage * message, const Camel
 		goto fail_write;
 
 	/* filter stream ref's the output stream itself, so we need to unref it too */
-	camel_object_unref (filter_stream);
-	camel_object_unref (output_stream);
+	g_object_unref (filter_stream);
+	g_object_unref (output_stream);
 	g_free(fromline);
 
 	if (!((CamelMessageInfoBase *)mi)->preview && camel_folder_summary_get_need_preview(folder->summary)) {
@@ -301,16 +270,20 @@ fail_write:
 				      lf->folder_path, g_strerror (errno));
 
 	if (output_stream) {
+		gint fd;
+
+		fd = camel_stream_fs_get_fd (CAMEL_STREAM_FS (output_stream));
+
 		/* reset the file to original size */
 		do {
-			retval = ftruncate (((CamelStreamFs *) output_stream)->fd, mbs->folder_size);
+			retval = ftruncate (fd, mbs->folder_size);
 		} while (retval == -1 && errno == EINTR);
 
-		camel_object_unref (output_stream);
+		g_object_unref (output_stream);
 	}
 
 	if (filter_stream)
-		camel_object_unref (filter_stream);
+		g_object_unref (filter_stream);
 
 	g_free(fromline);
 
@@ -450,7 +423,7 @@ retry:
 			  (glong)camel_mime_parser_tell_start_from(parser),
 			  camel_mime_parser_state(parser));
 
-		camel_object_unref((CamelObject *)parser);
+		g_object_unref (parser);
 		parser = NULL;
 
 		if (!retried) {
@@ -472,7 +445,7 @@ retry:
 		camel_exception_setv(ex, errno==EINTR?CAMEL_EXCEPTION_USER_CANCEL:CAMEL_EXCEPTION_SYSTEM,
 				     _("Cannot get message: %s from folder %s\n  %s"), uid, lf->folder_path,
 				     _("Message construction failed."));
-		camel_object_unref((CamelObject *)message);
+		g_object_unref (message);
 		message = NULL;
 		goto fail;
 	}
@@ -484,7 +457,7 @@ fail:
 	camel_local_folder_unlock(lf);
 
 	if (parser)
-		camel_object_unref((CamelObject *)parser);
+		g_object_unref (parser);
 
 	/* use the opportunity to notify of changes (particularly if we had a rebuild) */
 	if (camel_folder_change_info_changed(lf->changes)) {
diff --git a/camel/providers/local/camel-mbox-folder.h b/camel/providers/local/camel-mbox-folder.h
index e442133..89b03b7 100644
--- a/camel/providers/local/camel-mbox-folder.h
+++ b/camel/providers/local/camel-mbox-folder.h
@@ -20,37 +20,50 @@
  */
 
 #ifndef CAMEL_MBOX_FOLDER_H
-#define CAMEL_MBOX_FOLDER_H 1
+#define CAMEL_MBOX_FOLDER_H
 
 #include "camel-local-folder.h"
 #include "camel-mbox-summary.h"
 
-#define CAMEL_MBOX_FOLDER_TYPE     (camel_mbox_folder_get_type ())
-#define CAMEL_MBOX_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MBOX_FOLDER_TYPE, CamelMboxFolder))
-#define CAMEL_MBOX_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MBOX_FOLDER_TYPE, CamelMboxFolderClass))
-#define CAMEL_IS_MBOX_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MBOX_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MBOX_FOLDER \
+	(camel_mbox_folder_get_type ())
+#define CAMEL_MBOX_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MBOX_FOLDER, CamelMboxFolder))
+#define CAMEL_MBOX_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MBOX_FOLDER, CamelMboxFolderClass))
+#define CAMEL_IS_MBOX_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MBOX_FOLDER))
+#define CAMEL_IS_MBOX_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MBOX_FOLDER))
+#define CAMEL_MBOX_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MBOX_FOLDER, CamelMboxFolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelLocalFolder parent_object;
+typedef struct _CamelMboxFolder CamelMboxFolder;
+typedef struct _CamelMboxFolderClass CamelMboxFolderClass;
+
+struct _CamelMboxFolder {
+	CamelLocalFolder parent;
 
 	gint lockfd;		/* for when we have a lock on the folder */
-} CamelMboxFolder;
+};
 
-typedef struct {
+struct _CamelMboxFolderClass {
 	CamelLocalFolderClass parent_class;
-
-	/* Virtual methods */
-
-} CamelMboxFolderClass;
+};
 
 /* public methods */
 /* flags are taken from CAMEL_STORE_FOLDER_* flags */
 CamelFolder *camel_mbox_folder_new(CamelStore *parent_store, const gchar *full_name, guint32 flags, CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_mbox_folder_get_type(void);
+GType camel_mbox_folder_get_type(void);
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c
index 95ab871..03b6f8c 100644
--- a/camel/providers/local/camel-mbox-store.c
+++ b/camel/providers/local/camel-mbox-store.c
@@ -30,29 +30,17 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
 #include <libedataserver/e-data-server-util.h>
 
-#include "camel/camel-exception.h"
-#include "camel/camel-file-utils.h"
-#include "camel/camel-private.h"
-#include "camel/camel-text-index.h"
-#include "camel/camel-url.h"
-
 #include "camel-mbox-folder.h"
 #include "camel-mbox-store.h"
 
 #define d(x)
 
-static CamelLocalStoreClass *parent_class = NULL;
-
-/* Returns the class for a CamelMboxStore */
-#define CMBOXS_CLASS(so) CAMEL_MBOX_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS(CAMEL_OBJECT_GET_CLASS(so))
-#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS(CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static CamelFolder *get_folder(CamelStore *store, const gchar *folder_name, guint32 flags, CamelException *ex);
 static void delete_folder(CamelStore *store, const gchar *folder_name, CamelException *ex);
@@ -63,41 +51,42 @@ static gchar *mbox_get_meta_path(CamelLocalStore *ls, const gchar *full_name, co
 static gchar *mbox_get_full_path(CamelLocalStore *ls, const gchar *full_name);
 
 static void
-camel_mbox_store_class_init(CamelMboxStoreClass *camel_mbox_store_class)
+mbox_store_class_init (CamelMboxStoreClass *class)
 {
-	CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS(camel_mbox_store_class);
-
-	parent_class =(CamelLocalStoreClass *)camel_type_get_global_classfuncs(camel_local_store_get_type());
-
-	/* virtual method overload */
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->delete_folder = delete_folder;
-	camel_store_class->rename_folder = rename_folder;
-	camel_store_class->create_folder = create_folder;
-
-	camel_store_class->get_folder_info = get_folder_info;
-	camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-
-	((CamelLocalStoreClass *)camel_store_class)->get_full_path = mbox_get_full_path;
-	((CamelLocalStoreClass *)camel_store_class)->get_meta_path = mbox_get_meta_path;
+	CamelStoreClass *store_class;
+	CamelLocalStoreClass *local_store_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_folder = get_folder;
+	store_class->delete_folder = delete_folder;
+	store_class->rename_folder = rename_folder;
+	store_class->create_folder = create_folder;
+	store_class->get_folder_info = get_folder_info;
+	store_class->free_folder_info = camel_store_free_folder_info_full;
+
+	local_store_class = CAMEL_LOCAL_STORE_CLASS (class);
+	local_store_class->get_full_path = mbox_get_full_path;
+	local_store_class->get_meta_path = mbox_get_meta_path;
 }
 
-CamelType
-camel_mbox_store_get_type(void)
+GType
+camel_mbox_store_get_type (void)
 {
-	static CamelType camel_mbox_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_mbox_store_type == CAMEL_INVALID_TYPE)	{
-		camel_mbox_store_type = camel_type_register(CAMEL_LOCAL_STORE_TYPE, "CamelMboxStore",
-							    sizeof(CamelMboxStore),
-							    sizeof(CamelMboxStoreClass),
-							    (CamelObjectClassInitFunc) camel_mbox_store_class_init,
-							    NULL,
-							    NULL,
-							    NULL);
-	}
-
-	return camel_mbox_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_STORE,
+			"CamelMboxStore",
+			sizeof (CamelMboxStoreClass),
+			(GClassInitFunc) mbox_store_class_init,
+			sizeof (CamelMboxStore),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 static const gchar *extensions[] = {
@@ -311,7 +300,7 @@ delete_folder(CamelStore *store, const gchar *folder_name, CamelException *ex)
 	if ((lf = camel_store_get_folder(store, folder_name, 0, &lex))) {
 		camel_object_get(lf, NULL, CAMEL_OBJECT_STATE_FILE, &path, NULL);
 		camel_object_set(lf, NULL, CAMEL_OBJECT_STATE_FILE, NULL, NULL);
-		camel_object_unref(lf);
+		g_object_unref (lf);
 	} else {
 		camel_exception_clear(&lex);
 	}
@@ -401,10 +390,10 @@ create_folder(CamelStore *store, const gchar *parent_name, const gchar *folder_n
 
 	g_free(path);
 
-	folder =((CamelStoreClass *)((CamelObject *) store)->klass)->get_folder(store, name, CAMEL_STORE_FOLDER_CREATE, ex);
+	folder = CAMEL_STORE_GET_CLASS (store)->get_folder (store, name, CAMEL_STORE_FOLDER_CREATE, ex);
 	if (folder) {
-		camel_object_unref(folder);
-		info =((CamelStoreClass *)((CamelObject *) store)->klass)->get_folder_info(store, name, 0, ex);
+		g_object_unref (folder);
+		info = CAMEL_STORE_GET_CLASS (store)->get_folder_info (store, name, 0, ex);
 	}
 
 	g_free(name);
@@ -551,7 +540,7 @@ rename_folder(CamelStore *store, const gchar *old, const gchar *new, CamelExcept
 	g_free(newibex);
 
 	if (folder)
-		camel_object_unref(folder);
+		g_object_unref (folder);
 
 	return;
 
@@ -583,7 +572,7 @@ ibex_failed:
 	g_free(oldibex);
 
 	if (folder)
-		camel_object_unref(folder);
+		g_object_unref (folder);
 }
 
 /* used to find out where we've visited already */
@@ -628,7 +617,7 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 			camel_folder_refresh_info(folder, NULL);
 		fi->unread = camel_folder_get_unread_message_count(folder);
 		fi->total = camel_folder_get_message_count(folder);
-		camel_object_unref(folder);
+		g_object_unref (folder);
 	} else {
 		gchar *path, *folderpath;
 		CamelMboxSummary *mbs;
@@ -644,7 +633,7 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 			fi->total = ((CamelFolderSummary *)mbs)->saved_count;
 		}
 
-		camel_object_unref(mbs);
+		g_object_unref (mbs);
 		g_free(folderpath);
 		g_free(path);
 	}
diff --git a/camel/providers/local/camel-mbox-store.h b/camel/providers/local/camel-mbox-store.h
index d697562..97cad66 100644
--- a/camel/providers/local/camel-mbox-store.h
+++ b/camel/providers/local/camel-mbox-store.h
@@ -20,31 +20,43 @@
  */
 
 #ifndef CAMEL_MBOX_STORE_H
-#define CAMEL_MBOX_STORE_H 1
+#define CAMEL_MBOX_STORE_H
 
 #include "camel-local-store.h"
 
-#define CAMEL_MBOX_STORE_TYPE     (camel_mbox_store_get_type ())
-#define CAMEL_MBOX_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MBOX_STORE_TYPE, CamelMboxStore))
-#define CAMEL_MBOX_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MBOX_STORE_TYPE, CamelMboxStoreClass))
-#define CAMEL_IS_MBOX_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MBOX_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MBOX_STORE \
+	(camel_mbox_store_get_type ())
+#define CAMEL_MBOX_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MBOX_STORE, CamelMboxStore))
+#define CAMEL_MBOX_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MBOX_STORE, CamelMboxStoreClass))
+#define CAMEL_IS_MBOX_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MBOX_STORE))
+#define CAMEL_IS_MBOX_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MBOX_STORE))
+#define CAMEL_MBOX_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MBOX_STORE, CamelMboxStoreClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelLocalStore parent_object;
+typedef struct _CamelMboxStore CamelMboxStore;
+typedef struct _CamelMboxStoreClass CamelMboxStoreClass;
 
-} CamelMboxStore;
+struct _CamelMboxStore {
+	CamelLocalStore parent;
+};
 
-typedef struct {
+struct _CamelMboxStoreClass {
 	CamelLocalStoreClass parent_class;
+};
 
-} CamelMboxStoreClass;
-
-/* public methods */
-
-/* Standard Camel function */
-CamelType camel_mbox_store_get_type (void);
+GType camel_mbox_store_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c
index 5b422ac..a86da80 100644
--- a/camel/providers/local/camel-mbox-summary.c
+++ b/camel/providers/local/camel-mbox-summary.c
@@ -32,20 +32,10 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "camel-db.h"
-#include "camel-file-utils.h"
-#include "camel-mime-message.h"
-#include "camel-operation.h"
-#include "camel-private.h"
-
 #include "camel-mbox-summary.h"
-#include "camel-string-utils.h"
-#include "camel-store.h"
-#include "camel-folder.h"
 #include "camel-local-private.h"
 
 #define io(x)
@@ -82,10 +72,6 @@ static CamelMessageInfo *mbox_summary_add(CamelLocalSummary *cls, CamelMimeMessa
 static gint mbox_summary_sync_quick(CamelMboxSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 static gint mbox_summary_sync_full(CamelMboxSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 
-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);
-
 #ifdef STATUS_PINE
 /* Which status flags are stored in each separate header */
 #define STATUS_XSTATUS (CAMEL_MESSAGE_FLAGGED|CAMEL_MESSAGE_ANSWERED|CAMEL_MESSAGE_DELETED)
@@ -95,31 +81,14 @@ static void encode_status(guint32 flags, gchar status[8]);
 static guint32 decode_status(const gchar *status);
 #endif
 
-static CamelLocalSummaryClass *camel_mbox_summary_parent;
-
-CamelType
-camel_mbox_summary_get_type(void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_local_summary_get_type(), "CamelMboxSummary",
-					   sizeof (CamelMboxSummary),
-					   sizeof (CamelMboxSummaryClass),
-					   (CamelObjectClassInitFunc) camel_mbox_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_mbox_summary_init,
-					   (CamelObjectFinalizeFunc) camel_mbox_summary_finalise);
-	}
+static gpointer parent_class;
 
-	return type;
-}
 static gboolean
 mbox_info_set_user_flag(CamelMessageInfo *mi, const gchar *name, gboolean value)
 {
 	gint res;
 
-	res = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->info_set_user_flag(mi, name, value);
+	res = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->info_set_user_flag(mi, name, value);
 	if (res)
 		((CamelLocalMessageInfo *)mi)->info.flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
 
@@ -131,7 +100,7 @@ mbox_info_set_user_tag(CamelMessageInfo *mi, const gchar *name, const gchar *val
 {
 	gint res;
 
-	res = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->info_set_user_tag(mi, name, value);
+	res = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->info_set_user_tag(mi, name, value);
 	if (res)
 		((CamelLocalMessageInfo *)mi)->info.flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
 
@@ -149,67 +118,80 @@ mbox_info_set_flags(CamelMessageInfo *mi, guint32 flags, guint32 set)
 		set |= CAMEL_MESSAGE_FOLDER_XEVCHANGE|CAMEL_MESSAGE_FOLDER_FLAGGED;
 	}
 
-	return ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->info_set_flags(mi, flags, set);
+	return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->info_set_flags(mi, flags, set);
 }
 #endif
 
 static void
-camel_mbox_summary_class_init(CamelMboxSummaryClass *klass)
+mbox_summary_class_init (CamelMboxSummaryClass *class)
 {
-	CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *)klass;
-	CamelLocalSummaryClass *lklass = (CamelLocalSummaryClass *)klass;
-
-	camel_mbox_summary_parent = (CamelLocalSummaryClass *)camel_type_get_global_classfuncs(camel_local_summary_get_type());
-
-	sklass->summary_header_load = summary_header_load;
-	sklass->summary_header_save = summary_header_save;
-
-	sklass->summary_header_from_db = summary_header_from_db;
-	sklass->summary_header_to_db = summary_header_to_db;
-	sklass->message_info_from_db = message_info_from_db;
-	sklass->message_info_to_db = message_info_to_db;
-
-	sklass->message_info_new_from_header  = message_info_new_from_header;
-	sklass->message_info_new_from_parser = message_info_new_from_parser;
-	sklass->message_info_load = message_info_load;
-	sklass->message_info_save = message_info_save;
-	sklass->meta_message_info_save = meta_message_info_save;
-	/*sklass->message_info_free = message_info_free;*/
-
-	sklass->info_set_user_flag = mbox_info_set_user_flag;
-	sklass->info_set_user_tag = mbox_info_set_user_tag;
+	CamelFolderSummaryClass *folder_summary_class;
+	CamelLocalSummaryClass *local_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->summary_header_load = summary_header_load;
+	folder_summary_class->summary_header_save = summary_header_save;
+	folder_summary_class->summary_header_from_db = summary_header_from_db;
+	folder_summary_class->summary_header_to_db = summary_header_to_db;
+	folder_summary_class->message_info_from_db = message_info_from_db;
+	folder_summary_class->message_info_to_db = message_info_to_db;
+	folder_summary_class->message_info_new_from_header  = message_info_new_from_header;
+	folder_summary_class->message_info_new_from_parser = message_info_new_from_parser;
+	folder_summary_class->message_info_load = message_info_load;
+	folder_summary_class->message_info_save = message_info_save;
+	folder_summary_class->meta_message_info_save = meta_message_info_save;
+	/*folder_summary_class->message_info_free = message_info_free;*/
+	folder_summary_class->info_set_user_flag = mbox_info_set_user_flag;
+	folder_summary_class->info_set_user_tag = mbox_info_set_user_tag;
 #ifdef STATUS_PINE
-	sklass->info_set_flags = mbox_info_set_flags;
+	folder_summary_class->info_set_flags = mbox_info_set_flags;
 #endif
 
-	lklass->encode_x_evolution = mbox_summary_encode_x_evolution;
-	lklass->check = mbox_summary_check;
-	lklass->sync = mbox_summary_sync;
+	local_summary_class = CAMEL_LOCAL_SUMMARY_CLASS (class);
+	local_summary_class->encode_x_evolution = mbox_summary_encode_x_evolution;
+	local_summary_class->check = mbox_summary_check;
+	local_summary_class->sync = mbox_summary_sync;
 #ifdef STATUS_PINE
-	lklass->add = mbox_summary_add;
+	local_summary_class->add = mbox_summary_add;
 #endif
 
-	klass->sync_quick = mbox_summary_sync_quick;
-	klass->sync_full = mbox_summary_sync_full;
+	class->sync_quick = mbox_summary_sync_quick;
+	class->sync_full = mbox_summary_sync_full;
 }
 
 static void
-camel_mbox_summary_init(CamelMboxSummary *obj)
+mbox_summary_init (CamelMboxSummary *mbox_summary)
 {
-	struct _CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *folder_summary;
+
+	folder_summary = CAMEL_FOLDER_SUMMARY (mbox_summary);
 
 	/* subclasses need to set the right instance data sizes */
-	s->message_info_size = sizeof(CamelMboxMessageInfo);
-	s->content_info_size = sizeof(CamelMboxMessageContentInfo);
+	folder_summary->message_info_size = sizeof (CamelMboxMessageInfo);
+	folder_summary->content_info_size = sizeof (CamelMboxMessageContentInfo);
 
 	/* and a unique file version */
-	s->version += CAMEL_MBOX_SUMMARY_VERSION;
+	folder_summary->version += CAMEL_MBOX_SUMMARY_VERSION;
 }
 
-static void
-camel_mbox_summary_finalise(CamelObject *obj)
+GType
+camel_mbox_summary_get_type (void)
 {
-	/*CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(obj);*/
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_SUMMARY,
+			"CamelMboxSummary",
+			sizeof (CamelMboxSummaryClass),
+			(GClassInitFunc) mbox_summary_class_init,
+			sizeof (CamelMboxSummary),
+			(GInstanceInitFunc) mbox_summary_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -222,8 +204,9 @@ camel_mbox_summary_finalise(CamelObject *obj)
 CamelMboxSummary *
 camel_mbox_summary_new(struct _CamelFolder *folder, const gchar *filename, const gchar *mbox_name, CamelIndex *index)
 {
-	CamelMboxSummary *new = (CamelMboxSummary *)camel_object_new(camel_mbox_summary_get_type());
+	CamelMboxSummary *new;
 
+	new = g_object_new (CAMEL_TYPE_MBOX_SUMMARY, NULL);
 	((CamelFolderSummary *)new)->folder = folder;
 	if (folder) {
 		CamelFolderSummary *summary = (CamelFolderSummary *)new;
@@ -267,7 +250,7 @@ summary_header_from_db (CamelFolderSummary *s, struct _CamelFIRecord *fir)
 	CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s);
 	gchar *part;
 
-	((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_from_db(s, fir);
+	CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_from_db(s, fir);
 
 	part = fir->bdata;
 	if (part) {
@@ -283,7 +266,7 @@ summary_header_load(CamelFolderSummary *s, FILE *in)
 {
 	CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s);
 
-	if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load(s, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load(s, in) == -1)
 		return -1;
 
 	/* legacy version */
@@ -305,7 +288,7 @@ summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 	struct _CamelFIRecord *fir;
 	gchar *tmp;
 
-	fir = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_to_db (s, ex);
+	fir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_to_db (s, ex);
 	if (fir) {
 		tmp = fir->bdata;
 		fir->bdata = g_strdup_printf ("%s %d %d", tmp ? tmp : "", CAMEL_MBOX_SUMMARY_VERSION, (gint) mbs->folder_size);
@@ -320,7 +303,7 @@ summary_header_save(CamelFolderSummary *s, FILE *out)
 {
 	CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s);
 
-	if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_save(s, out) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_save(s, out) == -1)
 		return -1;
 
 	camel_file_util_encode_fixed_int32(out, CAMEL_MBOX_SUMMARY_VERSION);
@@ -334,7 +317,7 @@ message_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
 	CamelMboxMessageInfo *mi;
 	CamelMboxSummary *mbs = (CamelMboxSummary *)s;
 
-	mi = (CamelMboxMessageInfo *)((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new_from_header(s, h);
+	mi = (CamelMboxMessageInfo *)CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_new_from_header(s, h);
 	if (mi) {
 		const gchar *xev, *uid;
 		CamelMboxMessageInfo *info = NULL;
@@ -414,7 +397,7 @@ message_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser *mp)
 {
 	CamelMessageInfo *mi;
 
-	mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new_from_parser(s, mp);
+	mi = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_new_from_parser(s, mp);
 	if (mi) {
 		CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
 
@@ -430,7 +413,7 @@ message_info_from_db(CamelFolderSummary *s, struct _CamelMIRecord *mir)
 	CamelMessageInfo *mi;
 	gchar *part;
 
-	mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_from_db(s, mir);
+	mi = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_from_db(s, mir);
 
 	if (mi) {
 		CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
@@ -450,7 +433,7 @@ message_info_load(CamelFolderSummary *s, FILE *in)
 
 	io(printf("loading mbox message info\n"));
 
-	mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load(s, in);
+	mi = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load(s, in);
 	if (mi) {
 		CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
 
@@ -471,7 +454,7 @@ meta_message_info_save(CamelFolderSummary *s, FILE *out_meta, FILE *out, CamelMe
 
 	io(printf("saving mbox message info\n"));
 
-	if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->meta_message_info_save(s, out_meta, out, mi) == -1
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->meta_message_info_save(s, out_meta, out, mi) == -1
 	    || camel_file_util_encode_off_t(out_meta, mbi->frompos) == -1)
 		return -1;
 
@@ -484,7 +467,7 @@ message_info_to_db(CamelFolderSummary *s, CamelMessageInfo *info)
 	CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)info;
 	struct _CamelMIRecord *mir;
 
-	mir = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_to_db(s, info);
+	mir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_to_db(s, info);
 	mir->bdata = g_strdup_printf("%lu", mbi->frompos);
 
 	return mir;
@@ -497,7 +480,7 @@ message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi)
 
 	io(printf("saving mbox message info\n"));
 
-	if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_save(s, out, mi) == -1
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_save(s, out, mi) == -1
 	    || camel_file_util_encode_off_t (out, mbi->frompos) == -1)
 		return -1;
 
@@ -588,7 +571,7 @@ summary_update(CamelLocalSummary *cls, off_t offset, CamelFolderChangeInfo *chan
 		g_assert(camel_mime_parser_step(mp, NULL, NULL) == CAMEL_MIME_PARSER_STATE_FROM_END);
 	}
 
-	camel_object_unref(CAMEL_OBJECT (mp));
+	g_object_unref (CAMEL_OBJECT (mp));
 
 	count = camel_folder_summary_count(s);
 	for (i=0;i<count;i++) {
@@ -851,7 +834,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,
@@ -961,7 +944,7 @@ mbox_summary_sync_quick(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChan
 
 	g_ptr_array_foreach (summary, (GFunc) camel_pstring_free, NULL);
 	g_ptr_array_free (summary, TRUE);
-	camel_object_unref((CamelObject *)mp);
+	g_object_unref (mp);
 
 	camel_operation_end(NULL);
 
@@ -972,7 +955,7 @@ mbox_summary_sync_quick(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChan
 	if (fd != -1)
 		close(fd);
 	if (mp)
-		camel_object_unref((CamelObject *)mp);
+		g_object_unref (mp);
 	if (info)
 		camel_message_info_free((CamelMessageInfo *)info);
 
@@ -1026,7 +1009,7 @@ mbox_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInf
 	ret = -1;
 	if (quick) {
 		if (work) {
-			ret = ((CamelMboxSummaryClass *)((CamelObject *)cls)->klass)->sync_quick(mbs, expunge, changeinfo, ex);
+			ret = CAMEL_MBOX_SUMMARY_GET_CLASS (cls)->sync_quick (mbs, expunge, changeinfo, ex);
 			if (ret == -1) {
 				g_warning("failed a quick-sync, trying a full sync");
 				camel_exception_clear(ex);
@@ -1037,7 +1020,7 @@ mbox_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInf
 	}
 
 	if (ret == -1)
-		ret = ((CamelMboxSummaryClass *)((CamelObject *)cls)->klass)->sync_full(mbs, expunge, changeinfo, ex);
+		ret = CAMEL_MBOX_SUMMARY_GET_CLASS (cls)->sync_full (mbs, expunge, changeinfo, ex);
 	if (ret == -1)
 		return -1;
 
@@ -1053,7 +1036,7 @@ mbox_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInf
 		camel_folder_summary_touch(s);
 	}
 
-	return ((CamelLocalSummaryClass *)camel_mbox_summary_parent)->sync(cls, expunge, changeinfo, ex);
+	return CAMEL_LOCAL_SUMMARY_CLASS (parent_class)->sync(cls, expunge, changeinfo, ex);
 }
 
 gint
@@ -1234,7 +1217,7 @@ camel_mbox_summary_sync_mbox(CamelMboxSummary *cls, guint32 flags, CamelFolderCh
 		write(fdout, "\n", 1);
 #endif
 
-	camel_object_unref((CamelObject *)mp);
+	g_object_unref (mp);
 
 	/* clear working flags */
 	for (i=0; i<count; i++) {
@@ -1259,7 +1242,7 @@ camel_mbox_summary_sync_mbox(CamelMboxSummary *cls, guint32 flags, CamelFolderCh
 	g_free(xevnew);
 
 	if (mp)
-		camel_object_unref((CamelObject *)mp);
+		g_object_unref (mp);
 	if (info)
 		camel_message_info_free((CamelMessageInfo *)info);
 
@@ -1272,7 +1255,7 @@ mbox_summary_add(CamelLocalSummary *cls, CamelMimeMessage *msg, const CamelMessa
 {
 	CamelMboxMessageInfo *mi;
 
-	mi = (CamelMboxMessageInfo *)((CamelLocalSummaryClass *)camel_mbox_summary_parent)->add(cls, msg, info, ci, ex);
+	mi = (CamelMboxMessageInfo *)CAMEL_LOCAL_SUMMARY_CLASS (parent_class)->add(cls, msg, info, ci, ex);
 	if (mi && ((CamelMboxSummary *)cls)->xstatus) {
 		gchar status[8];
 
diff --git a/camel/providers/local/camel-mbox-summary.h b/camel/providers/local/camel-mbox-summary.h
index 2fca130..5b4f95c 100644
--- a/camel/providers/local/camel-mbox-summary.h
+++ b/camel/providers/local/camel-mbox-summary.h
@@ -18,21 +18,36 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MBOX_SUMMARY_H
-#define _CAMEL_MBOX_SUMMARY_H
+#ifndef CAMEL_MBOX_SUMMARY_H
+#define CAMEL_MBOX_SUMMARY_H
 
 #include "camel-local-summary.h"
 
 /* Enable the use of elm/pine style "Status" & "X-Status" headers */
 #define STATUS_PINE
 
-#define CAMEL_MBOX_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_mbox_summary_get_type (), CamelMboxSummary)
-#define CAMEL_MBOX_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mbox_summary_get_type (), CamelMboxSummaryClass)
-#define CAMEL_IS_MBOX_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_mbox_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MBOX_SUMMARY \
+	(camel_mbox_summary_get_type ())
+#define CAMEL_MBOX_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MBOX_SUMMARY, CamelMboxSummary))
+#define CAMEL_MBOX_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MBOX_SUMMARY, CamelMboxSummaryClass))
+#define CAMEL_IS_MBOX_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MBOX_SUMMARY))
+#define CAMEL_IS_MBOX_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MBOX_SUMMARY))
+#define CAMEL_MBOX_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MBOX_SUMMARY, CamelMboxSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMboxSummary      CamelMboxSummary;
+typedef struct _CamelMboxSummary CamelMboxSummary;
 typedef struct _CamelMboxSummaryClass CamelMboxSummaryClass;
 
 typedef struct _CamelMboxMessageContentInfo {
@@ -65,7 +80,7 @@ struct _CamelMboxSummaryClass {
 	gint (*sync_full)(CamelMboxSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 };
 
-CamelType		camel_mbox_summary_get_type	(void);
+GType		camel_mbox_summary_get_type	(void);
 CamelMboxSummary      *camel_mbox_summary_new	(struct _CamelFolder *, const gchar *filename, const gchar *mbox_name, CamelIndex *index);
 
 /* do we honour/use xstatus headers, etc */
@@ -76,4 +91,4 @@ gint camel_mbox_summary_sync_mbox(CamelMboxSummary *cls, guint32 flags, CamelFol
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MBOX_SUMMARY_H */
+#endif /* CAMEL_MBOX_SUMMARY_H */
diff --git a/camel/providers/local/camel-mh-folder.c b/camel/providers/local/camel-mh-folder.c
index d4f2779..361f596 100644
--- a/camel/providers/local/camel-mh-folder.c
+++ b/camel/providers/local/camel-mh-folder.c
@@ -34,22 +34,12 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-data-wrapper.h"
-#include "camel-exception.h"
 #include "camel-mh-folder.h"
-#include "camel-mh-store.h"
 #include "camel-mh-summary.h"
-#include "camel-mime-message.h"
-#include "camel-stream-fs.h"
 
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
 
-static CamelLocalFolderClass *parent_class = NULL;
-
-/* Returns the class for a CamelMhFolder */
-#define CMHF_CLASS(so) CAMEL_MH_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CMHS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static CamelLocalSummary *mh_create_summary(CamelLocalFolder *lf, const gchar *path, const gchar *folder, CamelIndex *index);
 
@@ -57,51 +47,39 @@ static void mh_append_message(CamelFolder * folder, CamelMimeMessage * message,
 static CamelMimeMessage *mh_get_message(CamelFolder * folder, const gchar * uid, CamelException * ex);
 static gchar * mh_get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex);
 
-static void mh_finalize(CamelObject * object);
-
-static void camel_mh_folder_class_init(CamelObjectClass * camel_mh_folder_class)
+static void
+mh_folder_class_init (CamelObjectClass *class)
 {
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS(camel_mh_folder_class);
-	CamelLocalFolderClass *lclass = (CamelLocalFolderClass *)camel_mh_folder_class;
-
-	parent_class = CAMEL_LOCAL_FOLDER_CLASS (camel_type_get_global_classfuncs(camel_local_folder_get_type()));
-
-	/* virtual method definition */
-
-	/* virtual method overload */
-	camel_folder_class->append_message = mh_append_message;
-	camel_folder_class->get_message = mh_get_message;
-	camel_folder_class->get_filename = mh_get_filename;
+	CamelFolderClass *folder_class;
+	CamelLocalFolderClass *local_folder_class;
 
-	lclass->create_summary = mh_create_summary;
-}
+	parent_class = g_type_class_peek_parent (class);
 
-static void mh_init(gpointer object, gpointer klass)
-{
-	/*CamelFolder *folder = object;
-	  CamelMhFolder *mh_folder = object;*/
-}
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->append_message = mh_append_message;
+	folder_class->get_message = mh_get_message;
+	folder_class->get_filename = mh_get_filename;
 
-static void mh_finalize(CamelObject * object)
-{
-	/*CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(object);*/
+	local_folder_class = CAMEL_LOCAL_FOLDER_CLASS (class);
+	local_folder_class->create_summary = mh_create_summary;
 }
 
-CamelType camel_mh_folder_get_type(void)
+GType
+camel_mh_folder_get_type (void)
 {
-	static CamelType camel_mh_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_mh_folder_type == CAMEL_INVALID_TYPE) {
-		camel_mh_folder_type = camel_type_register(CAMEL_LOCAL_FOLDER_TYPE, "CamelMhFolder",
-							   sizeof(CamelMhFolder),
-							   sizeof(CamelMhFolderClass),
-							   (CamelObjectClassInitFunc) camel_mh_folder_class_init,
-							   NULL,
-							   (CamelObjectInitFunc) mh_init,
-							   (CamelObjectFinalizeFunc) mh_finalize);
-	}
-
-	return camel_mh_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_FOLDER,
+			"CamelMhFolder",
+			sizeof (CamelMhFolderClass),
+			(GClassInitFunc) mh_folder_class_init,
+			sizeof (CamelMhFolder),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 CamelFolder *
@@ -111,7 +89,7 @@ camel_mh_folder_new(CamelStore *parent_store, const gchar *full_name, guint32 fl
 
 	d(printf("Creating mh folder: %s\n", full_name));
 
-	folder = (CamelFolder *)camel_object_new(CAMEL_MH_FOLDER_TYPE);
+	folder = g_object_new (CAMEL_TYPE_MH_FOLDER, NULL);
 	folder = (CamelFolder *)camel_local_folder_construct((CamelLocalFolder *)folder,
 							     parent_store, full_name, flags, ex);
 
@@ -160,7 +138,7 @@ mh_append_message (CamelFolder *folder, CamelMimeMessage *message, const CamelMe
 		goto fail_write;
 
 	/* close this? */
-	camel_object_unref (CAMEL_OBJECT (output_stream));
+	g_object_unref (CAMEL_OBJECT (output_stream));
 
 	g_free(name);
 
@@ -184,7 +162,7 @@ mh_append_message (CamelFolder *folder, CamelMimeMessage *message, const CamelMe
 				      name, g_strerror (errno));
 
 	if (output_stream) {
-		camel_object_unref (CAMEL_OBJECT (output_stream));
+		g_object_unref (CAMEL_OBJECT (output_stream));
 		unlink (name);
 	}
 
@@ -243,11 +221,11 @@ static CamelMimeMessage *mh_get_message(CamelFolder * folder, const gchar * uid,
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Cannot get message: %s from folder %s\n  %s"), name, lf->folder_path,
 				      _("Message construction failed."));
-		camel_object_unref((CamelObject *)message);
+		g_object_unref (message);
 		message = NULL;
 
 	}
-	camel_object_unref((CamelObject *)message_stream);
+	g_object_unref (message_stream);
 
  fail:
 	g_free (name);
diff --git a/camel/providers/local/camel-mh-folder.h b/camel/providers/local/camel-mh-folder.h
index 08f8f2c..9857a3e 100644
--- a/camel/providers/local/camel-mh-folder.h
+++ b/camel/providers/local/camel-mh-folder.h
@@ -21,34 +21,45 @@
  */
 
 #ifndef CAMEL_MH_FOLDER_H
-#define CAMEL_MH_FOLDER_H 1
+#define CAMEL_MH_FOLDER_H
 
 #include "camel-local-folder.h"
 
-#define CAMEL_MH_FOLDER_TYPE     (camel_mh_folder_get_type ())
-#define CAMEL_MH_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MH_FOLDER_TYPE, CamelMhFolder))
-#define CAMEL_MH_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MH_FOLDER_TYPE, CamelMhFolderClass))
-#define CAMEL_IS_MH_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MH_FOLDER_TYPE))
+#define CAMEL_TYPE_MH_FOLDER \
+	(camel_mh_folder_get_type ())
+#define CAMEL_MH_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MH_FOLDER, CamelMhFolder))
+#define CAMEL_MH_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MH_FOLDER, CamelMhFolderClass))
+#define CAMEL_IS_MH_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MH_FOLDER))
+#define CAMEL_IS_MH_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MH_FOLDER))
+#define CAMEL_MH_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MH_FOLDER, CamelMhFolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelLocalFolder parent_object;
+typedef struct _CamelMhFolder CamelMhFolder;
+typedef struct _CamelMhFolderClass CamelMhFolderClass;
 
-} CamelMhFolder;
+struct _CamelMhFolder {
+	CamelLocalFolder parent;
+};
 
-typedef struct {
+struct _CamelMhFolderClass {
 	CamelLocalFolderClass parent_class;
-
-	/* Virtual methods */
-
-} CamelMhFolderClass;
+};
 
 /* public methods */
 CamelFolder *camel_mh_folder_new(CamelStore *parent_store, const gchar *full_name, guint32 flags, CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_mh_folder_get_type(void);
+GType camel_mh_folder_get_type(void);
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-mh-store.c b/camel/providers/local/camel-mh-store.c
index 7d2a6b1..5741ac2 100644
--- a/camel/providers/local/camel-mh-store.c
+++ b/camel/providers/local/camel-mh-store.c
@@ -31,25 +31,14 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-exception.h"
-#include "camel-private.h"
-#include "camel-stream-buffer.h"
-#include "camel-stream-fs.h"
-#include "camel-url.h"
-
 #include "camel-mh-folder.h"
 #include "camel-mh-store.h"
 #include "camel-mh-summary.h"
 
-static CamelLocalStoreClass *parent_class = NULL;
+static gpointer parent_class;
 
 #define d(x)
 
-/* Returns the class for a CamelMhStore */
-#define CMHS_CLASS(so) CAMEL_MH_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CMHF_CLASS(so) CAMEL_MH_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
 static void construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex);
 static CamelFolder *get_folder(CamelStore * store, const gchar *folder_name, guint32 flags, CamelException * ex);
 static CamelFolder *get_inbox (CamelStore *store, CamelException *ex);
@@ -57,38 +46,41 @@ static void delete_folder(CamelStore * store, const gchar *folder_name, CamelExc
 static void rename_folder(CamelStore *store, const gchar *old, const gchar *new, CamelException *ex);
 static CamelFolderInfo * get_folder_info (CamelStore *store, const gchar *top, guint32 flags, CamelException *ex);
 
-static void camel_mh_store_class_init(CamelObjectClass * camel_mh_store_class)
+static void
+mh_store_class_init (CamelObjectClass *class)
 {
-	CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS(camel_mh_store_class);
-	CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS(camel_mh_store_class);
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
 
-	parent_class = (CamelLocalStoreClass *)camel_type_get_global_classfuncs(camel_local_store_get_type());
+	parent_class = g_type_class_peek_parent (class);
 
-	/* virtual method overload, use defaults for most */
-	camel_service_class->construct = construct;
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = construct;
 
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->get_inbox = get_inbox;
-	camel_store_class->delete_folder = delete_folder;
-	camel_store_class->rename_folder = rename_folder;
-	camel_store_class->get_folder_info = get_folder_info;
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_folder = get_folder;
+	store_class->get_inbox = get_inbox;
+	store_class->delete_folder = delete_folder;
+	store_class->rename_folder = rename_folder;
+	store_class->get_folder_info = get_folder_info;
 }
 
-CamelType camel_mh_store_get_type(void)
+GType
+camel_mh_store_get_type (void)
 {
-	static CamelType camel_mh_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_mh_store_type == CAMEL_INVALID_TYPE) {
-		camel_mh_store_type = camel_type_register(CAMEL_LOCAL_STORE_TYPE, "CamelMhStore",
-							  sizeof(CamelMhStore),
-							  sizeof(CamelMhStoreClass),
-							  (CamelObjectClassInitFunc) camel_mh_store_class_init,
-							  NULL,
-							  NULL,
-							  NULL);
-	}
-
-	return camel_mh_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_STORE,
+			"CamelMhStore",
+			sizeof (CamelMhStoreClass),
+			(GClassInitFunc) mh_store_class_init,
+			sizeof (CamelMhStore),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 static void
@@ -131,7 +123,7 @@ folders_update(const gchar *root, gint mode, const gchar *folder, const gchar *n
 	stream = camel_stream_fs_new_with_name(tmp, O_RDONLY, 0);
 	if (stream) {
 		in = camel_stream_buffer_new(stream, CAMEL_STREAM_BUFFER_READ);
-		camel_object_unref(stream);
+		g_object_unref (stream);
 	}
 	if (in == NULL || stream == NULL) {
 		if (mode == UPDATE_ADD && camel_stream_printf(out, "%s\n", folder) == -1)
@@ -195,9 +187,9 @@ fail:
 	unlink(tmpnew);		/* remove it if its there */
 	g_free(line);
 	if (in)
-		camel_object_unref(in);
+		g_object_unref (in);
 	if (out)
-		camel_object_unref(out);
+		g_object_unref (out);
 }
 
 static CamelFolder *
@@ -320,7 +312,7 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 			camel_folder_refresh_info(folder, NULL);
 		fi->unread = camel_folder_get_unread_message_count(folder);
 		fi->total = camel_folder_get_message_count(folder);
-		camel_object_unref(folder);
+		g_object_unref (folder);
 	} else {
 		gchar *path, *folderpath;
 		CamelFolderSummary *s;
@@ -340,7 +332,7 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 			fi->unread = s->unread_count;
 			fi->total = s->saved_count;
 		}
-		camel_object_unref(s);
+		g_object_unref (s);
 		g_free(folderpath);
 		g_free(path);
 	}
@@ -466,7 +458,7 @@ folders_scan(CamelStore *store, CamelURL *url, const gchar *root, const gchar *t
 		return;
 
 	in = camel_stream_buffer_new(stream, CAMEL_STREAM_BUFFER_READ);
-	camel_object_unref(stream);
+	g_object_unref (stream);
 	if (in == NULL)
 		return;
 
@@ -526,7 +518,7 @@ folders_scan(CamelStore *store, CamelURL *url, const gchar *root, const gchar *t
 	g_hash_table_foreach(visited, (GHFunc)g_free, NULL);
 	g_hash_table_destroy(visited);
 
-	camel_object_unref(in);
+	g_object_unref (in);
 }
 
 /* FIXME: move to camel-local, this is shared with maildir code */
diff --git a/camel/providers/local/camel-mh-store.h b/camel/providers/local/camel-mh-store.h
index d86ba55..e166ea3 100644
--- a/camel/providers/local/camel-mh-store.h
+++ b/camel/providers/local/camel-mh-store.h
@@ -20,36 +20,49 @@
  */
 
 #ifndef CAMEL_MH_STORE_H
-#define CAMEL_MH_STORE_H 1
+#define CAMEL_MH_STORE_H
 
 #include "camel-local-store.h"
 
-#define CAMEL_MH_STORE_TYPE     (camel_mh_store_get_type ())
-#define CAMEL_MH_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MH_STORE_TYPE, CamelMhStore))
-#define CAMEL_MH_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MH_STORE_TYPE, CamelMhStoreClass))
-#define CAMEL_IS_MH_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MH_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_MH_STORE \
+	(camel_mh_store_get_type ())
+#define CAMEL_MH_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MH_STORE, CamelMhStore))
+#define CAMEL_MH_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MH_STORE, CamelMhStoreClass))
+#define CAMEL_IS_MH_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MH_STORE))
+#define CAMEL_IS_MH_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MH_STORE))
+#define CAMEL_MH_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MH_STORE, CamelMhStoreClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelMhStore CamelMhStore;
+typedef struct _CamelMhStoreClass CamelMhStoreClass;
+
 enum {
 	CAMEL_MH_DOTFOLDERS = (1<<0) /* update/use .folders file */
 };
 
-typedef struct {
-	CamelLocalStore parent_object;
+struct _CamelMhStore {
+	CamelLocalStore parent;
 
 	guint32 flags;
-} CamelMhStore;
+};
 
-typedef struct {
+struct _CamelMhStoreClass {
 	CamelLocalStoreClass parent_class;
+};
 
-} CamelMhStoreClass;
-
-/* public methods */
-
-/* Standard Camel function */
-CamelType camel_mh_store_get_type(void);
+GType camel_mh_store_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-mh-summary.c b/camel/providers/local/camel-mh-summary.c
index 81add38..a8f4f97 100644
--- a/camel/providers/local/camel-mh-summary.c
+++ b/camel/providers/local/camel-mh-summary.c
@@ -34,9 +34,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-db.h"
-#include "camel-store.h"
-#include "camel-mime-message.h"
 #include "camel-private.h"
 
 #include "camel-mh-summary.h"
@@ -46,74 +43,68 @@
 
 #define CAMEL_MH_SUMMARY_VERSION (0x2000)
 
+#define CAMEL_MH_SUMMARY_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MH_SUMMARY, CamelMhSummaryPrivate))
+
 static gint mh_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 static gint mh_summary_sync(CamelLocalSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 /*static gint mh_summary_add(CamelLocalSummary *cls, CamelMimeMessage *msg, CamelMessageInfo *info, CamelFolderChangeInfo *, CamelException *ex);*/
 
 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);
-
-#define _PRIVATE(x) (((CamelMhSummary *)(x))->priv)
-
 struct _CamelMhSummaryPrivate {
 	gchar *current_uid;
 };
 
-static CamelLocalSummaryClass *parent_class;
-
-CamelType
-camel_mh_summary_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_local_summary_get_type (), "CamelMhSummary",
-					   sizeof(CamelMhSummary),
-					   sizeof(CamelMhSummaryClass),
-					   (CamelObjectClassInitFunc)camel_mh_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc)camel_mh_summary_init,
-					   (CamelObjectFinalizeFunc)camel_mh_summary_finalise);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static void
-camel_mh_summary_class_init (CamelMhSummaryClass *class)
+mh_summary_class_init (CamelMhSummaryClass *class)
 {
-	CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) class;
-	CamelLocalSummaryClass *lklass = (CamelLocalSummaryClass *)class;
+	CamelFolderSummaryClass *folder_summary_class;
+	CamelLocalSummaryClass *local_summary_class;
 
-	parent_class = (CamelLocalSummaryClass *)camel_type_get_global_classfuncs(camel_local_summary_get_type ());
+	parent_class = g_type_class_peek_parent (class);
 
-	/* override methods */
-	sklass->next_uid_string = mh_summary_next_uid_string;
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->next_uid_string = mh_summary_next_uid_string;
 
-	lklass->check = mh_summary_check;
-	lklass->sync = mh_summary_sync;
-	/*lklass->add = mh_summary_add;*/
+	local_summary_class = CAMEL_LOCAL_SUMMARY_CLASS (class);
+	local_summary_class->check = mh_summary_check;
+	local_summary_class->sync = mh_summary_sync;
+	/*local_summary_class->add = mh_summary_add;*/
 }
 
 static void
-camel_mh_summary_init (CamelMhSummary *o)
+mh_summary_init (CamelMhSummary *mh_summary)
 {
-	struct _CamelFolderSummary *s = (CamelFolderSummary *) o;
+	CamelFolderSummary *folder_summary;
+
+	mh_summary->priv = CAMEL_MH_SUMMARY_GET_PRIVATE (mh_summary);
+
+	folder_summary = CAMEL_FOLDER_SUMMARY (mh_summary);
 
-	o->priv = g_malloc0(sizeof(*o->priv));
 	/* set unique file version */
-	s->version += CAMEL_MH_SUMMARY_VERSION;
+	folder_summary->version += CAMEL_MH_SUMMARY_VERSION;
 }
 
-static void
-camel_mh_summary_finalise(CamelObject *obj)
+GType
+camel_mh_summary_get_type (void)
 {
-	CamelMhSummary *o = (CamelMhSummary *)obj;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_LOCAL_SUMMARY,
+			"CamelMhSummary",
+			sizeof (CamelMhSummaryClass),
+			(GClassInitFunc) mh_summary_class_init,
+			sizeof (CamelMhSummary),
+			(GInstanceInitFunc) mh_summary_init,
+			0);
 
-	g_free(o->priv);
+	return type;
 }
 
 /**
@@ -125,8 +116,9 @@ camel_mh_summary_finalise(CamelObject *obj)
  **/
 CamelMhSummary	*camel_mh_summary_new(struct _CamelFolder *folder, const gchar *filename, const gchar *mhdir, CamelIndex *index)
 {
-	CamelMhSummary *o = (CamelMhSummary *)camel_object_new(camel_mh_summary_get_type ());
+	CamelMhSummary *o;
 
+	o = g_object_new (CAMEL_TYPE_MH_SUMMARY, NULL);
 	((CamelFolderSummary *)o)->folder = folder;
 	if (folder) {
 		camel_db_set_collate (folder->parent_store->cdb_r, "uid", "mh_uid_sort", (CamelDBCollate)camel_local_frompos_sort);
@@ -199,7 +191,7 @@ static gint camel_mh_summary_add(CamelLocalSummary *cls, const gchar *name, gint
 	}
 	mhs->priv->current_uid = (gchar *)name;
 	camel_folder_summary_add_from_parser((CamelFolderSummary *)mhs, mp);
-	camel_object_unref((CamelObject *)mp);
+	g_object_unref (mp);
 	mhs->priv->current_uid = NULL;
 	camel_folder_summary_set_index((CamelFolderSummary *)mhs, NULL);
 	g_free(filename);
diff --git a/camel/providers/local/camel-mh-summary.h b/camel/providers/local/camel-mh-summary.h
index 81d43a8..568f98a 100644
--- a/camel/providers/local/camel-mh-summary.h
+++ b/camel/providers/local/camel-mh-summary.h
@@ -18,39 +18,50 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_MH_SUMMARY_H
-#define _CAMEL_MH_SUMMARY_H
+#ifndef CAMEL_MH_SUMMARY_H
+#define CAMEL_MH_SUMMARY_H
+
+#include <camel/camel.h>
 
 #include "camel-local-summary.h"
-#include <camel/camel-folder.h>
-#include <camel/camel-exception.h>
-#include <camel/camel-index.h>
 
-#define CAMEL_MH_SUMMARY(obj)	CAMEL_CHECK_CAST (obj, camel_mh_summary_get_type (), CamelMhSummary)
-#define CAMEL_MH_SUMMARY_CLASS(klass)	CAMEL_CHECK_CLASS_CAST (klass, camel_mh_summary_get_type (), CamelMhSummaryClass)
-#define CAMEL_IS_MH_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_mh_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_MH_SUMMARY \
+	(camel_mh_summary_get_type ())
+#define CAMEL_MH_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MH_SUMMARY, CamelMhSummary))
+#define CAMEL_MH_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MH_SUMMARY, CamelMhSummaryClass))
+#define CAMEL_IS_MH_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MH_SUMMARY))
+#define CAMEL_IS_MH_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MH_SUMMARY))
+#define CAMEL_MH_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MH_SUMMARY, CamelMhSummaryClass))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelMhSummary	CamelMhSummary;
-typedef struct _CamelMhSummaryClass	CamelMhSummaryClass;
+typedef struct _CamelMhSummaryClass CamelMhSummaryClass;
+typedef struct _CamelMhSummaryPrivate CamelMhSummaryPrivate;
 
 struct _CamelMhSummary {
 	CamelLocalSummary parent;
-	struct _CamelMhSummaryPrivate *priv;
+	CamelMhSummaryPrivate *priv;
 };
 
 struct _CamelMhSummaryClass {
 	CamelLocalSummaryClass parent_class;
-
-	/* virtual methods */
-
-	/* signals */
 };
 
-CamelType	 camel_mh_summary_get_type	(void);
+GType	 camel_mh_summary_get_type	(void);
 CamelMhSummary	*camel_mh_summary_new(struct _CamelFolder *, const gchar *filename, const gchar *mhdir, CamelIndex *index);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_MH_SUMMARY_H */
+#endif /* CAMEL_MH_SUMMARY_H */
diff --git a/camel/providers/local/camel-spool-folder.c b/camel/providers/local/camel-spool-folder.c
index 0c28410..2e11f92 100644
--- a/camel/providers/local/camel-spool-folder.c
+++ b/camel/providers/local/camel-spool-folder.c
@@ -34,78 +34,54 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-data-wrapper.h"
-#include "camel-exception.h"
-#include "camel-file-utils.h"
-#include "camel-local-private.h"
-#include "camel-lock-client.h"
-#include "camel-mime-filter-from.h"
-#include "camel-mime-message.h"
-#include "camel-session.h"
-#include "camel-stream-filter.h"
-#include "camel-stream-fs.h"
-
 #include "camel-spool-folder.h"
 #include "camel-spool-store.h"
 #include "camel-spool-summary.h"
 
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
 
-static CamelFolderClass *parent_class = NULL;
-
-/* Returns the class for a CamelSpoolFolder */
-#define CSPOOLF_CLASS(so) CAMEL_SPOOL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CSPOOLS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static CamelLocalSummary *spool_create_summary(CamelLocalFolder *lf, const gchar *path, const gchar *folder, CamelIndex *index);
 
 static gint spool_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex);
 static void spool_unlock(CamelLocalFolder *lf);
 
-static void spool_finalize(CamelObject * object);
-
 static void
-camel_spool_folder_class_init(CamelSpoolFolderClass *klass)
+spool_folder_class_init (CamelSpoolFolderClass *class)
 {
-	CamelLocalFolderClass *lklass = (CamelLocalFolderClass *)klass;
+	CamelLocalFolderClass *local_folder_class;
 
-	parent_class = (CamelFolderClass *)camel_mbox_folder_get_type();
+	parent_class = g_type_class_peek_parent (class);
 
-	lklass->create_summary = spool_create_summary;
-	lklass->lock = spool_lock;
-	lklass->unlock = spool_unlock;
+	local_folder_class = CAMEL_LOCAL_FOLDER_CLASS (class);
+	local_folder_class->create_summary = spool_create_summary;
+	local_folder_class->lock = spool_lock;
+	local_folder_class->unlock = spool_unlock;
 }
 
 static void
-spool_init(gpointer object, gpointer klass)
+spool_folder_init (CamelSpoolFolder *spool_folder)
 {
-	CamelSpoolFolder *spool_folder = object;
-
 	spool_folder->lockid = -1;
 }
 
-static void
-spool_finalize(CamelObject * object)
-{
-	/*CamelSpoolFolder *spool_folder = CAMEL_SPOOL_FOLDER(object);*/
-}
-
-CamelType camel_spool_folder_get_type(void)
+GType
+camel_spool_folder_get_type (void)
 {
-	static CamelType camel_spool_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_spool_folder_type == CAMEL_INVALID_TYPE) {
-		camel_spool_folder_type = camel_type_register(camel_mbox_folder_get_type(), "CamelSpoolFolder",
-							     sizeof(CamelSpoolFolder),
-							     sizeof(CamelSpoolFolderClass),
-							     (CamelObjectClassInitFunc) camel_spool_folder_class_init,
-							     NULL,
-							     (CamelObjectInitFunc) spool_init,
-							     (CamelObjectFinalizeFunc) spool_finalize);
-	}
-
-	return camel_spool_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MBOX_FOLDER,
+			"CamelSpoolFolder",
+			sizeof (CamelSpoolFolderClass),
+			(GClassInitFunc) spool_folder_class_init,
+			sizeof (CamelSpoolFolder),
+			(GInstanceInitFunc) spool_folder_init,
+			0);
+
+	return type;
 }
 
 CamelFolder *
@@ -115,7 +91,7 @@ camel_spool_folder_new(CamelStore *parent_store, const gchar *full_name, guint32
 
 	d(printf("Creating spool folder: %s in %s\n", full_name, camel_local_store_get_toplevel_dir((CamelLocalStore *)parent_store)));
 
-	folder = (CamelFolder *)camel_object_new(CAMEL_SPOOL_FOLDER_TYPE);
+	folder = g_object_new (CAMEL_TYPE_SPOOL_FOLDER, NULL);
 
 	if (parent_store->flags & CAMEL_STORE_FILTER_INBOX
 	    && strcmp(full_name, "INBOX") == 0)
diff --git a/camel/providers/local/camel-spool-folder.h b/camel/providers/local/camel-spool-folder.h
index ce057b8..1e7d2a4 100644
--- a/camel/providers/local/camel-spool-folder.h
+++ b/camel/providers/local/camel-spool-folder.h
@@ -20,37 +20,50 @@
  */
 
 #ifndef CAMEL_SPOOL_FOLDER_H
-#define CAMEL_SPOOL_FOLDER_H 1
+#define CAMEL_SPOOL_FOLDER_H
+
+#include <camel/camel.h>
 
 #include "camel-mbox-folder.h"
-#include <camel/camel-folder-search.h>
-#include <camel/camel-index.h>
 #include "camel-spool-summary.h"
-#include "camel-lock.h"
-
-/*  #include "camel-store.h" */
 
-#define CAMEL_SPOOL_FOLDER_TYPE     (camel_spool_folder_get_type ())
-#define CAMEL_SPOOL_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SPOOL_FOLDER_TYPE, CamelSpoolFolder))
-#define CAMEL_SPOOL_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SPOOL_FOLDER_TYPE, CamelSpoolFolderClass))
-#define CAMEL_IS_SPOOL_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SPOOL_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SPOOL_FOLDER \
+	(camel_spool_folder_get_type ())
+#define CAMEL_SPOOL_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SPOOL_FOLDER, CamelSpoolFolder))
+#define CAMEL_SPOOL_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SPOOL_FOLDER, CamelSpoolFolderClass))
+#define CAMEL_IS_SPOOL_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SPOOL_FOLDER))
+#define CAMEL_IS_SPOOL_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SPOOL_FOLDER))
+#define CAMEL_SPOOL_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SPOOL_FOLDER, CamelSpoolFolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelMboxFolder parent;
+typedef struct _CamelSpoolFolder CamelSpoolFolder;
+typedef struct _CamelSpoolFolderClass CamelSpoolFolderClass;
+typedef struct _CamelSpoolFolderPrivate CamelSpoolFolderPrivate;
 
-	struct _CamelSpoolFolderPrivate *priv;
+struct _CamelSpoolFolder {
+	CamelMboxFolder parent;
+	CamelSpoolFolderPrivate *priv;
 
 	gint lockid;		/* lock id for dot locking */
-} CamelSpoolFolder;
+};
 
-typedef struct {
+struct _CamelSpoolFolderClass {
 	CamelMboxFolderClass parent_class;
-} CamelSpoolFolderClass;
+};
 
-/* Standard Camel function */
-CamelType camel_spool_folder_get_type(void);
+GType camel_spool_folder_get_type(void);
 
 CamelFolder *camel_spool_folder_new(CamelStore *parent_store, const gchar *full_name, guint32 flags, CamelException *ex);
 
diff --git a/camel/providers/local/camel-spool-store.c b/camel/providers/local/camel-spool-store.c
index e94be9a..04a8806 100644
--- a/camel/providers/local/camel-spool-store.c
+++ b/camel/providers/local/camel-spool-store.c
@@ -40,21 +40,11 @@
 
 #include <libedataserver/e-data-server-util.h>
 
-#include "camel-exception.h"
-#include "camel-file-utils.h"
-#include "camel-private.h"
-#include "camel-session.h"
-#include "camel-url.h"
-
 #include "camel-spool-folder.h"
 #include "camel-spool-store.h"
 
 #define d(x)
 
-/* Returns the class for a CamelSpoolStore */
-#define CSPOOLS_CLASS(so) CAMEL_SPOOL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
 static void construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex);
 static CamelFolder *get_folder(CamelStore * store, const gchar *folder_name, guint32 flags, CamelException * ex);
 static gchar *get_name(CamelService *service, gboolean brief);
@@ -68,47 +58,50 @@ static void delete_folder(CamelStore *store, const gchar *folder_name, CamelExce
 static gchar *spool_get_meta_path(CamelLocalStore *ls, const gchar *full_name, const gchar *ext);
 static gchar *spool_get_full_path(CamelLocalStore *ls, const gchar *full_name);
 
-static CamelStoreClass *parent_class = NULL;
+static gpointer parent_class;
 
 static void
-camel_spool_store_class_init (CamelSpoolStoreClass *camel_spool_store_class)
+spool_store_class_init (CamelSpoolStoreClass *class)
 {
-	CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_spool_store_class);
-	CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS (camel_spool_store_class);
-
-	parent_class = CAMEL_STORE_CLASS(camel_mbox_store_get_type());
-
-	/* virtual method overload */
-	camel_service_class->construct = construct;
-	camel_service_class->get_name = get_name;
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->get_inbox = get_inbox;
-	camel_store_class->get_folder_info = get_folder_info;
-	camel_store_class->free_folder_info = free_folder_info;
-
-	camel_store_class->delete_folder = delete_folder;
-	camel_store_class->rename_folder = rename_folder;
-
-	((CamelLocalStoreClass *)camel_store_class)->get_full_path = spool_get_full_path;
-	((CamelLocalStoreClass *)camel_store_class)->get_meta_path = spool_get_meta_path;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
+	CamelLocalStoreClass *local_store_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = construct;
+	service_class->get_name = get_name;
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_folder = get_folder;
+	store_class->get_inbox = get_inbox;
+	store_class->get_folder_info = get_folder_info;
+	store_class->free_folder_info = free_folder_info;
+	store_class->delete_folder = delete_folder;
+	store_class->rename_folder = rename_folder;
+
+	local_store_class = CAMEL_LOCAL_STORE_CLASS (class);
+	local_store_class->get_full_path = spool_get_full_path;
+	local_store_class->get_meta_path = spool_get_meta_path;
 }
 
-CamelType
+GType
 camel_spool_store_get_type (void)
 {
-	static CamelType camel_spool_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_spool_store_type == CAMEL_INVALID_TYPE)	{
-		camel_spool_store_type = camel_type_register (camel_mbox_store_get_type(), "CamelSpoolStore",
-							     sizeof (CamelSpoolStore),
-							     sizeof (CamelSpoolStoreClass),
-							     (CamelObjectClassInitFunc) camel_spool_store_class_init,
-							     NULL,
-							     NULL,
-							     NULL);
-	}
-
-	return camel_spool_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MBOX_STORE,
+			"CamelSpoolStore",
+			sizeof (CamelSpoolStoreClass),
+			(GClassInitFunc) spool_store_class_init,
+			sizeof (CamelSpoolStore),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 static void
@@ -117,7 +110,7 @@ construct (CamelService *service, CamelSession *session, CamelProvider *provider
 	struct stat st;
 
 	d(printf("constructing store of type %s '%s:%s'\n",
-		 camel_type_to_name(((CamelObject *)service)->s.type), url->protocol, url->path));
+		 G_OBJECT_CLASS_NAME(((CamelObject *)service)->s.type), url->protocol, url->path));
 
 	CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
 	if (camel_exception_is_set (ex))
@@ -261,7 +254,7 @@ spool_fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
 			camel_folder_refresh_info(folder, NULL);
 		fi->unread = camel_folder_get_unread_message_count(folder);
 		fi->total = camel_folder_get_message_count(folder);
-		camel_object_unref(folder);
+		g_object_unref (folder);
 	}
 }
 
@@ -384,7 +377,7 @@ static gint scan_dir(CamelStore *store, GHashTable *visited, gchar *root, const
 					spool_fill_fi(store, fi, flags);
 				}
 				if (folder)
-					camel_object_unref(folder);
+					g_object_unref (folder);
 
 			} else if (S_ISDIR(st.st_mode)) {
 				struct _inode in = { st.st_dev, st.st_ino };
diff --git a/camel/providers/local/camel-spool-store.h b/camel/providers/local/camel-spool-store.h
index d56c937..f0b9d34 100644
--- a/camel/providers/local/camel-spool-store.h
+++ b/camel/providers/local/camel-spool-store.h
@@ -20,37 +20,50 @@
  */
 
 #ifndef CAMEL_SPOOL_STORE_H
-#define CAMEL_SPOOL_STORE_H 1
+#define CAMEL_SPOOL_STORE_H
 
 #include "camel-mbox-store.h"
 
-#define CAMEL_SPOOL_STORE_TYPE     (camel_spool_store_get_type ())
-#define CAMEL_SPOOL_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SPOOL_STORE_TYPE, CamelSpoolStore))
-#define CAMEL_SPOOL_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SPOOL_STORE_TYPE, CamelSpoolStoreClass))
-#define CAMEL_IS_SPOOL_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SPOOL_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SPOOL_STORE \
+	(camel_spool_store_get_type ())
+#define CAMEL_SPOOL_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SPOOL_STORE, CamelSpoolStore))
+#define CAMEL_SPOOL_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SPOOL_STORE, CamelSpoolStoreClass))
+#define CAMEL_IS_SPOOL_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SPOOL_STORE))
+#define CAMEL_IS_SPOOL_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SPOOL_STORE))
+#define CAMEL_SPOOL_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SPOOL_STORE, CamelSpoolStoreClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelSpoolStore CamelSpoolStore;
+typedef struct _CamelSpoolStoreClass CamelSpoolStoreClass;
+
 typedef enum _camel_spool_store_t {
 	CAMEL_SPOOL_STORE_MBOX,	/* a single mbox */
 	CAMEL_SPOOL_STORE_ELM	/* elm/pine/etc tree of mbox files in folders */
 } camel_spool_store_t;
 
-typedef struct {
-	CamelMboxStore parent_object;
+struct _CamelSpoolStore {
+	CamelMboxStore parent;
 
 	camel_spool_store_t type;
-} CamelSpoolStore;
+};
 
-typedef struct {
+struct _CamelSpoolStoreClass {
 	CamelMboxStoreClass parent_class;
+};
 
-} CamelSpoolStoreClass;
-
-/* public methods */
-
-/* Standard Camel function */
-CamelType camel_spool_store_get_type (void);
+GType camel_spool_store_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/providers/local/camel-spool-summary.c b/camel/providers/local/camel-spool-summary.c
index e774ee9..b05ce2d 100644
--- a/camel/providers/local/camel-spool-summary.c
+++ b/camel/providers/local/camel-spool-summary.c
@@ -34,12 +34,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-db.h"
-#include "camel-file-utils.h"
-#include "camel-mime-message.h"
-#include "camel-operation.h"
-#include "camel-store.h"
-
 #include "camel-spool-summary.h"
 #include "camel-local-private.h"
 
@@ -54,67 +48,61 @@ static gint spool_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *c
 static gint spool_summary_sync_full(CamelMboxSummary *cls, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex);
 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 CamelFolderSummaryClass *camel_spool_summary_parent;
-
-CamelType
-camel_spool_summary_get_type(void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_mbox_summary_get_type(), "CamelSpoolSummary",
-					   sizeof (CamelSpoolSummary),
-					   sizeof (CamelSpoolSummaryClass),
-					   (CamelObjectClassInitFunc) camel_spool_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_spool_summary_init,
-					   (CamelObjectFinalizeFunc) camel_spool_summary_finalise);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static void
-camel_spool_summary_class_init(CamelSpoolSummaryClass *klass)
+spool_summary_class_init (CamelSpoolSummaryClass *class)
 {
-	CamelLocalSummaryClass *lklass = (CamelLocalSummaryClass *)klass;
-	CamelMboxSummaryClass *mklass = (CamelMboxSummaryClass *)klass;
+	CamelLocalSummaryClass *local_summary_class;
+	CamelMboxSummaryClass *mbox_summary_class;
 
-	camel_spool_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS(camel_mbox_summary_get_type());
+	parent_class = g_type_class_peek_parent (class);
 
-	lklass->load = spool_summary_load;
-	lklass->check = spool_summary_check;
-	lklass->need_index = spool_summary_need_index;
+	local_summary_class = CAMEL_LOCAL_SUMMARY_CLASS (class);
+	local_summary_class->load = spool_summary_load;
+	local_summary_class->check = spool_summary_check;
+	local_summary_class->need_index = spool_summary_need_index;
 
-	mklass->sync_full = spool_summary_sync_full;
+	mbox_summary_class->sync_full = spool_summary_sync_full;
 }
 
 static void
-camel_spool_summary_init(CamelSpoolSummary *obj)
+spool_summary_init(CamelSpoolSummary *spool_summary)
 {
-	struct _CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *folder_summary;
+
+	folder_summary = CAMEL_FOLDER_SUMMARY (spool_summary);
 
 	/* message info size is from mbox parent */
 
 	/* and a unique file version */
-	s->version += CAMEL_SPOOL_SUMMARY_VERSION;
+	folder_summary->version += CAMEL_SPOOL_SUMMARY_VERSION;
 }
 
-static void
-camel_spool_summary_finalise(CamelObject *obj)
+GType
+camel_spool_summary_get_type(void)
 {
-	/*CamelSpoolSummary *mbs = CAMEL_SPOOL_SUMMARY(obj);*/
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_MBOX_SUMMARY,
+			"CamelSpoolSummary",
+			sizeof (CamelSpoolSummaryClass),
+			(GClassInitFunc) spool_summary_class_init,
+			sizeof (CamelSpoolSummary),
+			(GInstanceInitFunc) spool_summary_init,
+			0);
+
+	return type;
 }
 
 CamelSpoolSummary *
 camel_spool_summary_new(struct _CamelFolder *folder, const gchar *mbox_name)
 {
-	CamelSpoolSummary *new = (CamelSpoolSummary *)camel_object_new(camel_spool_summary_get_type());
+	CamelSpoolSummary *new;
 
+	new = g_object_new (CAMEL_TYPE_SPOOL_SUMMARY, NULL);
 	((CamelFolderSummary *)new)->folder = folder;
 	if (folder) {
 		camel_db_set_collate (folder->parent_store->cdb_r, "bdata", "spool_frompos_sort", (CamelDBCollate)camel_local_frompos_sort);
@@ -310,7 +298,7 @@ spool_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changeinfo, C
 	struct stat st;
 	CamelFolderSummary *s = (CamelFolderSummary *)cls;
 
-	if (((CamelLocalSummaryClass *)camel_spool_summary_parent)->check(cls, changeinfo, ex) == -1)
+	if (CAMEL_LOCAL_SUMMARY_CLASS (parent_class)->check(cls, changeinfo, ex) == -1)
 		return -1;
 
 	/* check to see if we need to copy/update the file; missing xev headers prompt this */
@@ -326,7 +314,7 @@ spool_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changeinfo, C
 	/* if we do, then write out the headers using sync_full, etc */
 	if (work) {
 		d(printf("Have to add new headers, re-syncing from the start to accomplish this\n"));
-		if (((CamelMboxSummaryClass *)((CamelObject *)cls)->klass)->sync_full((CamelMboxSummary *)cls, FALSE, changeinfo, ex) == -1)
+		if (CAMEL_MBOX_SUMMARY_GET_CLASS (cls)->sync_full (CAMEL_MBOX_SUMMARY (cls), FALSE, changeinfo, ex) == -1)
 			return -1;
 
 		if (stat(cls->folder_path, &st) == -1) {
diff --git a/camel/providers/local/camel-spool-summary.h b/camel/providers/local/camel-spool-summary.h
index f2137f1..98aa960 100644
--- a/camel/providers/local/camel-spool-summary.h
+++ b/camel/providers/local/camel-spool-summary.h
@@ -18,22 +18,35 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_SPOOL_SUMMARY_H
-#define _CAMEL_SPOOL_SUMMARY_H
+#ifndef CAMEL_SPOOL_SUMMARY_H
+#define CAMEL_SPOOL_SUMMARY_H
+
+#include <camel/camel.h>
 
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-folder.h>
-#include <camel/camel-exception.h>
-#include <camel/camel-index.h>
 #include "camel-mbox-summary.h"
 
-#define CAMEL_SPOOL_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_spool_summary_get_type (), CamelSpoolSummary)
-#define CAMEL_SPOOL_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_spool_summary_get_type (), CamelSpoolSummaryClass)
-#define CAMEL_IS_SPOOL_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_spool_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_SPOOL_SUMMARY \
+	(camel_spool_summary_get_type ())
+#define CAMEL_SPOOL_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SPOOL_SUMMARY, CamelSpoolSummary))
+#define CAMEL_SPOOL_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SPOOL_SUMMARY, CamelSpoolSummaryClass))
+#define CAMEL_IS_SPOOL_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SPOOL_SUMMARY))
+#define CAMEL_IS_SPOOL_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SPOOL_SUMMARY))
+#define CAMEL_SPOOL_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SPOOL_SUMMARY, CamelSpoolSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelSpoolSummary      CamelSpoolSummary;
+typedef struct _CamelSpoolSummary CamelSpoolSummary;
 typedef struct _CamelSpoolSummaryClass CamelSpoolSummaryClass;
 
 struct _CamelSpoolSummary {
@@ -45,7 +58,7 @@ struct _CamelSpoolSummaryClass {
 	CamelMboxSummaryClass parent_class;
 };
 
-CamelType	camel_spool_summary_get_type	(void);
+GType	camel_spool_summary_get_type	(void);
 void	camel_spool_summary_construct	(CamelSpoolSummary *new, const gchar *filename, const gchar *spool_name, CamelIndex *index);
 
 /* create the summary, in-memory only */
@@ -69,4 +82,4 @@ gint camel_spool_summary_write_headers(gint fd, struct _camel_header_raw *header
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_SPOOL_SUMMARY_H */
+#endif /* CAMEL_SPOOL_SUMMARY_H */
diff --git a/camel/providers/nntp/camel-nntp-auth.c b/camel/providers/nntp/camel-nntp-auth.c
index f015f09..c11321c 100644
--- a/camel/providers/nntp/camel-nntp-auth.c
+++ b/camel/providers/nntp/camel-nntp-auth.c
@@ -26,9 +26,6 @@
 
 #include <string.h>
 
-#include "camel-exception.h"
-#include "camel-session.h"
-
 #include "camel-nntp-auth.h"
 #include "camel-nntp-store.h"
 #include "camel-nntp-resp-codes.h"
diff --git a/camel/providers/nntp/camel-nntp-auth.h b/camel/providers/nntp/camel-nntp-auth.h
index 4958fa3..c74869a 100644
--- a/camel/providers/nntp/camel-nntp-auth.h
+++ b/camel/providers/nntp/camel-nntp-auth.h
@@ -23,9 +23,9 @@
  */
 
 #ifndef CAMEL_NNTP_AUTH_H
-#define CAMEL_NNTP_AUTH_H 1
+#define CAMEL_NNTP_AUTH_H
 
-#include <camel-nntp-store.h>
+#include "camel-nntp-store.h"
 
 G_BEGIN_DECLS
 
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c
index ea18215..2b29576 100644
--- a/camel/providers/nntp/camel-nntp-folder.c
+++ b/camel/providers/nntp/camel-nntp-folder.c
@@ -35,21 +35,7 @@
 
 #include <libedataserver/e-data-server-util.h>
 
-#include "camel/camel-data-cache.h"
-#include "camel/camel-data-wrapper.h"
-#include "camel/camel-exception.h"
-#include "camel/camel-file-utils.h"
-#include "camel/camel-folder-search.h"
-#include "camel/camel-mime-filter-crlf.h"
-#include "camel/camel-mime-message.h"
-#include "camel/camel-mime-message.h"
-#include "camel/camel-mime-part.h"
-#include "camel/camel-multipart.h"
-#include "camel/camel-private.h"
-#include "camel/camel-session.h"
-#include "camel/camel-stream-buffer.h"
-#include "camel/camel-stream-filter.h"
-#include "camel/camel-stream-mem.h"
+#include "camel-private.h"
 
 #include "camel-nntp-folder.h"
 #include "camel-nntp-private.h"
@@ -57,13 +43,29 @@
 #include "camel-nntp-store.h"
 #include "camel-nntp-summary.h"
 
-static CamelFolderClass *folder_class = NULL;
-static CamelDiscoFolderClass *parent_class = NULL;
+#define CAMEL_NNTP_FOLDER_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_NNTP_FOLDER, CamelNNTPFolderPrivate))
 
-/* Returns the class for a CamelNNTPFolder */
-#define CNNTPF_CLASS(so) CAMEL_NNTP_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CNNTPS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
+
+static void
+nntp_folder_finalize (GObject *object)
+{
+	CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (object);
+	CamelException ex;
+
+	camel_exception_init (&ex);
+
+	camel_folder_summary_save_to_db (
+		CAMEL_FOLDER (nntp_folder)->summary, &ex);
+
+	g_mutex_free (nntp_folder->priv->search_lock);
+	g_mutex_free (nntp_folder->priv->cache_lock);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
 
 void
 camel_nntp_folder_selected(CamelNNTPFolder *folder, gchar *line, CamelException *ex)
@@ -117,12 +119,6 @@ nntp_folder_sync_offline (CamelFolder *folder, CamelException *ex)
 	CAMEL_SERVICE_REC_UNLOCK(folder->parent_store, connect_lock);
 }
 
-static gboolean
-nntp_folder_set_message_flags (CamelFolder *folder, const gchar *uid, guint32 flags, guint32 set)
-{
-        return ((CamelFolderClass *) folder_class)->set_message_flags (folder, uid, flags, set);
-}
-
 static gchar *
 nntp_get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex)
 {
@@ -160,7 +156,7 @@ nntp_folder_download_message (CamelNNTPFolder *nntp_folder, const gchar *id, con
 				goto fail;
 		} else {
 			stream = (CamelStream *) nntp_store->stream;
-			camel_object_ref (stream);
+			g_object_ref (stream);
 		}
 	} else if (ret == 423 || ret == 430) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, _("Cannot get message %s: %s"), msgid, line);
@@ -200,7 +196,7 @@ nntp_folder_cache_message (CamelDiscoFolder *disco_folder, const gchar *uid, Cam
 
 	stream = nntp_folder_download_message ((CamelNNTPFolder *) disco_folder, article, msgid, ex);
 	if (stream)
-		camel_object_unref (stream);
+		g_object_unref (stream);
 
 	CAMEL_SERVICE_REC_UNLOCK(nntp_store, connect_lock);
 }
@@ -250,11 +246,11 @@ nntp_folder_get_message (CamelFolder *folder, const gchar *uid, CamelException *
 			camel_exception_setv (ex, CAMEL_EXCEPTION_USER_CANCEL, _("User canceled"));
 		else
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get message %s: %s"), uid, g_strerror (errno));
-		camel_object_unref(message);
+		g_object_unref (message);
 		message = NULL;
 	}
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 fail:
 	if (camel_folder_change_info_changed (nntp_folder->changes)) {
 		changes = nntp_folder->changes;
@@ -350,7 +346,7 @@ nntp_folder_append_message_online (CamelFolder *folder, CamelMimeMessage *mime_m
 {
 	CamelNNTPStore *nntp_store = (CamelNNTPStore *) folder->parent_store;
 	CamelStream *stream = (CamelStream*)nntp_store->stream;
-	CamelStreamFilter *filtered_stream;
+	CamelStream *filtered_stream;
 	CamelMimeFilter *crlffilter;
 	gint ret;
 	guint u;
@@ -377,15 +373,16 @@ nntp_folder_append_message_online (CamelFolder *folder, CamelMimeMessage *mime_m
 
 	/* setup stream filtering */
 	crlffilter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS);
-	filtered_stream = camel_stream_filter_new_with_stream (stream);
-	camel_stream_filter_add (filtered_stream, crlffilter);
-	camel_object_unref (crlffilter);
+	filtered_stream = camel_stream_filter_new (stream);
+	camel_stream_filter_add (
+		CAMEL_STREAM_FILTER (filtered_stream), crlffilter);
+	g_object_unref (crlffilter);
 
 	/* remove mail 'To', 'CC', and 'BCC' headers */
 	savedhdrs = NULL;
 	tail = (struct _camel_header_raw *) &savedhdrs;
 
-	header = (struct _camel_header_raw *) &CAMEL_MIME_PART (mime_message)->headers;
+	header = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (mime_message));
 	n = header->next;
 	while (n != NULL) {
 		if (!g_ascii_strcasecmp (n->name, "To") || !g_ascii_strcasecmp (n->name, "Cc") || !g_ascii_strcasecmp (n->name, "Bcc")) {
@@ -402,8 +399,8 @@ nntp_folder_append_message_online (CamelFolder *folder, CamelMimeMessage *mime_m
 
 	/* write the message */
 	if (camel_stream_write(stream, group, strlen(group)) == -1
-	    || camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (mime_message), CAMEL_STREAM (filtered_stream)) == -1
-	    || camel_stream_flush (CAMEL_STREAM (filtered_stream)) == -1
+	    || camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (mime_message), filtered_stream) == -1
+	    || camel_stream_flush (filtered_stream) == -1
 	    || camel_stream_write (stream, "\r\n.\r\n", 5) == -1
 	    || (ret = camel_nntp_stream_line (nntp_store->stream, (guchar **)&line, &u)) == -1) {
 		if (errno == EINTR)
@@ -414,7 +411,7 @@ nntp_folder_append_message_online (CamelFolder *folder, CamelMimeMessage *mime_m
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Posting failed: %s"), line);
 	}
 
-	camel_object_unref (filtered_stream);
+	g_object_unref (filtered_stream);
 	g_free(group);
 	header->next = savedhdrs;
 
@@ -444,82 +441,68 @@ nntp_folder_transfer_message (CamelFolder *source, GPtrArray *uids, CamelFolder
 }
 
 static void
-nntp_folder_init (CamelNNTPFolder *nntp_folder, CamelNNTPFolderClass *klass)
+nntp_folder_init (CamelNNTPFolder *nntp_folder)
 {
-	struct _CamelNNTPFolderPrivate *p;
+	nntp_folder->priv = CAMEL_NNTP_FOLDER_GET_PRIVATE (nntp_folder);
 
 	nntp_folder->changes = camel_folder_change_info_new ();
-	p = nntp_folder->priv = g_malloc0 (sizeof (*nntp_folder->priv));
-	p->search_lock = g_mutex_new ();
-	p->cache_lock = g_mutex_new ();
+	nntp_folder->priv->search_lock = g_mutex_new ();
+	nntp_folder->priv->cache_lock = g_mutex_new ();
 }
 
 static void
-nntp_folder_finalise (CamelNNTPFolder *nntp_folder)
+nntp_folder_class_init (CamelNNTPFolderClass *class)
 {
-	struct _CamelNNTPFolderPrivate *p;
-
-	CamelException ex;
-
-	camel_exception_init (&ex);
-
-	camel_folder_summary_save_to_db (((CamelFolder*) nntp_folder)->summary, &ex);
-
-	p = nntp_folder->priv;
-	g_mutex_free (p->search_lock);
-	g_mutex_free (p->cache_lock);
-	g_free (p);
+	GObjectClass *object_class;
+	CamelFolderClass *folder_class;
+	CamelDiscoFolderClass *disco_folder_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelNNTPFolderPrivate));
+
+	folder_class = CAMEL_FOLDER_CLASS (g_type_class_peek (CAMEL_TYPE_FOLDER));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = nntp_folder_finalize;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->get_message = nntp_folder_get_message;
+	folder_class->search_by_expression = nntp_folder_search_by_expression;
+	folder_class->count_by_expression = nntp_folder_count_by_expression;
+	folder_class->search_by_uids = nntp_folder_search_by_uids;
+	folder_class->search_free = nntp_folder_search_free;
+	folder_class->get_filename = nntp_get_filename;
+
+	disco_folder_class = CAMEL_DISCO_FOLDER_CLASS (class);
+	disco_folder_class->sync_online = nntp_folder_sync_online;
+	disco_folder_class->sync_resyncing = nntp_folder_sync_offline;
+	disco_folder_class->sync_offline = nntp_folder_sync_offline;
+	disco_folder_class->cache_message = nntp_folder_cache_message;
+	disco_folder_class->append_online = nntp_folder_append_message_online;
+	disco_folder_class->append_resyncing = nntp_folder_append_message_online;
+	disco_folder_class->append_offline = nntp_folder_append_message_offline;
+	disco_folder_class->transfer_online = nntp_folder_transfer_message;
+	disco_folder_class->transfer_resyncing = nntp_folder_transfer_message;
+	disco_folder_class->transfer_offline = nntp_folder_transfer_message;
+	disco_folder_class->refresh_info_online = nntp_folder_refresh_info_online;
 }
 
-static void
-nntp_folder_class_init (CamelNNTPFolderClass *camel_nntp_folder_class)
-{
-	CamelDiscoFolderClass *camel_disco_folder_class = CAMEL_DISCO_FOLDER_CLASS (camel_nntp_folder_class);
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_nntp_folder_class);
-
-	parent_class = CAMEL_DISCO_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_disco_folder_get_type ()));
-	folder_class = CAMEL_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_folder_get_type ()));
-
-	/* virtual method definition */
-
-	/* virtual method overload */
-	camel_disco_folder_class->sync_online = nntp_folder_sync_online;
-	camel_disco_folder_class->sync_resyncing = nntp_folder_sync_offline;
-	camel_disco_folder_class->sync_offline = nntp_folder_sync_offline;
-	camel_disco_folder_class->cache_message = nntp_folder_cache_message;
-	camel_disco_folder_class->append_online = nntp_folder_append_message_online;
-	camel_disco_folder_class->append_resyncing = nntp_folder_append_message_online;
-	camel_disco_folder_class->append_offline = nntp_folder_append_message_offline;
-	camel_disco_folder_class->transfer_online = nntp_folder_transfer_message;
-	camel_disco_folder_class->transfer_resyncing = nntp_folder_transfer_message;
-	camel_disco_folder_class->transfer_offline = nntp_folder_transfer_message;
-	camel_disco_folder_class->refresh_info_online = nntp_folder_refresh_info_online;
-
-	camel_folder_class->set_message_flags = nntp_folder_set_message_flags;
-	camel_folder_class->get_message = nntp_folder_get_message;
-	camel_folder_class->search_by_expression = nntp_folder_search_by_expression;
-	camel_folder_class->count_by_expression = nntp_folder_count_by_expression;
-	camel_folder_class->search_by_uids = nntp_folder_search_by_uids;
-	camel_folder_class->search_free = nntp_folder_search_free;
-	camel_folder_class->get_filename = nntp_get_filename;
-}
-
-CamelType
+GType
 camel_nntp_folder_get_type (void)
 {
-	static CamelType camel_nntp_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_nntp_folder_type == CAMEL_INVALID_TYPE)	{
-		camel_nntp_folder_type = camel_type_register (CAMEL_DISCO_FOLDER_TYPE, "CamelNNTPFolder",
-							      sizeof (CamelNNTPFolder),
-							      sizeof (CamelNNTPFolderClass),
-							      (CamelObjectClassInitFunc) nntp_folder_class_init,
-							      NULL,
-							      (CamelObjectInitFunc) nntp_folder_init,
-							      (CamelObjectFinalizeFunc) nntp_folder_finalise);
-	}
-
-	return camel_nntp_folder_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_DISCO_FOLDER,
+			"CamelNNTPFolder",
+			sizeof (CamelNNTPFolderClass),
+			(GClassInitFunc) nntp_folder_class_init,
+			sizeof (CamelNNTPFolder),
+			(GInstanceInitFunc) nntp_folder_init,
+			0);
+
+	return type;
 }
 
 CamelFolder *
@@ -540,7 +523,7 @@ camel_nntp_folder_new (CamelStore *parent, const gchar *folder_name, CamelExcept
 	/* If this doesn't work, stuff wont save, but let it continue anyway */
 	g_mkdir_with_parents (root, 0777);
 
-	folder = (CamelFolder *) camel_object_new (CAMEL_NNTP_FOLDER_TYPE);
+	folder = g_object_new (CAMEL_TYPE_NNTP_FOLDER, NULL);
 	nntp_folder = (CamelNNTPFolder *)folder;
 
 	camel_folder_construct (folder, parent, folder_name, folder_name);
@@ -569,7 +552,7 @@ camel_nntp_folder_new (CamelStore *parent, const gchar *folder_name, CamelExcept
 	if (subscribed) {
 		camel_folder_refresh_info(folder, ex);
 		if (camel_exception_is_set(ex)) {
-			camel_object_unref (folder);
+			g_object_unref (folder);
 			folder = NULL;
 		}
         }
diff --git a/camel/providers/nntp/camel-nntp-folder.h b/camel/providers/nntp/camel-nntp-folder.h
index 7d43231..8f3c23b 100644
--- a/camel/providers/nntp/camel-nntp-folder.h
+++ b/camel/providers/nntp/camel-nntp-folder.h
@@ -23,17 +23,28 @@
  */
 
 #ifndef CAMEL_NNTP_FOLDER_H
-#define CAMEL_NNTP_FOLDER_H 1
-
-#include "camel/camel-folder.h"
-#include "camel/camel-disco-folder.h"
-
-/*  #include "camel-store.h" */
-
-#define CAMEL_NNTP_FOLDER_TYPE     (camel_nntp_folder_get_type ())
-#define CAMEL_NNTP_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_NNTP_FOLDER_TYPE, CamelNNTPFolder))
-#define CAMEL_NNTP_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_NNTP_FOLDER_TYPE, CamelNNTPFolderClass))
-#define CAMEL_IS_NNTP_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_NNTP_FOLDER_TYPE))
+#define CAMEL_NNTP_FOLDER_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_NNTP_FOLDER \
+	(camel_nntp_folder_get_type ())
+#define CAMEL_NNTP_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_NNTP_FOLDER, CamelNNTPFolder))
+#define CAMEL_NNTP_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_NNTP_FOLDER, CamelNNTPFolderClass))
+#define CAMEL_IS_NNTP_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_NNTP_FOLDER))
+#define CAMEL_IS_NNTP_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_NNTP_FOLDER))
+#define CAMEL_NNTP_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_NNTP_FOLDER, CamelNNTPFolderClass))
 
 G_BEGIN_DECLS
 
@@ -55,10 +66,7 @@ struct _CamelNNTPFolderClass {
 	CamelDiscoFolderClass parent;
 };
 
-/* public methods */
-
-/* Standard Camel function */
-CamelType camel_nntp_folder_get_type (void);
+GType camel_nntp_folder_get_type (void);
 
 CamelFolder *camel_nntp_folder_new (CamelStore *parent, const gchar *folder_name, CamelException *ex);
 
diff --git a/camel/providers/nntp/camel-nntp-grouplist.c b/camel/providers/nntp/camel-nntp-grouplist.c
index c74bae4..062cca3 100644
--- a/camel/providers/nntp/camel-nntp-grouplist.c
+++ b/camel/providers/nntp/camel-nntp-grouplist.c
@@ -28,11 +28,8 @@
 #include <errno.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
-#include "camel-exception.h"
-
 #include "camel-nntp-grouplist.h"
 #include "camel-nntp-resp-codes.h"
 
diff --git a/camel/providers/nntp/camel-nntp-grouplist.h b/camel/providers/nntp/camel-nntp-grouplist.h
index 036b135..b1e5997 100644
--- a/camel/providers/nntp/camel-nntp-grouplist.h
+++ b/camel/providers/nntp/camel-nntp-grouplist.h
@@ -22,7 +22,7 @@
  */
 
 #ifndef CAMEL_NNTP_GROUPLIST_H
-#define CAMEL_NNTP_GROUPLIST_H 1
+#define CAMEL_NNTP_GROUPLIST_H
 
 #include <time.h>
 #include "camel-nntp-store.h"
diff --git a/camel/providers/nntp/camel-nntp-newsrc.c b/camel/providers/nntp/camel-nntp-newsrc.c
index 05281a8..f9a6e37 100644
--- a/camel/providers/nntp/camel-nntp-newsrc.c
+++ b/camel/providers/nntp/camel-nntp-newsrc.c
@@ -32,11 +32,8 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
-#include "camel-folder-summary.h"
-
 #include "camel-nntp-newsrc.h"
 
 #define NEWSRC_LOCK(f, l) (g_mutex_lock(((CamelNNTPNewsrc *)f)->l))
diff --git a/camel/providers/nntp/camel-nntp-newsrc.h b/camel/providers/nntp/camel-nntp-newsrc.h
index 3160b7f..16093d3 100644
--- a/camel/providers/nntp/camel-nntp-newsrc.h
+++ b/camel/providers/nntp/camel-nntp-newsrc.h
@@ -1,6 +1,6 @@
 
-#ifndef _CAMEL_NNTP_NEWSRC_H_
-#define _CAMEL_NNTP_NEWSRC_H_
+#ifndef CAMEL_NNTP_NEWSRC_H
+#define CAMEL_NNTP_NEWSRC_H
 
 #include <stdio.h>
 #include "glib.h"
@@ -33,4 +33,4 @@ CamelNNTPNewsrc *camel_nntp_newsrc_read_for_server            (const gchar *serv
 
 G_END_DECLS
 
-#endif /* _CAMEL_NNTP_NEWSRC_H_ */
+#endif /* CAMEL_NNTP_NEWSRC_H */
diff --git a/camel/providers/nntp/camel-nntp-private.h b/camel/providers/nntp/camel-nntp-private.h
index e60daf9..a4d8744 100644
--- a/camel/providers/nntp/camel-nntp-private.h
+++ b/camel/providers/nntp/camel-nntp-private.h
@@ -21,7 +21,7 @@
  */
 
 #ifndef CAMEL_NNTP_PRIVATE_H
-#define CAMEL_NNTP_PRIVATE_H 1
+#define CAMEL_NNTP_PRIVATE_H
 
 /* need a way to configure and save this data, if this header is to
    be installed.  For now, dont install it */
diff --git a/camel/providers/nntp/camel-nntp-provider.c b/camel/providers/nntp/camel-nntp-provider.c
index be8e29e..3f8a3ac 100644
--- a/camel/providers/nntp/camel-nntp-provider.c
+++ b/camel/providers/nntp/camel-nntp-provider.c
@@ -31,8 +31,6 @@
 #include <glib/gi18n-lib.h>
 
 #include "camel-nntp-store.h"
-#include "camel-provider.h"
-#include "camel-session.h"
 
 static void add_hash (guint *hash, gchar *s);
 static guint nntp_url_hash (gconstpointer key);
@@ -83,7 +81,7 @@ CamelServiceAuthType camel_nntp_password_authtype = {
 void
 camel_provider_module_init(void)
 {
-	news_provider.object_types[CAMEL_PROVIDER_STORE] = camel_nntp_store_get_type();
+	news_provider.object_types[CAMEL_PROVIDER_STORE] = camel_nntp_store_get_type ();
 
 	news_provider.url_hash = nntp_url_hash;
 	news_provider.url_equal = nntp_url_equal;
diff --git a/camel/providers/nntp/camel-nntp-resp-codes.h b/camel/providers/nntp/camel-nntp-resp-codes.h
index d1beb81..1cfe517 100644
--- a/camel/providers/nntp/camel-nntp-resp-codes.h
+++ b/camel/providers/nntp/camel-nntp-resp-codes.h
@@ -21,7 +21,7 @@
  */
 
 #ifndef CAMEL_NNTP_RESP_CODES_H
-#define CAMEL_NNTP_RESP_CODES_H 1
+#define CAMEL_NNTP_RESP_CODES_H
 
 #define CAMEL_NNTP_OK(x) ((x) < 400)
 #define CAMEL_NNTP_ERR(x) (!CAMEL_NNTP_OK(x) && (x) < 500)
diff --git a/camel/providers/nntp/camel-nntp-store-summary.c b/camel/providers/nntp/camel-nntp-store-summary.c
index dd72d28..84ac5cb 100644
--- a/camel/providers/nntp/camel-nntp-store-summary.c
+++ b/camel/providers/nntp/camel-nntp-store-summary.c
@@ -29,9 +29,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "camel-file-utils.h"
 #include "camel-private.h"
-#include "camel-utf8.h"
 
 #include "camel-nntp-store-summary.h"
 
@@ -43,12 +41,9 @@
 
 #define CAMEL_NNTP_STORE_SUMMARY_VERSION (1)
 
-#define _PRIVATE(o) (((CamelNNTPStoreSummary *)(o))->priv)
-
 static gint summary_header_load(CamelStoreSummary *, FILE *);
 static gint summary_header_save(CamelStoreSummary *, FILE *);
 
-/*static CamelStoreInfo * store_info_new(CamelStoreSummary *, const gchar *);*/
 static CamelStoreInfo * store_info_load(CamelStoreSummary *, FILE *);
 static gint		 store_info_save(CamelStoreSummary *, FILE *, CamelStoreInfo *);
 static void		 store_info_free(CamelStoreSummary *, CamelStoreInfo *);
@@ -56,66 +51,54 @@ static void		 store_info_free(CamelStoreSummary *, CamelStoreInfo *);
 static const gchar *store_info_string(CamelStoreSummary *, const CamelStoreInfo *, gint);
 static void store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int, const gchar *);
 
-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 CamelStoreSummaryClass *camel_nntp_store_summary_parent;
+static gpointer parent_class;
 
 static void
-camel_nntp_store_summary_class_init (CamelNNTPStoreSummaryClass *klass)
+nntp_store_summary_class_init (CamelNNTPStoreSummaryClass *class)
 {
-	CamelStoreSummaryClass *ssklass = (CamelStoreSummaryClass *)klass;
-
-	ssklass->summary_header_load = summary_header_load;
-	ssklass->summary_header_save = summary_header_save;
-
-	/*ssklass->store_info_new  = store_info_new;*/
-	ssklass->store_info_load = store_info_load;
-	ssklass->store_info_save = store_info_save;
-	ssklass->store_info_free = store_info_free;
-
-	ssklass->store_info_string = store_info_string;
-	ssklass->store_info_set_string = store_info_set_string;
+	CamelStoreSummaryClass *store_summary_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (class);
+	store_summary_class->summary_header_load = summary_header_load;
+	store_summary_class->summary_header_save = summary_header_save;
+	store_summary_class->store_info_load = store_info_load;
+	store_summary_class->store_info_save = store_info_save;
+	store_summary_class->store_info_free = store_info_free;
+	store_summary_class->store_info_string = store_info_string;
+	store_summary_class->store_info_set_string = store_info_set_string;
 }
 
 static void
-camel_nntp_store_summary_init (CamelNNTPStoreSummary *s)
+nntp_store_summary_init (CamelNNTPStoreSummary *nntp_store_summary)
 {
-	/*struct _CamelNNTPStoreSummaryPrivate *p;
+	CamelStoreSummary *store_summary;
 
-	  p = _PRIVATE(s) = g_malloc0(sizeof(*p));*/
+	store_summary = CAMEL_STORE_SUMMARY (nntp_store_summary);
+	store_summary->store_info_size = sizeof (CamelNNTPStoreInfo);
 
-	((CamelStoreSummary *) s)->store_info_size = sizeof (CamelNNTPStoreInfo);
-	s->version = CAMEL_NNTP_STORE_SUMMARY_VERSION;
-	memset (&s->last_newslist, 0, sizeof (s->last_newslist));
-}
+	nntp_store_summary->version = CAMEL_NNTP_STORE_SUMMARY_VERSION;
 
-static void
-camel_nntp_store_summary_finalise (CamelObject *obj)
-{
-	/*struct _CamelNNTPStoreSummaryPrivate *p;*/
-	/*CamelNNTPStoreSummary *s = (CamelNNTPStoreSummary *)obj;*/
-
-	/*p = _PRIVATE(obj);
-	  g_free(p);*/
+	memset (
+		&nntp_store_summary->last_newslist, 0,
+		sizeof (nntp_store_summary->last_newslist));
 }
 
-CamelType
+GType
 camel_nntp_store_summary_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		camel_nntp_store_summary_parent = (CamelStoreSummaryClass *)camel_store_summary_get_type();
-		type = camel_type_register((CamelType)camel_nntp_store_summary_parent, "CamelNNTPStoreSummary",
-					   sizeof (CamelNNTPStoreSummary),
-					   sizeof (CamelNNTPStoreSummaryClass),
-					   (CamelObjectClassInitFunc) camel_nntp_store_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_nntp_store_summary_init,
-					   (CamelObjectFinalizeFunc) camel_nntp_store_summary_finalise);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE_SUMMARY,
+			"CamelNNTPStoreSummary",
+			sizeof (CamelNNTPStoreSummaryClass),
+			(GClassInitFunc) nntp_store_summary_class_init,
+			sizeof (CamelNNTPStoreSummary),
+			(GInstanceInitFunc) nntp_store_summary_init,
+			0);
 
 	return type;
 }
@@ -130,7 +113,7 @@ camel_nntp_store_summary_get_type (void)
 CamelNNTPStoreSummary *
 camel_nntp_store_summary_new (void)
 {
-	return (CamelNNTPStoreSummary *) camel_object_new (camel_nntp_store_summary_get_type ());
+	return g_object_new (CAMEL_TYPE_NNTP_STORE_SUMMARY, NULL);
 }
 
 /**
@@ -315,7 +298,7 @@ summary_header_load (CamelStoreSummary *s, FILE *in)
 	CamelNNTPStoreSummary *is = (CamelNNTPStoreSummary *) s;
 	gint32 version, nil;
 
-	if (camel_nntp_store_summary_parent->summary_header_load ((CamelStoreSummary *) s, in) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->summary_header_load ((CamelStoreSummary *) s, in) == -1
 	    || camel_file_util_decode_fixed_int32 (in, &version) == -1)
 		return -1;
 
@@ -340,7 +323,7 @@ summary_header_save (CamelStoreSummary *s, FILE *out)
 	CamelNNTPStoreSummary *is = (CamelNNTPStoreSummary *) s;
 
 	/* always write as latest version */
-	if (camel_nntp_store_summary_parent->summary_header_save ((CamelStoreSummary *) s, out) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->summary_header_save ((CamelStoreSummary *) s, out) == -1
 	    || camel_file_util_encode_fixed_int32 (out, CAMEL_NNTP_STORE_SUMMARY_VERSION) == -1
 	    || fwrite (is->last_newslist, 1, NNTP_DATE_SIZE, out) < NNTP_DATE_SIZE
 	    || camel_file_util_encode_fixed_int32 (out, 0) == -1)
@@ -354,7 +337,7 @@ store_info_load (CamelStoreSummary *s, FILE *in)
 {
 	CamelNNTPStoreInfo *ni;
 
-	ni = (CamelNNTPStoreInfo *) camel_nntp_store_summary_parent->store_info_load (s, in);
+	ni = (CamelNNTPStoreInfo *) CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_load (s, in);
 	if (ni) {
 		if (camel_file_util_decode_string (in, &ni->full_name) == -1) {
 			camel_store_summary_info_free (s, (CamelStoreInfo *) ni);
@@ -378,7 +361,7 @@ store_info_save (CamelStoreSummary *s, FILE *out, CamelStoreInfo *mi)
 {
 	CamelNNTPStoreInfo *isi = (CamelNNTPStoreInfo *)mi;
 
-	if (camel_nntp_store_summary_parent->store_info_save (s, out, mi) == -1
+	if (CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_save (s, out, mi) == -1
 	    || camel_file_util_encode_string (out, isi->full_name) == -1
 	    || camel_file_util_encode_uint32(out, isi->first) == -1
 	    || camel_file_util_encode_uint32(out, isi->last) == -1)
@@ -393,7 +376,7 @@ store_info_free (CamelStoreSummary *s, CamelStoreInfo *mi)
 	CamelNNTPStoreInfo *nsi = (CamelNNTPStoreInfo *) mi;
 
 	g_free (nsi->full_name);
-	camel_nntp_store_summary_parent->store_info_free (s, mi);
+	CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_free (s, mi);
 }
 
 static const gchar *
@@ -409,7 +392,7 @@ store_info_string(CamelStoreSummary *s, const CamelStoreInfo *mi, gint type)
 	case CAMEL_NNTP_STORE_INFO_FULL_NAME:
 		return nsi->full_name;
 	default:
-		return camel_nntp_store_summary_parent->store_info_string(s, mi, type);
+		return CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_string(s, mi, type);
 	}
 }
 
@@ -429,7 +412,7 @@ store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const
 		CAMEL_STORE_SUMMARY_UNLOCK(s, summary_lock);
 		break;
 	default:
-		camel_nntp_store_summary_parent->store_info_set_string (s, mi, type, str);
+		CAMEL_STORE_SUMMARY_CLASS (parent_class)->store_info_set_string (s, mi, type, str);
 		break;
 	}
 }
diff --git a/camel/providers/nntp/camel-nntp-store-summary.h b/camel/providers/nntp/camel-nntp-store-summary.h
index 15ae705..8cd598a 100644
--- a/camel/providers/nntp/camel-nntp-store-summary.h
+++ b/camel/providers/nntp/camel-nntp-store-summary.h
@@ -21,20 +21,35 @@
 
 /* currently, this is just a straigt s/imap/nntp from the IMAP file*/
 
-#ifndef _CAMEL_NNTP_STORE_SUMMARY_H
-#define _CAMEL_NNTP_STORE_SUMMARY_H
-
-#include <camel/camel-object.h>
-#include <camel/camel-store-summary.h>
-
-#define CAMEL_NNTP_STORE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_nntp_store_summary_get_type (), CamelNNTPStoreSummary)
-#define CAMEL_NNTP_STORE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_nntp_store_summary_get_type (), CamelNNTPStoreSummaryClass)
-#define CAMEL_IS_NNTP_STORE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_nntp_store_summary_get_type ())
+#ifndef CAMEL_NNTP_STORE_SUMMARY_H
+#define CAMEL_NNTP_STORE_SUMMARY_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_NNTP_STORE_SUMMARY \
+	(camel_nntp_store_summary_get_type ())
+#define CAMEL_NNTP_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_NNTP_STORE_SUMMARY, CamelNNTPStoreSummary))
+#define CAMEL_NNTP_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_NNTP_STORE_SUMMARY, CamelNNTPStoreSummaryClass))
+#define CAMEL_IS_NNTP_STORE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_NNTP_STORE_SUMMARY))
+#define CAMEL_IS_NNTP_STORE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_NNTP_STORE_SUMMARY))
+#define CAMEL_NNTP_STORE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_NNTP_STORE_SUMMARY, CamelNNTPStoreSummaryClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelNNTPStoreSummary      CamelNNTPStoreSummary;
+typedef struct _CamelNNTPStoreSummary CamelNNTPStoreSummary;
 typedef struct _CamelNNTPStoreSummaryClass CamelNNTPStoreSummaryClass;
+typedef struct _CamelNNTPStoreSummaryPrivate CamelNNTPStoreSummaryPrivate;
 
 typedef struct _CamelNNTPStoreInfo CamelNNTPStoreInfo;
 
@@ -55,7 +70,7 @@ struct _CamelNNTPStoreInfo {
 struct _CamelNNTPStoreSummary {
 	CamelStoreSummary summary;
 
-	struct _CamelNNTPStoreSummaryPrivate *priv;
+	CamelNNTPStoreSummaryPrivate *priv;
 
 	/* header info */
 	guint32 version;	/* version of base part of file */
@@ -66,7 +81,7 @@ struct _CamelNNTPStoreSummaryClass {
 	CamelStoreSummaryClass summary_class;
 };
 
-CamelType			 camel_nntp_store_summary_get_type	(void);
+GType			 camel_nntp_store_summary_get_type	(void);
 CamelNNTPStoreSummary      *camel_nntp_store_summary_new	(void);
 
 /* TODO: this api needs some more work, needs to support lists */
@@ -92,4 +107,4 @@ gchar *camel_nntp_store_summary_full_from_path(CamelNNTPStoreSummary *s, const g
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_NNTP_STORE_SUMMARY_H */
+#endif /* CAMEL_NNTP_STORE_SUMMARY_H */
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 200a09d..eff8fac 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -34,18 +34,7 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel/camel-data-cache.h"
-#include "camel/camel-debug.h"
-#include "camel/camel-disco-diary.h"
-#include "camel/camel-disco-store.h"
-#include "camel/camel-net-utils.h"
-#include "camel/camel-private.h"
-#include "camel/camel-session.h"
-#include "camel/camel-stream-mem.h"
-#include "camel/camel-string-utils.h"
-#include "camel/camel-tcp-stream-raw.h"
-#include "camel/camel-tcp-stream-ssl.h"
-#include "camel/camel-url.h"
+#include "camel-private.h"
 
 #include "camel-nntp-summary.h"
 #include "camel-nntp-store.h"
@@ -62,19 +51,74 @@
 
 #define DUMP_EXTENSIONS
 
-static CamelDiscoStoreClass *parent_class = NULL;
-static CamelServiceClass *service_class = NULL;
+#define CAMEL_NNTP_STORE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_NNTP_STORE, CamelNNTPStorePrivate))
 
-/* Returns the class for a CamelNNTPStore */
-#define CNNTPS_CLASS(so) CAMEL_NNTP_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CNNTPF_CLASS(so) CAMEL_NNTP_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static gint camel_nntp_try_authenticate (CamelNNTPStore *store, CamelException *ex);
 
-static void nntp_construct (CamelService *service, CamelSession *session,
-			    CamelProvider *provider, CamelURL *url,
-			    CamelException *ex);
+static void
+nntp_store_dispose (GObject *object)
+{
+	CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (object);
+	CamelDiscoStore *disco_store = CAMEL_DISCO_STORE (object);
+
+	/* Only run this the first time. */
+	if (nntp_store->summary != NULL)
+		camel_service_disconnect (CAMEL_SERVICE (object), TRUE, NULL);
+
+	if (nntp_store->summary != NULL) {
+		camel_store_summary_save (
+			CAMEL_STORE_SUMMARY (nntp_store->summary));
+		g_object_unref (nntp_store->summary);
+		nntp_store->summary = NULL;
+	}
+
+	if (nntp_store->mem != NULL) {
+		g_object_unref (nntp_store->mem);
+		nntp_store->mem = NULL;
+	}
+
+	if (nntp_store->stream != NULL) {
+		g_object_unref (nntp_store->stream);
+		nntp_store->stream = NULL;
+	}
+
+	if (nntp_store->cache != NULL) {
+		g_object_unref (nntp_store->cache);
+		nntp_store->cache = NULL;
+	}
+
+	if (disco_store->diary != NULL) {
+		g_object_unref (disco_store->diary);
+		disco_store->diary = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+nntp_store_finalize (GObject *object)
+{
+	CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (object);
+	struct _xover_header *xover, *xn;
+
+	g_free (nntp_store->base_url);
+	g_free (nntp_store->storage_path);
+
+	xover = nntp_store->xover;
+	while (xover) {
+		xn = xover->next;
+		g_free(xover);
+		xover = xn;
+	}
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
 
 static gboolean
 nntp_can_work_offline(CamelDiscoStore *store)
@@ -198,13 +242,13 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 					      service->url->host,
 					      g_strerror (errno));
 
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 
 		goto fail;
 	}
 
 	store->stream = (CamelNNTPStream *) camel_nntp_stream_new (tcp_stream);
-	camel_object_unref (tcp_stream);
+	g_object_unref (tcp_stream);
 
 	/* Read the greeting, if any. */
 	if (camel_nntp_stream_line (store->stream, &buf, &len) == -1) {
@@ -216,7 +260,7 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 					      _("Could not read greeting from %s: %s"),
 					      service->url->host, g_strerror (errno));
 
-		camel_object_unref (store->stream);
+		g_object_unref (store->stream);
 		store->stream = NULL;
 
 		goto fail;
@@ -228,7 +272,7 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 				      _("NNTP server %s returned error code %d: %s"),
 				      service->url->host, len, buf);
 
-		camel_object_unref (store->stream);
+		g_object_unref (store->stream);
 		store->stream = NULL;
 
 		goto fail;
@@ -335,7 +379,7 @@ nntp_connect_offline (CamelService *service, CamelException *ex)
 
 	/* setup store-wide cache */
 	if (nntp_store->cache == NULL) {
-		nntp_store->cache = camel_data_cache_new (nntp_store->storage_path, 0, ex);
+		nntp_store->cache = camel_data_cache_new (nntp_store->storage_path, ex);
 		if (nntp_store->cache == NULL)
 			return FALSE;
 
@@ -361,8 +405,11 @@ static gboolean
 nntp_disconnect_online (CamelService *service, gboolean clean, CamelException *ex)
 {
 	CamelNNTPStore *store = CAMEL_NNTP_STORE (service);
+	CamelServiceClass *service_class;
 	gchar *line;
 
+	service_class = CAMEL_SERVICE_CLASS (parent_class);
+
 	CAMEL_SERVICE_REC_LOCK(store, connect_lock);
 
 	if (clean) {
@@ -370,12 +417,13 @@ nntp_disconnect_online (CamelService *service, gboolean clean, CamelException *e
 		camel_exception_clear(ex);
 	}
 
+	/* Chain up to parent's disconnect() method. */
 	if (!service_class->disconnect (service, clean, ex)) {
 		CAMEL_SERVICE_REC_UNLOCK(store, connect_lock);
 		return FALSE;
 	}
 
-	camel_object_unref (store->stream);
+	g_object_unref (store->stream);
 	store->stream = NULL;
 	g_free(store->current_folder);
 	store->current_folder = NULL;
@@ -389,12 +437,16 @@ static gboolean
 nntp_disconnect_offline (CamelService *service, gboolean clean, CamelException *ex)
 {
 	CamelDiscoStore *disco = CAMEL_DISCO_STORE(service);
+	CamelServiceClass *service_class;
 
+	service_class = CAMEL_SERVICE_CLASS (parent_class);
+
+	/* Chain up to parent's disconnect() method. */
 	if (!service_class->disconnect (service, clean, ex))
 		return FALSE;
 
 	if (disco->diary) {
-		camel_object_unref (disco->diary);
+		g_object_unref (disco->diary);
 		disco->diary = NULL;
 	}
 
@@ -625,7 +677,7 @@ nntp_store_get_subscribed_folder_info (CamelNNTPStore *store, const gchar *top,
 						camel_object_trigger_event((CamelObject *) folder, "folder_changed", changes);
 						camel_folder_change_info_free(changes);
 					}
-					camel_object_unref(folder);
+					g_object_unref (folder);
 				}
 				camel_exception_clear(ex);
 			}
@@ -987,50 +1039,6 @@ nntp_delete_folder (CamelStore *store, const gchar *folder_name, CamelException
 	return;
 }
 
-static void
-nntp_store_finalize (CamelObject *object)
-{
-	/* call base finalize */
-	CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (object);
-	CamelDiscoStore *disco_store = (CamelDiscoStore *) nntp_store;
-	struct _CamelNNTPStorePrivate *p = nntp_store->priv;
-	struct _xover_header *xover, *xn;
-
-	camel_service_disconnect ((CamelService *)object, TRUE, NULL);
-
-	if (nntp_store->summary) {
-		camel_store_summary_save ((CamelStoreSummary *) nntp_store->summary);
-		camel_object_unref (nntp_store->summary);
-	}
-
-	camel_object_unref (nntp_store->mem);
-	nntp_store->mem = NULL;
-	if (nntp_store->stream)
-		camel_object_unref (nntp_store->stream);
-
-	if (nntp_store->base_url)
-		g_free (nntp_store->base_url);
-	if (nntp_store->storage_path)
-		g_free (nntp_store->storage_path);
-
-	xover = nntp_store->xover;
-	while (xover) {
-		xn = xover->next;
-		g_free(xover);
-		xover = xn;
-	}
-
-	if (nntp_store->cache)
-		camel_object_unref(nntp_store->cache);
-
-	if (disco_store->diary) {
-		camel_object_unref (disco_store->diary);
-		disco_store->diary = NULL;
-	}
-
-	g_free(p);
-}
-
 static gboolean
 nntp_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex)
 {
@@ -1038,46 +1046,6 @@ nntp_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelExceptio
 	return TRUE;
 }
 
-static void
-nntp_store_class_init (CamelNNTPStoreClass *camel_nntp_store_class)
-{
-	CamelDiscoStoreClass *camel_disco_store_class = CAMEL_DISCO_STORE_CLASS (camel_nntp_store_class);
-	CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_nntp_store_class);
-	CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS (camel_nntp_store_class);
-
-	parent_class = CAMEL_DISCO_STORE_CLASS (camel_type_get_global_classfuncs (camel_disco_store_get_type ()));
-	service_class = CAMEL_SERVICE_CLASS (camel_type_get_global_classfuncs (camel_service_get_type ()));
-
-	/* virtual method overload */
-	camel_service_class->construct = nntp_construct;
-	camel_service_class->query_auth_types = nntp_store_query_auth_types;
-	camel_service_class->get_name = nntp_store_get_name;
-
-	camel_disco_store_class->can_work_offline = nntp_can_work_offline;
-	camel_disco_store_class->connect_online = nntp_connect_online;
-	camel_disco_store_class->connect_offline = nntp_connect_offline;
-	camel_disco_store_class->disconnect_online = nntp_disconnect_online;
-	camel_disco_store_class->disconnect_offline = nntp_disconnect_offline;
-	camel_disco_store_class->get_folder_online = nntp_get_folder;
-	camel_disco_store_class->get_folder_resyncing = nntp_get_folder;
-	camel_disco_store_class->get_folder_offline = nntp_get_folder;
-
-	camel_disco_store_class->get_folder_info_online = nntp_get_folder_info_online;
-	camel_disco_store_class->get_folder_info_resyncing = nntp_get_folder_info_online;
-	camel_disco_store_class->get_folder_info_offline = nntp_get_folder_info_offline;
-
-	camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-
-	camel_store_class->folder_subscribed = nntp_store_folder_subscribed;
-	camel_store_class->subscribe_folder = nntp_store_subscribe_folder;
-	camel_store_class->unsubscribe_folder = nntp_store_unsubscribe_folder;
-
-	camel_store_class->create_folder = nntp_create_folder;
-	camel_store_class->delete_folder = nntp_delete_folder;
-	camel_store_class->rename_folder = nntp_rename_folder;
-	camel_store_class->can_refresh_folder = nntp_can_refresh_folder;
-}
-
 /* construction function in which we set some basic store properties */
 static void
 nntp_construct (CamelService *service, CamelSession *session,
@@ -1124,7 +1092,7 @@ nntp_construct (CamelService *service, CamelSession *session,
 		nntp_store->folder_hierarchy_relative = FALSE;
 
 	/* setup store-wide cache */
-	nntp_store->cache = camel_data_cache_new(nntp_store->storage_path, 0, ex);
+	nntp_store->cache = camel_data_cache_new(nntp_store->storage_path, ex);
 	if (nntp_store->cache == NULL)
 		return;
 
@@ -1134,37 +1102,77 @@ nntp_construct (CamelService *service, CamelSession *session,
 }
 
 static void
-nntp_store_init (gpointer object, gpointer klass)
+nntp_store_class_init (CamelNNTPStoreClass *class)
+{
+	GObjectClass *object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
+	CamelDiscoStoreClass *disco_store_class;
+
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelNNTPStorePrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = nntp_store_dispose;
+	object_class->finalize = nntp_store_finalize;
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = nntp_construct;
+	service_class->query_auth_types = nntp_store_query_auth_types;
+	service_class->get_name = nntp_store_get_name;
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->free_folder_info = camel_store_free_folder_info_full;
+	store_class->folder_subscribed = nntp_store_folder_subscribed;
+	store_class->subscribe_folder = nntp_store_subscribe_folder;
+	store_class->unsubscribe_folder = nntp_store_unsubscribe_folder;
+	store_class->create_folder = nntp_create_folder;
+	store_class->delete_folder = nntp_delete_folder;
+	store_class->rename_folder = nntp_rename_folder;
+	store_class->can_refresh_folder = nntp_can_refresh_folder;
+
+	disco_store_class = CAMEL_DISCO_STORE_CLASS (class);
+	disco_store_class->can_work_offline = nntp_can_work_offline;
+	disco_store_class->connect_online = nntp_connect_online;
+	disco_store_class->connect_offline = nntp_connect_offline;
+	disco_store_class->disconnect_online = nntp_disconnect_online;
+	disco_store_class->disconnect_offline = nntp_disconnect_offline;
+	disco_store_class->get_folder_online = nntp_get_folder;
+	disco_store_class->get_folder_resyncing = nntp_get_folder;
+	disco_store_class->get_folder_offline = nntp_get_folder;
+	disco_store_class->get_folder_info_online = nntp_get_folder_info_online;
+	disco_store_class->get_folder_info_resyncing = nntp_get_folder_info_online;
+	disco_store_class->get_folder_info_offline = nntp_get_folder_info_offline;
+}
+
+static void
+nntp_store_init (CamelNNTPStore *nntp_store)
 {
-	CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE(object);
-	CamelStore *store = CAMEL_STORE (object);
-	struct _CamelNNTPStorePrivate *p;
+	CamelStore *store = CAMEL_STORE (nntp_store);
 
 	store->flags = CAMEL_STORE_SUBSCRIPTIONS;
 
 	nntp_store->mem = (CamelStreamMem *)camel_stream_mem_new();
 
-	p = nntp_store->priv = g_malloc0(sizeof(*p));
+	nntp_store->priv = CAMEL_NNTP_STORE_GET_PRIVATE (nntp_store);
 }
 
-CamelType
+GType
 camel_nntp_store_get_type (void)
 {
-	static CamelType camel_nntp_store_type = CAMEL_INVALID_TYPE;
-
-	if (camel_nntp_store_type == CAMEL_INVALID_TYPE) {
-		camel_nntp_store_type =
-			camel_type_register (CAMEL_DISCO_STORE_TYPE,
-					     "CamelNNTPStore",
-					     sizeof (CamelNNTPStore),
-					     sizeof (CamelNNTPStoreClass),
-					     (CamelObjectClassInitFunc) nntp_store_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) nntp_store_init,
-					     (CamelObjectFinalizeFunc) nntp_store_finalize);
-	}
-
-	return camel_nntp_store_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_DISCO_STORE,
+			"CamelNNTPStore",
+			sizeof (CamelNNTPStoreClass),
+			(GClassInitFunc) nntp_store_class_init,
+			sizeof (CamelNNTPStore),
+			(GInstanceInitFunc) nntp_store_init,
+			0);
+
+	return type;
 }
 
 static gint
@@ -1235,6 +1243,7 @@ camel_nntp_try_authenticate (CamelNNTPStore *store, CamelException *ex)
 gint
 camel_nntp_raw_commandv (CamelNNTPStore *store, CamelException *ex, gchar **line, const gchar *fmt, va_list ap)
 {
+	GByteArray *buffer;
 	const guchar *p, *ps;
 	guchar c;
 	gchar *s;
@@ -1287,15 +1296,16 @@ camel_nntp_raw_commandv (CamelNNTPStore *store, CamelException *ex, gchar **line
 	}
 
 	camel_stream_write ((CamelStream *) store->mem, (const gchar *) ps, p-ps-1);
-	dd(printf("NNTP_COMMAND: '%.*s'\n", (gint)store->mem->buffer->len, store->mem->buffer->data));
 	camel_stream_write ((CamelStream *) store->mem, "\r\n", 2);
 
-	if (camel_stream_write((CamelStream *) store->stream, (const gchar *) store->mem->buffer->data, store->mem->buffer->len) == -1)
+	buffer = camel_stream_mem_get_byte_array (store->mem);
+
+	if (camel_stream_write((CamelStream *) store->stream, (const gchar *) buffer->data, buffer->len) == -1)
 		goto ioerror;
 
 	/* FIXME: hack */
 	camel_stream_reset ((CamelStream *) store->mem);
-	g_byte_array_set_size (store->mem->buffer, 0);
+	g_byte_array_set_size (buffer, 0);
 
 	if (camel_nntp_stream_line (store->stream, (guchar **) line, &u) == -1)
 		goto ioerror;
diff --git a/camel/providers/nntp/camel-nntp-store.h b/camel/providers/nntp/camel-nntp-store.h
index 73ec19f..1a07a95 100644
--- a/camel/providers/nntp/camel-nntp-store.h
+++ b/camel/providers/nntp/camel-nntp-store.h
@@ -21,17 +21,31 @@
  */
 
 #ifndef CAMEL_NNTP_STORE_H
-#define CAMEL_NNTP_STORE_H 1
+#define CAMEL_NNTP_STORE_H
 
-#include <camel/camel-disco-store.h>
+#include <camel/camel.h>
 
 #include "camel-nntp-stream.h"
 #include "camel-nntp-store-summary.h"
 
-#define CAMEL_NNTP_STORE_TYPE     (camel_nntp_store_get_type ())
-#define CAMEL_NNTP_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_NNTP_STORE_TYPE, CamelNNTPStore))
-#define CAMEL_NNTP_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_NNTP_STORE_TYPE, CamelNNTPStoreClass))
-#define CAMEL_IS_NNTP_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_NNTP_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_NNTP_STORE \
+	(camel_nntp_store_get_type ())
+#define CAMEL_NNTP_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_NNTP_STORE, CamelNNTPStore))
+#define CAMEL_NNTP_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_NNTP_STORE, CamelNNTPStoreClass))
+#define CAMEL_IS_NNTP_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_NNTP_STORE))
+#define CAMEL_IS_NNTP_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_NNTP_STORE))
+#define CAMEL_NNTP_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_NNTP_STORE, CamelNNTPStoreClass))
 
 #define CAMEL_NNTP_EXT_SEARCH     (1<<0)
 #define CAMEL_NNTP_EXT_SETGET     (1<<1)
@@ -66,7 +80,7 @@ struct _xover_header {
 };
 
 struct _CamelNNTPStore {
-	CamelDiscoStore parent_object;
+	CamelDiscoStore parent;
 
 	CamelNNTPStorePrivate *priv;
 
@@ -93,8 +107,7 @@ struct _CamelNNTPStoreClass {
 
 };
 
-/* Standard Camel function */
-CamelType camel_nntp_store_get_type (void);
+GType camel_nntp_store_get_type (void);
 
 gint camel_nntp_raw_commandv (CamelNNTPStore *store, struct _CamelException *ex, gchar **line, const gchar *fmt, va_list ap);
 gint camel_nntp_raw_command(CamelNNTPStore *store, struct _CamelException *ex, gchar **line, const gchar *fmt, ...);
diff --git a/camel/providers/nntp/camel-nntp-stream.c b/camel/providers/nntp/camel-nntp-stream.c
index fa2533e..c03432d 100644
--- a/camel/providers/nntp/camel-nntp-stream.c
+++ b/camel/providers/nntp/camel-nntp-stream.c
@@ -28,37 +28,56 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
-
-#include "camel-debug.h"
-
 #include "camel-nntp-stream.h"
 
-#define dd(x) (camel_debug("nntp:stream";)?(x):0)
+#define dd(x) (camel_debug ("nntp:stream";)?(x):0)
 
 #ifndef ECONNRESET
 #define ECONNRESET EIO
 #endif
 
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_NNTP_STREAM_CLASS(CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 #define CAMEL_NNTP_STREAM_SIZE (4096)
 #define CAMEL_NNTP_STREAM_LINE_SIZE (1024) /* maximum line size */
 
+static void
+nntp_stream_dispose (GObject *object)
+{
+	CamelNNTPStream *stream = CAMEL_NNTP_STREAM (object);
+
+	if (stream->source != NULL) {
+		g_object_unref (stream->source);
+		stream->source = NULL;
+	}
+
+	/* Chain up to parent's dispose () method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+nntp_stream_finalize (GObject *object)
+{
+	CamelNNTPStream *stream = CAMEL_NNTP_STREAM (object);
+
+	g_free (stream->buf);
+	g_free (stream->linebuf);
+
+	/* Chain up to parent's finalize () method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
 static gint
-stream_fill(CamelNNTPStream *is)
+stream_fill (CamelNNTPStream *is)
 {
 	gint left = 0;
 
 	if (is->source) {
 		left = is->end - is->ptr;
-		memcpy(is->buf, is->ptr, left);
+		memcpy (is->buf, is->ptr, left);
 		is->end = is->buf + left;
 		is->ptr = is->buf;
-		left = camel_stream_read(is->source, (gchar *) is->end, CAMEL_NNTP_STREAM_SIZE - (is->end - is->buf));
+		left = camel_stream_read (is->source, (gchar *) is->end, CAMEL_NNTP_STREAM_SIZE - (is->end - is->buf));
 		if (left > 0) {
 			is->end += left;
 			is->end[0] = '\n';
@@ -66,7 +85,7 @@ stream_fill(CamelNNTPStream *is)
 		} else {
 			if (left == 0)
 				errno = ECONNRESET;
-			dd(printf("NNTP_STREAM_FILL(ERROR): %d - '%s'\n", left, g_strerror(errno)));
+			dd (printf ("NNTP_STREAM_FILL (ERROR): %d - '%s'\n", left, g_strerror (errno)));
 			return -1;
 		}
 	}
@@ -75,7 +94,7 @@ stream_fill(CamelNNTPStream *is)
 }
 
 static gssize
-stream_read(CamelStream *stream, gchar *buffer, gsize n)
+stream_read (CamelStream *stream, gchar *buffer, gsize n)
 {
 	CamelNNTPStream *is = (CamelNNTPStream *)stream;
 	gchar *o, *oe;
@@ -98,7 +117,7 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 	case 0:		/* start of line, always read at least 3 chars */
 		while (e - p < 3) {
 			is->ptr = p;
-			if (stream_fill(is) == -1)
+			if (stream_fill (is) == -1)
 				return -1;
 			p = is->ptr;
 			e = is->end;
@@ -108,7 +127,7 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 				is->ptr = p+3;
 				is->mode = CAMEL_NNTP_STREAM_EOD;
 				is->state = 0;
-				dd(printf("NNTP_STREAM_READ(%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
+				dd (printf ("NNTP_STREAM_READ (%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
 				return o-buffer;
 			}
 			p++;
@@ -122,7 +141,7 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 				/* end of input sentinal check */
 				if (p > e) {
 					is->ptr = e;
-					if (stream_fill(is) == -1)
+					if (stream_fill (is) == -1)
 						return -1;
 					p = is->ptr;
 					e = is->end;
@@ -141,35 +160,35 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 	is->ptr = p;
 	is->state = state;
 
-	dd(printf("NNTP_STREAM_READ(%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
+	dd (printf ("NNTP_STREAM_READ (%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
 
 	return o-buffer;
 }
 
 static gssize
-stream_write(CamelStream *stream, const gchar *buffer, gsize n)
+stream_write (CamelStream *stream, const gchar *buffer, gsize n)
 {
 	CamelNNTPStream *is = (CamelNNTPStream *)stream;
 
-	return camel_stream_write(is->source, buffer, n);
+	return camel_stream_write (is->source, buffer, n);
 }
 
 static gint
-stream_close(CamelStream *stream)
+stream_close (CamelStream *stream)
 {
 	/* nop? */
 	return 0;
 }
 
 static gint
-stream_flush(CamelStream *stream)
+stream_flush (CamelStream *stream)
 {
 	/* nop? */
 	return 0;
 }
 
 static gboolean
-stream_eos(CamelStream *stream)
+stream_eos (CamelStream *stream)
 {
 	CamelNNTPStream *is = (CamelNNTPStream *)stream;
 
@@ -177,34 +196,39 @@ stream_eos(CamelStream *stream)
 }
 
 static gint
-stream_reset(CamelStream *stream)
+stream_reset (CamelStream *stream)
 {
 	/* nop?  reset literal mode? */
 	return 0;
 }
 
 static void
-camel_nntp_stream_class_init (CamelStreamClass *camel_nntp_stream_class)
+nntp_stream_class_init (CamelStreamClass *class)
 {
-	CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_nntp_stream_class;
-
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
-
-	/* virtual method definition */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->eos = stream_eos;
-	camel_stream_class->reset = stream_reset;
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = nntp_stream_dispose;
+	object_class->finalize = nntp_stream_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_read;
+	stream_class->write = stream_write;
+	stream_class->close = stream_close;
+	stream_class->flush = stream_flush;
+	stream_class->eos = stream_eos;
+	stream_class->reset = stream_reset;
 }
 
 static void
-camel_nntp_stream_init(CamelNNTPStream *is, CamelNNTPStreamClass *isclass)
+nntp_stream_init (CamelNNTPStream *is)
 {
 	/* +1 is room for appending a 0 if we need to for a line */
-	is->ptr = is->end = is->buf = g_malloc(CAMEL_NNTP_STREAM_SIZE+1);
-	is->lineptr = is->linebuf = g_malloc(CAMEL_NNTP_STREAM_LINE_SIZE+1);
+	is->ptr = is->end = is->buf = g_malloc (CAMEL_NNTP_STREAM_SIZE+1);
+	is->lineptr = is->linebuf = g_malloc (CAMEL_NNTP_STREAM_LINE_SIZE+1);
 	is->lineend = is->linebuf + CAMEL_NNTP_STREAM_LINE_SIZE;
 
 	/* init sentinal */
@@ -214,32 +238,22 @@ camel_nntp_stream_init(CamelNNTPStream *is, CamelNNTPStreamClass *isclass)
 	is->mode = CAMEL_NNTP_STREAM_LINE;
 }
 
-static void
-camel_nntp_stream_finalise(CamelNNTPStream *is)
-{
-	g_free(is->buf);
-	g_free(is->linebuf);
-	if (is->source)
-		camel_object_unref((CamelObject *)is->source);
-}
-
-CamelType
+GType
 camel_nntp_stream_get_type (void)
 {
-	static CamelType camel_nntp_stream_type = CAMEL_INVALID_TYPE;
-
-	if (camel_nntp_stream_type == CAMEL_INVALID_TYPE) {
-		camel_nntp_stream_type = camel_type_register( camel_stream_get_type(),
-							    "CamelNNTPStream",
-							    sizeof( CamelNNTPStream ),
-							    sizeof( CamelNNTPStreamClass ),
-							    (CamelObjectClassInitFunc) camel_nntp_stream_class_init,
-							    NULL,
-							    (CamelObjectInitFunc) camel_nntp_stream_init,
-							    (CamelObjectFinalizeFunc) camel_nntp_stream_finalise );
-	}
-
-	return camel_nntp_stream_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelNNTPStream",
+			sizeof (CamelNNTPStreamClass),
+			(GClassInitFunc) nntp_stream_class_init,
+			sizeof (CamelNNTPStream),
+			(GInstanceInitFunc) nntp_stream_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -251,20 +265,19 @@ camel_nntp_stream_get_type (void)
  * Return value: the stream
  **/
 CamelStream *
-camel_nntp_stream_new(CamelStream *source)
+camel_nntp_stream_new (CamelStream *source)
 {
 	CamelNNTPStream *is;
 
-	is = (CamelNNTPStream *)camel_object_new(camel_nntp_stream_get_type ());
-	camel_object_ref((CamelObject *)source);
-	is->source = source;
+	is = g_object_new (CAMEL_TYPE_NNTP_STREAM, NULL);
+	is->source = g_object_ref (source);
 
 	return (CamelStream *)is;
 }
 
 /* Get one line from the nntp stream */
 gint
-camel_nntp_stream_line(CamelNNTPStream *is, guchar **data, guint *len)
+camel_nntp_stream_line (CamelNNTPStream *is, guchar **data, guint *len)
 {
 	register guchar c, *p, *o, *oe;
 	gint newlen, oldlen;
@@ -286,7 +299,7 @@ camel_nntp_stream_line(CamelNNTPStream *is, guchar **data, guint *len)
 		/* need at least 3 chars in buffer */
 		while (e-p < 3) {
 			is->ptr = p;
-			if (stream_fill(is) == -1)
+			if (stream_fill (is) == -1)
 				return -1;
 			p = is->ptr;
 			e = is->end;
@@ -301,7 +314,7 @@ camel_nntp_stream_line(CamelNNTPStream *is, guchar **data, guint *len)
 				*len = 0;
 				is->linebuf[0] = 0;
 
-				dd(printf("NNTP_STREAM_LINE(END)\n"));
+				dd (printf ("NNTP_STREAM_LINE (END)\n"));
 
 				return 0;
 			}
@@ -316,7 +329,7 @@ camel_nntp_stream_line(CamelNNTPStream *is, guchar **data, guint *len)
 				/* sentinal? */
 				if (p> e) {
 					is->ptr = e;
-					if (stream_fill(is) == -1)
+					if (stream_fill (is) == -1)
 						return -1;
 					p = is->ptr;
 					e = is->end;
@@ -326,7 +339,7 @@ camel_nntp_stream_line(CamelNNTPStream *is, guchar **data, guint *len)
 					*len = o - is->linebuf;
 					*o = 0;
 
-					dd(printf("NNTP_STREAM_LINE(%d): '%s'\n", *len, *data));
+					dd (printf ("NNTP_STREAM_LINE (%d): '%s'\n", *len, *data));
 
 					return 1;
 				}
@@ -338,7 +351,7 @@ camel_nntp_stream_line(CamelNNTPStream *is, guchar **data, guint *len)
 		/* limit this for bad server data? */
 		oldlen = o - is->linebuf;
 		newlen = (is->lineend - is->linebuf) * 3 / 2;
-		is->lineptr = is->linebuf = g_realloc(is->linebuf, newlen);
+		is->lineptr = is->linebuf = g_realloc (is->linebuf, newlen);
 		is->lineend = is->linebuf + newlen;
 		oe = is->lineend - 1;
 		o = is->linebuf + oldlen;
@@ -348,7 +361,7 @@ camel_nntp_stream_line(CamelNNTPStream *is, guchar **data, guint *len)
 }
 
 /* returns -1 on error, 0 if last lot of data, >0 if more remaining */
-gint camel_nntp_stream_gets(CamelNNTPStream *is, guchar **start, guint *len)
+gint camel_nntp_stream_gets (CamelNNTPStream *is, guchar **start, guint *len)
 {
 	gint max;
 	guchar *end;
@@ -357,31 +370,31 @@ gint camel_nntp_stream_gets(CamelNNTPStream *is, guchar **start, guint *len)
 
 	max = is->end - is->ptr;
 	if (max == 0) {
-		max = stream_fill(is);
+		max = stream_fill (is);
 		if (max <= 0)
 			return max;
 	}
 
 	*start = is->ptr;
-	end = memchr(is->ptr, '\n', max);
+	end = memchr (is->ptr, '\n', max);
 	if (end)
 		max = (end - is->ptr) + 1;
 	*start = is->ptr;
 	*len = max;
 	is->ptr += max;
 
-	dd(printf("NNTP_STREAM_GETS(%s,%d): '%.*s'\n", end==NULL?"more":"last", *len, (gint)*len, *start));
+	dd (printf ("NNTP_STREAM_GETS (%s,%d): '%.*s'\n", end==NULL?"more":"last", *len, (gint)*len, *start));
 
 	return end == NULL?1:0;
 }
 
-void camel_nntp_stream_set_mode(CamelNNTPStream *is, camel_nntp_stream_mode_t mode)
+void camel_nntp_stream_set_mode (CamelNNTPStream *is, camel_nntp_stream_mode_t mode)
 {
 	is->mode = mode;
 }
 
 /* returns -1 on erorr, 0 if last data, >0 if more data left */
-gint camel_nntp_stream_getd(CamelNNTPStream *is, guchar **start, guint *len)
+gint camel_nntp_stream_getd (CamelNNTPStream *is, guchar **start, guint *len)
 {
 	guchar *p, *e, *s;
 	gint state;
@@ -392,7 +405,7 @@ gint camel_nntp_stream_getd(CamelNNTPStream *is, guchar **start, guint *len)
 		return 0;
 
 	if (is->mode == CAMEL_NNTP_STREAM_LINE) {
-		g_warning("nntp_stream reading data in line mode\n");
+		g_warning ("nntp_stream reading data in line mode\n");
 		return 0;
 	}
 
@@ -402,7 +415,7 @@ gint camel_nntp_stream_getd(CamelNNTPStream *is, guchar **start, guint *len)
 
 	while (e - p < 3) {
 		is->ptr = p;
-		if (stream_fill(is) == -1)
+		if (stream_fill (is) == -1)
 			return -1;
 		p = is->ptr;
 		e = is->end;
@@ -422,7 +435,7 @@ gint camel_nntp_stream_getd(CamelNNTPStream *is, guchar **start, guint *len)
 					is->mode = CAMEL_NNTP_STREAM_EOD;
 					is->state = 0;
 
-					dd(printf("NNTP_STREAM_GETD(%s,%d): '%.*s'\n", "last", *len, (gint)*len, *start));
+					dd (printf ("NNTP_STREAM_GETD (%s,%d): '%.*s'\n", "last", *len, (gint)*len, *start));
 
 					return 0;
 				}
@@ -437,7 +450,7 @@ gint camel_nntp_stream_getd(CamelNNTPStream *is, guchar **start, guint *len)
 					*start = s;
 					is->state = 1;
 
-					dd(printf("NNTP_STREAM_GETD(%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
+					dd (printf ("NNTP_STREAM_GETD (%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
 
 					return 1;
 				}
@@ -462,7 +475,7 @@ gint camel_nntp_stream_getd(CamelNNTPStream *is, guchar **start, guint *len)
 	*len = p-s;
 	*start = s;
 
-	dd(printf("NNTP_STREAM_GETD(%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
+	dd (printf ("NNTP_STREAM_GETD (%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
 	return 1;
 }
 
diff --git a/camel/providers/nntp/camel-nntp-stream.h b/camel/providers/nntp/camel-nntp-stream.h
index 6d8ac33..38171c5 100644
--- a/camel/providers/nntp/camel-nntp-stream.h
+++ b/camel/providers/nntp/camel-nntp-stream.h
@@ -18,19 +18,34 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_NNTP_STREAM_H
-#define _CAMEL_NNTP_STREAM_H
-
-#include <camel/camel-stream.h>
-
-#define CAMEL_NNTP_STREAM(obj)         CAMEL_CHECK_CAST (obj, camel_nntp_stream_get_type (), CamelNNTPStream)
-#define CAMEL_NNTP_STREAM_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_nntp_stream_get_type (), CamelNNTPStreamClass)
-#define CAMEL_IS_NNTP_STREAM(obj)      CAMEL_CHECK_TYPE (obj, camel_nntp_stream_get_type ())
+#ifndef CAMEL_NNTP_STREAM_H
+#define CAMEL_NNTP_STREAM_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_NNTP_STREAM \
+	(camel_nntp_stream_get_type ())
+#define CAMEL_NNTP_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_NNTP_STREAM, CamelNNTPStream))
+#define CAMEL_NNTP_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_NNTP_STREAM, CamelNNTPStreamClass))
+#define CAMEL_IS_NNTP_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_NNTP_STREAM))
+#define CAMEL_IS_NNTP_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_NNTP_STREAM))
+#define CAMEL_NNTP_STREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_NNTP_STREAM, CamelNNTPStreamClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelNNTPStreamClass CamelNNTPStreamClass;
 typedef struct _CamelNNTPStream CamelNNTPStream;
+typedef struct _CamelNNTPStreamClass CamelNNTPStreamClass;
 
 typedef enum {
 	CAMEL_NNTP_STREAM_LINE,
@@ -54,7 +69,7 @@ struct _CamelNNTPStreamClass {
 	CamelStreamClass parent_class;
 };
 
-CamelType		 camel_nntp_stream_get_type	(void);
+GType		 camel_nntp_stream_get_type	(void);
 
 CamelStream     *camel_nntp_stream_new		(CamelStream *source);
 
@@ -66,4 +81,4 @@ gint		 camel_nntp_stream_getd		(CamelNNTPStream *is, guchar **start, guint *len)
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_NNTP_STREAM_H */
+#endif /* CAMEL_NNTP_STREAM_H */
diff --git a/camel/providers/nntp/camel-nntp-summary.c b/camel/providers/nntp/camel-nntp-summary.c
index 5e7e3b7..fa29049 100644
--- a/camel/providers/nntp/camel-nntp-summary.c
+++ b/camel/providers/nntp/camel-nntp-summary.c
@@ -32,30 +32,25 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel/camel-data-cache.h"
-#include "camel/camel-db.h"
-#include "camel/camel-debug.h"
-#include "camel/camel-file-utils.h"
-#include "camel/camel-mime-message.h"
-#include "camel/camel-operation.h"
-#include "camel/camel-stream-null.h"
-
 #include "camel-nntp-folder.h"
 #include "camel-nntp-store.h"
 #include "camel-nntp-stream.h"
 #include "camel-nntp-summary.h"
-#include "camel-string-utils.h"
 
 #define w(x)
 #define io(x)
-#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
-#define dd(x) (camel_debug("nntp")?(x):0)
+#define d(x) /*(printf ("%s (%d): ", __FILE__, __LINE__),(x))*/
+#define dd(x) (camel_debug ("nntp")?(x):0)
 
 #define CAMEL_NNTP_SUMMARY_VERSION (1)
 
 #define EXTRACT_FIRST_DIGIT(val) val=strtoul (part, &part, 10);
 #define EXTRACT_DIGIT(val) part++; val=strtoul (part, &part, 10);
 
+#define CAMEL_NNTP_SUMMARY_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_NNTP_SUMMARY, CamelNNTPSummaryPrivate))
+
 struct _CamelNNTPSummaryPrivate {
 	gchar *uid;
 
@@ -63,90 +58,79 @@ struct _CamelNNTPSummaryPrivate {
 	gint xover_setup;
 };
 
-#define _PRIVATE(o) (((CamelNNTPSummary *)(o))->priv)
-
 static CamelMessageInfo * message_info_new_from_header (CamelFolderSummary *, struct _camel_header_raw *);
-static gint summary_header_load(CamelFolderSummary *, FILE *);
-static gint summary_header_save(CamelFolderSummary *, FILE *);
+static gint summary_header_load (CamelFolderSummary *, FILE *);
+static gint summary_header_save (CamelFolderSummary *, FILE *);
 static gint summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir);
 static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s, CamelException *ex);
 
-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 CamelFolderSummaryClass *camel_nntp_summary_parent;
-
-CamelType
-camel_nntp_summary_get_type(void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_folder_summary_get_type(), "CamelNNTPSummary",
-					   sizeof (CamelNNTPSummary),
-					   sizeof (CamelNNTPSummaryClass),
-					   (CamelObjectClassInitFunc) camel_nntp_summary_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_nntp_summary_init,
-					   (CamelObjectFinalizeFunc) camel_nntp_summary_finalise);
-	}
-
-	return type;
-}
+static gpointer parent_class;
 
 static void
-camel_nntp_summary_class_init(CamelNNTPSummaryClass *klass)
+nntp_summary_class_init (CamelNNTPSummaryClass *class)
 {
-	CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) klass;
+	CamelFolderSummaryClass *folder_summary_class;
 
-	camel_nntp_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS(camel_type_get_global_classfuncs(camel_folder_summary_get_type()));
+	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (CamelNNTPSummaryPrivate));
 
-	sklass->message_info_new_from_header  = message_info_new_from_header;
-	sklass->summary_header_load = summary_header_load;
-	sklass->summary_header_save = summary_header_save;
-	sklass->summary_header_from_db = summary_header_from_db;
-	sklass->summary_header_to_db = summary_header_to_db;
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->message_info_new_from_header = message_info_new_from_header;
+	folder_summary_class->summary_header_load = summary_header_load;
+	folder_summary_class->summary_header_save = summary_header_save;
+	folder_summary_class->summary_header_from_db = summary_header_from_db;
+	folder_summary_class->summary_header_to_db = summary_header_to_db;
 }
 
 static void
-camel_nntp_summary_init(CamelNNTPSummary *obj)
+nntp_summary_init (CamelNNTPSummary *nntp_summary)
 {
-	struct _CamelNNTPSummaryPrivate *p;
-	struct _CamelFolderSummary *s = (CamelFolderSummary *)obj;
+	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (nntp_summary);
 
-	p = _PRIVATE(obj) = g_malloc0(sizeof(*p));
+	nntp_summary->priv = CAMEL_NNTP_SUMMARY_GET_PRIVATE (nntp_summary);
 
 	/* subclasses need to set the right instance data sizes */
-	s->message_info_size = sizeof(CamelMessageInfoBase);
-	s->content_info_size = sizeof(CamelMessageContentInfo);
+	summary->message_info_size = sizeof (CamelMessageInfoBase);
+	summary->content_info_size = sizeof (CamelMessageContentInfo);
 
 	/* and a unique file version */
-	s->version += CAMEL_NNTP_SUMMARY_VERSION;
+	summary->version += CAMEL_NNTP_SUMMARY_VERSION;
 }
 
-static void
-camel_nntp_summary_finalise(CamelObject *obj)
+GType
+camel_nntp_summary_get_type (void)
 {
-	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY(obj);
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER_SUMMARY,
+			"CamelNNTPSummary",
+			sizeof (CamelNNTPSummaryClass),
+			(GClassInitFunc) nntp_summary_class_init,
+			sizeof (CamelNNTPSummary),
+			(GInstanceInitFunc) nntp_summary_init,
+			0);
 
-	g_free(cns->priv);
+	return type;
 }
 
 CamelNNTPSummary *
-camel_nntp_summary_new(struct _CamelFolder *folder, const gchar *path)
+camel_nntp_summary_new (struct _CamelFolder *folder, const gchar *path)
 {
-	CamelNNTPSummary *cns = (CamelNNTPSummary *)camel_object_new(camel_nntp_summary_get_type());
+	CamelNNTPSummary *cns;
 
+	cns = g_object_new (CAMEL_TYPE_NNTP_SUMMARY, NULL);
 	((CamelFolderSummary *)cns)->folder = folder;
 
-	camel_folder_summary_set_filename((CamelFolderSummary *)cns, path);
-	camel_folder_summary_set_build_content((CamelFolderSummary *)cns, FALSE);
+	camel_folder_summary_set_filename ((CamelFolderSummary *)cns, path);
+	camel_folder_summary_set_build_content ((CamelFolderSummary *)cns, FALSE);
 
 	return cns;
 }
 
 static CamelMessageInfo *
-message_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
+message_info_new_from_header (CamelFolderSummary *s, struct _camel_header_raw *h)
 {
 	CamelMessageInfoBase *mi;
 	CamelNNTPSummary *cns = (CamelNNTPSummary *)s;
@@ -155,11 +139,11 @@ message_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
 	if (cns->priv->uid == NULL)
 		return NULL;
 
-	mi = (CamelMessageInfoBase *)((CamelFolderSummaryClass *)camel_nntp_summary_parent)->message_info_new_from_header(s, h);
+	mi = (CamelMessageInfoBase *)CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_new_from_header (s, h);
 	if (mi) {
-		camel_pstring_free(mi->uid);
-		mi->uid = camel_pstring_strdup(cns->priv->uid);
-		g_free(cns->priv->uid);
+		camel_pstring_free (mi->uid);
+		mi->uid = camel_pstring_strdup (cns->priv->uid);
+		g_free (cns->priv->uid);
 		cns->priv->uid = NULL;
 	}
 
@@ -169,10 +153,10 @@ message_info_new_from_header(CamelFolderSummary *s, struct _camel_header_raw *h)
 static gint
 summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir)
 {
-	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY(s);
+	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY (s);
 	gchar *part;
 
-	if (camel_nntp_summary_parent->summary_header_from_db (s, mir) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_from_db (s, mir) == -1)
 		return -1;
 
 	part = mir->bdata;
@@ -193,30 +177,30 @@ summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir)
 }
 
 static gint
-summary_header_load(CamelFolderSummary *s, FILE *in)
+summary_header_load (CamelFolderSummary *s, FILE *in)
 {
-	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY(s);
+	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY (s);
 
-	if (((CamelFolderSummaryClass *)camel_nntp_summary_parent)->summary_header_load(s, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (s, in) == -1)
 		return -1;
 
 	/* Legacy version */
 	if (s->version == 0x20c) {
-		camel_file_util_decode_fixed_int32(in, (gint32 *) &cns->high);
-		return camel_file_util_decode_fixed_int32(in, (gint32 *) &cns->low);
+		camel_file_util_decode_fixed_int32 (in, (gint32 *) &cns->high);
+		return camel_file_util_decode_fixed_int32 (in, (gint32 *) &cns->low);
 	}
 
-	if (camel_file_util_decode_fixed_int32(in, (gint32 *) &cns->version) == -1)
+	if (camel_file_util_decode_fixed_int32 (in, (gint32 *) &cns->version) == -1)
 		return -1;
 
 	if (cns->version > CAMEL_NNTP_SUMMARY_VERSION) {
-		g_warning("Unknown NNTP summary version");
+		g_warning ("Unknown NNTP summary version");
 		errno = EINVAL;
 		return -1;
 	}
 
-	if (camel_file_util_decode_fixed_int32(in, (gint32 *) &cns->high) == -1
-	    || camel_file_util_decode_fixed_int32(in, (gint32 *) &cns->low) == -1)
+	if (camel_file_util_decode_fixed_int32 (in, (gint32 *) &cns->high) == -1
+	    || camel_file_util_decode_fixed_int32 (in, (gint32 *) &cns->low) == -1)
 		return -1;
 
 	return 0;
@@ -225,10 +209,10 @@ summary_header_load(CamelFolderSummary *s, FILE *in)
 static CamelFIRecord *
 summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 {
-	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY(s);
+	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY (s);
 	struct _CamelFIRecord *fir;
 
-	fir = camel_nntp_summary_parent->summary_header_to_db (s, ex);
+	fir = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_to_db (s, ex);
 	if (!fir)
 		return NULL;
 	fir->bdata = g_strdup_printf ("%d %d %d", CAMEL_NNTP_SUMMARY_VERSION, cns->high, cns->low);
@@ -237,14 +221,14 @@ summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
 }
 
 static gint
-summary_header_save(CamelFolderSummary *s, FILE *out)
+summary_header_save (CamelFolderSummary *s, FILE *out)
 {
-	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY(s);
+	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY (s);
 
-	if (((CamelFolderSummaryClass *)camel_nntp_summary_parent)->summary_header_save(s, out) == -1
-	    || camel_file_util_encode_fixed_int32(out, CAMEL_NNTP_SUMMARY_VERSION) == -1
-	    || camel_file_util_encode_fixed_int32(out, cns->high) == -1
-	    || camel_file_util_encode_fixed_int32(out, cns->low) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_save (s, out) == -1
+	    || camel_file_util_encode_fixed_int32 (out, CAMEL_NNTP_SUMMARY_VERSION) == -1
+	    || camel_file_util_encode_fixed_int32 (out, cns->high) == -1
+	    || camel_file_util_encode_fixed_int32 (out, cns->low) == -1)
 		return -1;
 
 	return 0;
@@ -254,7 +238,7 @@ summary_header_save(CamelFolderSummary *s, FILE *out)
 
 /* Note: This will be called from camel_nntp_command, so only use camel_nntp_raw_command */
 static gint
-add_range_xover(CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint low, CamelFolderChangeInfo *changes, CamelException *ex)
+add_range_xover (CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint low, CamelFolderChangeInfo *changes, CamelException *ex)
 {
 	CamelFolderSummary *s;
 	CamelMessageInfoBase *mi;
@@ -267,25 +251,25 @@ add_range_xover(CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint
 	GHashTable *summary_table;
 
 	s = (CamelFolderSummary *)cns;
-	summary_table = camel_folder_summary_get_hashtable(s);
+	summary_table = camel_folder_summary_get_hashtable (s);
 
-	camel_operation_start(NULL, _("%s: Scanning new messages"), ((CamelService *)store)->url->host);
+	camel_operation_start (NULL, _("%s: Scanning new messages"), ((CamelService *)store)->url->host);
 
-	ret = camel_nntp_raw_command_auth(store, ex, &line, "xover %r", low, high);
+	ret = camel_nntp_raw_command_auth (store, ex, &line, "xover %r", low, high);
 	if (ret != 224) {
-		camel_operation_end(NULL);
+		camel_operation_end (NULL);
 		if (ret != -1)
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 					     _("Unexpected server response from xover: %s"), line);
 		return -1;
 	}
 
 	count = 0;
 	total = high-low+1;
-	while ((ret = camel_nntp_stream_line(store->stream, (guchar **)&line, &len)) > 0) {
-		camel_operation_progress(NULL, (count * 100) / total);
+	while ((ret = camel_nntp_stream_line (store->stream, (guchar **)&line, &len)) > 0) {
+		camel_operation_progress (NULL, (count * 100) / total);
 		count++;
-		n = strtoul(line, &tab, 10);
+		n = strtoul (line, &tab, 10);
 		if (*tab != '\t')
 			continue;
 		tab++;
@@ -293,25 +277,25 @@ add_range_xover(CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint
 		size = 0;
 		for (;tab[0] && xover;xover = xover->next) {
 			line = tab;
-			tab = strchr(line, '\t');
+			tab = strchr (line, '\t');
 			if (tab)
 				*tab++ = 0;
 			else
-				tab = line+strlen(line);
+				tab = line+strlen (line);
 
 			/* do we care about this column? */
 			if (xover->name) {
 				line += xover->skip;
 				if (line < tab) {
-					camel_header_raw_append(&headers, xover->name, line, -1);
+					camel_header_raw_append (&headers, xover->name, line, -1);
 					switch (xover->type) {
 					case XOVER_STRING:
 						break;
 					case XOVER_MSGID:
-						cns->priv->uid = g_strdup_printf("%u,%s", n, line);
+						cns->priv->uid = g_strdup_printf ("%u,%s", n, line);
 						break;
 					case XOVER_SIZE:
-						size = strtoul(line, NULL, 10);
+						size = strtoul (line, NULL, 10);
 						break;
 					}
 				}
@@ -324,34 +308,34 @@ add_range_xover(CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint
 
 		/* truncated line? ignore? */
 		if (xover == NULL) {
-			if (!GPOINTER_TO_INT(g_hash_table_lookup (summary_table, cns->priv->uid))) {
-				mi = (CamelMessageInfoBase *)camel_folder_summary_add_from_header(s, headers);
+			if (!GPOINTER_TO_INT (g_hash_table_lookup (summary_table, cns->priv->uid))) {
+				mi = (CamelMessageInfoBase *)camel_folder_summary_add_from_header (s, headers);
 				if (mi) {
 					mi->size = size;
 					cns->high = n;
-					camel_folder_change_info_add_uid(changes, camel_message_info_uid(mi));
+					camel_folder_change_info_add_uid (changes, camel_message_info_uid (mi));
 				}
 			}
 		}
 
 		if (cns->priv->uid) {
-			g_free(cns->priv->uid);
+			g_free (cns->priv->uid);
 			cns->priv->uid = NULL;
 		}
 
-		camel_header_raw_clear(&headers);
+		camel_header_raw_clear (&headers);
 	}
 
-	camel_operation_end(NULL);
+	camel_operation_end (NULL);
 
-	camel_folder_summary_free_hashtable(summary_table);
+	camel_folder_summary_free_hashtable (summary_table);
 
 	return ret;
 }
 
 /* Note: This will be called from camel_nntp_command, so only use camel_nntp_raw_command */
 static gint
-add_range_head(CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint low, CamelFolderChangeInfo *changes, CamelException *ex)
+add_range_head (CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint low, CamelFolderChangeInfo *changes, CamelException *ex)
 {
 	CamelFolderSummary *s;
 	gint ret = -1;
@@ -363,50 +347,50 @@ add_range_head(CamelNNTPSummary *cns, CamelNNTPStore *store, guint high, guint l
 
 	s = (CamelFolderSummary *)cns;
 
-	summary_table = camel_folder_summary_get_hashtable(s);
+	summary_table = camel_folder_summary_get_hashtable (s);
 
-	mp = camel_mime_parser_new();
+	mp = camel_mime_parser_new ();
 
-	camel_operation_start(NULL, _("%s: Scanning new messages"), ((CamelService *)store)->url->host);
+	camel_operation_start (NULL, _("%s: Scanning new messages"), ((CamelService *)store)->url->host);
 
 	count = 0;
 	total = high-low+1;
 	for (i=low;i<high+1;i++) {
-		camel_operation_progress(NULL, (count * 100) / total);
+		camel_operation_progress (NULL, (count * 100) / total);
 		count++;
-		ret = camel_nntp_raw_command_auth(store, ex, &line, "head %u", i);
+		ret = camel_nntp_raw_command_auth (store, ex, &line, "head %u", i);
 		/* unknown article, ignore */
 		if (ret == 423)
 			continue;
 		else if (ret == -1)
 			goto ioerror;
 		else if (ret != 221) {
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Unexpected server response from head: %s"), line);
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Unexpected server response from head: %s"), line);
 			goto ioerror;
 		}
 		line += 3;
-		n = strtoul(line, &line, 10);
+		n = strtoul (line, &line, 10);
 		if (n != i)
-			g_warning("retrieved message '%u' when i expected '%u'?\n", n, i);
+			g_warning ("retrieved message '%u' when i expected '%u'?\n", n, i);
 
 		/* FIXME: use camel-mime-utils.c function for parsing msgid? */
-		if ((msgid = strchr(line, '<')) && (line = strchr(msgid+1, '>'))) {
+		if ((msgid = strchr (line, '<')) && (line = strchr (msgid+1, '>'))) {
 			line[1] = 0;
-			cns->priv->uid = g_strdup_printf("%u,%s\n", n, msgid);
-			if (!GPOINTER_TO_INT(g_hash_table_lookup (summary_table, cns->priv->uid))) {
-				if (camel_mime_parser_init_with_stream(mp, (CamelStream *)store->stream) == -1)
+			cns->priv->uid = g_strdup_printf ("%u,%s\n", n, msgid);
+			if (!GPOINTER_TO_INT (g_hash_table_lookup (summary_table, cns->priv->uid))) {
+				if (camel_mime_parser_init_with_stream (mp, (CamelStream *)store->stream) == -1)
 					goto error;
-				mi = camel_folder_summary_add_from_parser(s, mp);
-				while (camel_mime_parser_step(mp, NULL, NULL) != CAMEL_MIME_PARSER_STATE_EOF)
+				mi = camel_folder_summary_add_from_parser (s, mp);
+				while (camel_mime_parser_step (mp, NULL, NULL) != CAMEL_MIME_PARSER_STATE_EOF)
 					;
 				if (mi == NULL) {
 					goto error;
 				}
 				cns->high = i;
-				camel_folder_change_info_add_uid(changes, camel_message_info_uid(mi));
+				camel_folder_change_info_add_uid (changes, camel_message_info_uid (mi));
 			}
 			if (cns->priv->uid) {
-				g_free(cns->priv->uid);
+				g_free (cns->priv->uid);
 				cns->priv->uid = NULL;
 			}
 		}
@@ -417,21 +401,21 @@ error:
 
 	if (ret == -1) {
 		if (errno == EINTR)
-			camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Use cancel"));
+			camel_exception_setv (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Use cancel"));
 		else
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Operation failed: %s"), g_strerror(errno));
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Operation failed: %s"), g_strerror (errno));
 	}
 ioerror:
 
 	if (cns->priv->uid) {
-		g_free(cns->priv->uid);
+		g_free (cns->priv->uid);
 		cns->priv->uid = NULL;
 	}
-	camel_object_unref((CamelObject *)mp);
+	g_object_unref (mp);
 
-	camel_operation_end(NULL);
+	camel_operation_end (NULL);
 
-	camel_folder_summary_free_hashtable(summary_table);
+	camel_folder_summary_free_hashtable (summary_table);
 
 	return ret;
 }
@@ -439,7 +423,7 @@ ioerror:
 /* Assumes we have the stream */
 /* Note: This will be called from camel_nntp_command, so only use camel_nntp_raw_command */
 gint
-camel_nntp_summary_check(CamelNNTPSummary *cns, CamelNNTPStore *store, gchar *line, CamelFolderChangeInfo *changes, CamelException *ex)
+camel_nntp_summary_check (CamelNNTPSummary *cns, CamelNNTPStore *store, gchar *line, CamelFolderChangeInfo *changes, CamelException *ex)
 {
 	CamelFolderSummary *s;
 	gint ret = 0, i;
@@ -452,22 +436,22 @@ camel_nntp_summary_check(CamelNNTPSummary *cns, CamelNNTPStore *store, gchar *li
 	s = (CamelFolderSummary *)cns;
 
 	line +=3;
-	f = strtoul(line, &line, 10);
-	l = strtoul(line, &line, 10);
+	f = strtoul (line, &line, 10);
+	l = strtoul (line, &line, 10);
 	if (line[0] == ' ') {
 		gchar *tmp;
 
 		folder = line+1;
-		tmp = strchr(folder, ' ');
+		tmp = strchr (folder, ' ');
 		if (tmp)
 			*tmp = 0;
-		tmp = g_alloca(strlen(folder)+1);
-		strcpy(tmp, folder);
+		tmp = g_alloca (strlen (folder)+1);
+		strcpy (tmp, folder);
 		folder = tmp;
 	}
 
 	if (cns->low == f && cns->high == l) {
-		dd(printf("nntp_summary: no work to do!\n"));
+		dd (printf ("nntp_summary: no work to do!\n"));
 		goto update;
 	}
 
@@ -475,23 +459,23 @@ camel_nntp_summary_check(CamelNNTPSummary *cns, CamelNNTPStore *store, gchar *li
 
 	/* Check for messages no longer on the server */
 	if (cns->low != f) {
-		count = camel_folder_summary_count(s);
+		count = camel_folder_summary_count (s);
 		for (i = 0; i < count; i++) {
 			gchar *uid;
 			const gchar *msgid;
 
-			uid  = camel_folder_summary_uid_from_index(s, i);
-			n = strtoul(uid, NULL, 10);
+			uid  = camel_folder_summary_uid_from_index (s, i);
+			n = strtoul (uid, NULL, 10);
 
 			if (n < f || n > l) {
-				dd(printf("nntp_summary: %u is lower/higher than lowest/highest article, removed\n", n));
+				dd (printf ("nntp_summary: %u is lower/higher than lowest/highest article, removed\n", n));
 				/* Since we use a global cache this could prematurely remove
 				   a cached message that might be in another folder - not that important as
 				   it is a true cache */
-				msgid = strchr(uid, ',');
+				msgid = strchr (uid, ',');
 				if (msgid)
-					camel_data_cache_remove(store->cache, "cache", msgid+1, NULL);
-				camel_folder_change_info_remove_uid(changes, uid);
+					camel_data_cache_remove (store->cache, "cache", msgid+1, NULL);
+				camel_folder_change_info_remove_uid (changes, uid);
 				del = g_slist_prepend (del, uid);
 				camel_folder_summary_remove_uid_fast (s, uid);
 				uid = NULL; /*Lets not free it */
@@ -512,20 +496,20 @@ camel_nntp_summary_check(CamelNNTPSummary *cns, CamelNNTPStore *store, gchar *li
 			cns->high = f-1;
 
 		if (store->xover) {
-			ret = add_range_xover(cns, store, l, cns->high+1, changes, ex);
+			ret = add_range_xover (cns, store, l, cns->high+1, changes, ex);
 		} else {
-			ret = add_range_head(cns, store, l, cns->high+1, changes, ex);
+			ret = add_range_head (cns, store, l, cns->high+1, changes, ex);
 		}
 	}
 
 	/* TODO: not from here */
-	camel_folder_summary_touch(s);
+	camel_folder_summary_touch (s);
 	camel_folder_summary_save_to_db (s, ex);
 
 update:
 	/* update store summary if we have it */
 	if (folder
-	    && (si = (CamelNNTPStoreInfo *)camel_store_summary_path((CamelStoreSummary *)store->summary, folder))) {
+	    && (si = (CamelNNTPStoreInfo *)camel_store_summary_path ((CamelStoreSummary *)store->summary, folder))) {
 		guint32 unread = 0;
 
 		count = camel_folder_summary_count (s);
@@ -539,15 +523,15 @@ update:
 			si->info.total = count;
 			si->first = f;
 			si->last = l;
-			camel_store_summary_touch((CamelStoreSummary *)store->summary);
-			camel_store_summary_save((CamelStoreSummary *)store->summary);
+			camel_store_summary_touch ((CamelStoreSummary *)store->summary);
+			camel_store_summary_save ((CamelStoreSummary *)store->summary);
 		}
 		camel_store_summary_info_free ((CamelStoreSummary *)store->summary, (CamelStoreInfo *)si);
 	} else {
 		if (folder)
-			g_warning("Group '%s' not present in summary", folder);
+			g_warning ("Group '%s' not present in summary", folder);
 		else
-			g_warning("Missing group from group response");
+			g_warning ("Missing group from group response");
 	}
 
 	return ret;
diff --git a/camel/providers/nntp/camel-nntp-summary.h b/camel/providers/nntp/camel-nntp-summary.h
index 3a112d2..59ef66b 100644
--- a/camel/providers/nntp/camel-nntp-summary.h
+++ b/camel/providers/nntp/camel-nntp-summary.h
@@ -18,14 +18,29 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_NNTP_SUMMARY_H
-#define _CAMEL_NNTP_SUMMARY_H
+#ifndef CAMEL_NNTP_SUMMARY_H
+#define CAMEL_NNTP_SUMMARY_H
 
-#include <camel/camel-folder-summary.h>
+#include <camel/camel.h>
 
-#define CAMEL_NNTP_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_nntp_summary_get_type (), CamelNNTPSummary)
-#define CAMEL_NNTP_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_nntp_summary_get_type (), CamelNNTPSummaryClass)
-#define CAMEL_IS_LOCAL_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_nntp_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_NNTP_SUMMARY \
+	(camel_nntp_summary_get_type ())
+#define CAMEL_NNTP_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_NNTP_SUMMARY, CamelNNTPSummary))
+#define CAMEL_NNTP_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_NNTP_SUMMARY, CamelNNTPSummaryClass))
+#define CAMEL_IS_NNTP_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_NNTP_SUMMARY))
+#define CAMEL_IS_NNTP_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_NNTP_SUMMARY))
+#define CAMEL_NNTP_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_NNTP_SUMMARY, CamelNNTPSummaryClass))
 
 G_BEGIN_DECLS
 
@@ -33,13 +48,14 @@ struct _CamelNNTPStore;
 struct _CamelFolderChangeInfo;
 struct _CamelException;
 
-typedef struct _CamelNNTPSummary      CamelNNTPSummary;
+typedef struct _CamelNNTPSummary CamelNNTPSummary;
 typedef struct _CamelNNTPSummaryClass CamelNNTPSummaryClass;
+typedef struct _CamelNNTPSummaryPrivate CamelNNTPSummaryPrivate;
 
 struct _CamelNNTPSummary {
 	CamelFolderSummary parent;
 
-	struct _CamelNNTPSummaryPrivate *priv;
+	CamelNNTPSummaryPrivate *priv;
 
 	guint32 version;
 	guint32 high, low;
@@ -49,12 +65,12 @@ struct _CamelNNTPSummaryClass {
 	CamelFolderSummaryClass parent_class;
 };
 
-CamelType	camel_nntp_summary_get_type	(void);
+GType	camel_nntp_summary_get_type	(void);
 CamelNNTPSummary *camel_nntp_summary_new(struct _CamelFolder *folder, const gchar *path);
 
 gint camel_nntp_summary_check(CamelNNTPSummary *cns, struct _CamelNNTPStore *store, gchar *line, struct _CamelFolderChangeInfo *changes, struct _CamelException *ex);
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_NNTP_SUMMARY_H */
+#endif /* CAMEL_NNTP_SUMMARY_H */
 
diff --git a/camel/providers/nntp/camel-nntp-types.h b/camel/providers/nntp/camel-nntp-types.h
index c7b3352..b31eb0d 100644
--- a/camel/providers/nntp/camel-nntp-types.h
+++ b/camel/providers/nntp/camel-nntp-types.h
@@ -22,7 +22,7 @@
  */
 
 #ifndef CAMEL_NNTP_TYPES_H
-#define CAMEL_NNTP_TYPES_H 1
+#define CAMEL_NNTP_TYPES_H
 
 G_BEGIN_DECLS
 
diff --git a/camel/providers/nntp/camel-nntp-utils.c b/camel/providers/nntp/camel-nntp-utils.c
index f524c6f..3a307de 100644
--- a/camel/providers/nntp/camel-nntp-utils.c
+++ b/camel/providers/nntp/camel-nntp-utils.c
@@ -24,10 +24,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "camel-folder-summary.h"
-#include "camel-stream-mem.h"
-#include "camel-exception.h"
-
 #include "camel-nntp-resp-codes.h"
 #include "camel-nntp-folder.h"
 #include "camel-nntp-store.h"
diff --git a/camel/providers/nntp/camel-nntp-utils.h b/camel/providers/nntp/camel-nntp-utils.h
index fca72dd..986b3a5 100644
--- a/camel/providers/nntp/camel-nntp-utils.h
+++ b/camel/providers/nntp/camel-nntp-utils.h
@@ -23,7 +23,7 @@
  */
 
 #ifndef CAMEL_NNTP_UTILS_H
-#define CAMEL_NNTP_UTILS_H 1
+#define CAMEL_NNTP_UTILS_H
 
 G_BEGIN_DECLS
 
diff --git a/camel/providers/pop3/camel-pop3-engine.c b/camel/providers/pop3/camel-pop3-engine.c
index 0bc1736..993343a 100644
--- a/camel/providers/pop3/camel-pop3-engine.c
+++ b/camel/providers/pop3/camel-pop3-engine.c
@@ -28,13 +28,10 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-pop3-engine.h"
 #include "camel-pop3-stream.h"
-#include "camel-sasl.h"
-#include "camel-service.h"
 
 /* max 'outstanding' bytes in output stream, so we can't deadlock waiting
    for the server to accept our data when pipelining */
@@ -43,61 +40,77 @@
 extern CamelServiceAuthType camel_pop3_password_authtype;
 extern CamelServiceAuthType camel_pop3_apop_authtype;
 
-extern gint camel_verbose_debug;
 #define dd(x) (camel_verbose_debug?(x):0)
 
 static void get_capabilities(CamelPOP3Engine *pe);
 
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_POP3_ENGINE_CLASS(CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 static void
-camel_pop3_engine_class_init (CamelPOP3EngineClass *camel_pop3_engine_class)
+pop3_engine_dispose (GObject *object)
 {
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	CamelPOP3Engine *engine = CAMEL_POP3_ENGINE (object);
+
+	if (engine->stream != NULL) {
+		g_object_unref (engine->stream);
+		engine->stream = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-camel_pop3_engine_init(CamelPOP3Engine *pe, CamelPOP3EngineClass *peclass)
+pop3_engine_finalize (GObject *object)
 {
-	camel_dlist_init(&pe->active);
-	camel_dlist_init(&pe->queue);
-	camel_dlist_init(&pe->done);
-	pe->state = CAMEL_POP3_ENGINE_DISCONNECT;
+	CamelPOP3Engine *engine = CAMEL_POP3_ENGINE (object);
+
+	/* FIXME: Also flush/free any outstanding requests, etc */
+
+	g_list_free (engine->auth);
+	g_free (engine->apop);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_pop3_engine_finalise(CamelPOP3Engine *pe)
+camel_pop3_engine_class_init (CamelPOP3EngineClass *class)
 {
-	/* FIXME: Also flush/free any outstanding requests, etc */
+	GObjectClass *object_class;
 
-	if (pe->stream)
-		camel_object_unref(pe->stream);
+	parent_class = g_type_class_peek_parent (class);
 
-	g_list_free(pe->auth);
-	if (pe->apop)
-		g_free(pe->apop);
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = pop3_engine_dispose;
+	object_class->finalize = pop3_engine_finalize;
 }
 
-CamelType
-camel_pop3_engine_get_type (void)
+static void
+camel_pop3_engine_init (CamelPOP3Engine *engine)
 {
-	static CamelType camel_pop3_engine_type = CAMEL_INVALID_TYPE;
-
-	if (camel_pop3_engine_type == CAMEL_INVALID_TYPE) {
-		camel_pop3_engine_type = camel_type_register(camel_object_get_type(),
-							     "CamelPOP3Engine",
-							     sizeof( CamelPOP3Engine ),
-							     sizeof( CamelPOP3EngineClass ),
-							     (CamelObjectClassInitFunc) camel_pop3_engine_class_init,
-							     NULL,
-							     (CamelObjectInitFunc) camel_pop3_engine_init,
-							     (CamelObjectFinalizeFunc) camel_pop3_engine_finalise );
-	}
+	camel_dlist_init (&engine->active);
+	camel_dlist_init (&engine->queue);
+	camel_dlist_init (&engine->done);
+	engine->state = CAMEL_POP3_ENGINE_DISCONNECT;
+}
 
-	return camel_pop3_engine_type;
+GType
+camel_pop3_engine_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_OBJECT,
+			"CamelPOP3Engine",
+			sizeof (CamelPOP3EngineClass),
+			(GClassInitFunc) camel_pop3_engine_class_init,
+			sizeof (CamelPOP3Engine),
+			(GInstanceInitFunc) camel_pop3_engine_init,
+			0);
+
+	return type;
 }
 
 static gint
@@ -139,14 +152,14 @@ camel_pop3_engine_new(CamelStream *source, guint32 flags)
 {
 	CamelPOP3Engine *pe;
 
-	pe = (CamelPOP3Engine *)camel_object_new(camel_pop3_engine_get_type ());
+	pe = g_object_new (CAMEL_TYPE_POP3_ENGINE, NULL);
 
 	pe->stream = (CamelPOP3Stream *)camel_pop3_stream_new(source);
 	pe->state = CAMEL_POP3_ENGINE_AUTH;
 	pe->flags = flags;
 
 	if (read_greeting (pe) == -1) {
-		camel_object_unref (pe);
+		g_object_unref (pe);
 		return NULL;
 	}
 
diff --git a/camel/providers/pop3/camel-pop3-engine.h b/camel/providers/pop3/camel-pop3-engine.h
index 6377b75..89dbaf6 100644
--- a/camel/providers/pop3/camel-pop3-engine.h
+++ b/camel/providers/pop3/camel-pop3-engine.h
@@ -18,21 +18,36 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef _CAMEL_POP3_ENGINE_H
-#define _CAMEL_POP3_ENGINE_H
+#ifndef CAMEL_POP3_ENGINE_H
+#define CAMEL_POP3_ENGINE_H
+
+#include <camel/camel.h>
 
-#include <camel/camel-object.h>
-#include <camel/camel-list-utils.h>
 #include "camel-pop3-stream.h"
 
-#define CAMEL_POP3_ENGINE(obj)         CAMEL_CHECK_CAST (obj, camel_pop3_engine_get_type (), CamelPOP3Engine)
-#define CAMEL_POP3_ENGINE_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_pop3_engine_get_type (), CamelPOP3EngineClass)
-#define CAMEL_IS_POP3_ENGINE(obj)      CAMEL_CHECK_TYPE (obj, camel_pop3_engine_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_POP3_ENGINE \
+	(camel_pop3_engine_get_type ())
+#define CAMEL_POP3_ENGINE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_POP3_ENGINE, CamelPOP3Engine))
+#define CAMEL_POP3_ENGINE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_POP3_ENGINE, CamelPOP3EngineClass))
+#define CAMEL_IS_POP3_ENGINE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_POP3_ENGINE))
+#define CAMEL_IS_POP3_ENGINE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_POP3_ENGINE))
+#define CAMEL_POP3_ENGINE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_POP3_ENGINE, CamelPOP3EngineClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelPOP3EngineClass CamelPOP3EngineClass;
 typedef struct _CamelPOP3Engine CamelPOP3Engine;
+typedef struct _CamelPOP3EngineClass CamelPOP3EngineClass;
 typedef struct _CamelPOP3Command CamelPOP3Command;
 
 /* pop 3 connection states, actually since we're given a connected socket, we always start in auth state */
@@ -121,7 +136,7 @@ struct _CamelPOP3EngineClass {
 	CamelObjectClass parent_class;
 };
 
-CamelType		  camel_pop3_engine_get_type	(void);
+GType		  camel_pop3_engine_get_type	(void);
 
 CamelPOP3Engine  *camel_pop3_engine_new		(CamelStream *source, guint32 flags);
 
@@ -135,4 +150,4 @@ CamelPOP3Command *camel_pop3_engine_command_new	(CamelPOP3Engine *pe, guint32 fl
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_POP3_ENGINE_H */
+#endif /* CAMEL_POP3_ENGINE_H */
diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c
index 94d0722..77aa9c1 100644
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ b/camel/providers/pop3/camel-pop3-folder.c
@@ -33,21 +33,13 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-data-cache.h"
-#include "camel-exception.h"
-#include "camel-mime-message.h"
-#include "camel-operation.h"
 #include "camel-pop3-folder.h"
 #include "camel-pop3-store.h"
-#include "camel-stream-filter.h"
-#include "camel-stream-mem.h"
 
 #define d(x)
 
-#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(o)))
-static CamelFolderClass *parent_class;
+static gpointer parent_class;
 
-static void pop3_finalize (CamelObject *object);
 static void pop3_refresh_info (CamelFolder *folder, CamelException *ex);
 static void pop3_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
 static gint pop3_get_message_count (CamelFolder *folder);
@@ -57,45 +49,7 @@ static gboolean pop3_set_message_flags (CamelFolder *folder, const gchar *uid, g
 static gchar * pop3_get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex);
 
 static void
-camel_pop3_folder_class_init (CamelPOP3FolderClass *camel_pop3_folder_class)
-{
-	CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS(camel_pop3_folder_class);
-
-	parent_class = CAMEL_FOLDER_CLASS(camel_folder_get_type());
-
-	/* virtual method overload */
-	camel_folder_class->refresh_info = pop3_refresh_info;
-	camel_folder_class->sync = pop3_sync;
-
-	camel_folder_class->get_message_count = pop3_get_message_count;
-	camel_folder_class->get_uids = pop3_get_uids;
-	camel_folder_class->free_uids = camel_folder_free_shallow;
-	camel_folder_class->get_filename = pop3_get_filename;
-
-	camel_folder_class->get_message = pop3_get_message;
-	camel_folder_class->set_message_flags = pop3_set_message_flags;
-}
-
-CamelType
-camel_pop3_folder_get_type (void)
-{
-	static CamelType camel_pop3_folder_type = CAMEL_INVALID_TYPE;
-
-	if (!camel_pop3_folder_type) {
-		camel_pop3_folder_type = camel_type_register (CAMEL_FOLDER_TYPE, "CamelPOP3Folder",
-							      sizeof (CamelPOP3Folder),
-							      sizeof (CamelPOP3FolderClass),
-							      (CamelObjectClassInitFunc) camel_pop3_folder_class_init,
-							      NULL,
-							      NULL,
-							      (CamelObjectFinalizeFunc) pop3_finalize);
-	}
-
-	return camel_pop3_folder_type;
-}
-
-static void
-pop3_finalize (CamelObject *object)
+pop3_folder_finalize (GObject *object)
 {
 	CamelPOP3Folder *pop3_folder = CAMEL_POP3_FOLDER (object);
 	CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)pop3_folder->uids->pdata;
@@ -117,6 +71,49 @@ pop3_finalize (CamelObject *object)
 		g_ptr_array_free(pop3_folder->uids, TRUE);
 		g_hash_table_destroy(pop3_folder->uids_uid);
 	}
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+camel_pop3_folder_class_init (CamelPOP3FolderClass *class)
+{
+	GObjectClass *object_class;
+	CamelFolderClass *folder_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = pop3_folder_finalize;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->refresh_info = pop3_refresh_info;
+	folder_class->sync = pop3_sync;
+	folder_class->get_message_count = pop3_get_message_count;
+	folder_class->get_uids = pop3_get_uids;
+	folder_class->free_uids = camel_folder_free_shallow;
+	folder_class->get_filename = pop3_get_filename;
+	folder_class->get_message = pop3_get_message;
+	folder_class->set_message_flags = pop3_set_message_flags;
+}
+
+GType
+camel_pop3_folder_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_FOLDER,
+			"CamelPOP3Folder",
+			sizeof (CamelPOP3FolderClass),
+			(GClassInitFunc) camel_pop3_folder_class_init,
+			sizeof (CamelPOP3Folder),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 CamelFolder *
@@ -126,13 +123,13 @@ camel_pop3_folder_new (CamelStore *parent, CamelException *ex)
 
 	d(printf("opening pop3 INBOX folder\n"));
 
-	folder = CAMEL_FOLDER (camel_object_new (CAMEL_POP3_FOLDER_TYPE));
+	folder = g_object_new (CAMEL_TYPE_POP3_FOLDER, NULL);
 	camel_folder_construct (folder, parent, "inbox", "inbox");
 
 	/* mt-ok, since we dont have the folder-lock for new() */
 	camel_folder_refresh_info (folder, ex);/* mt-ok */
 	if (camel_exception_is_set (ex)) {
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 		folder = NULL;
 	}
 
@@ -176,7 +173,7 @@ cmd_builduid(CamelPOP3Engine *pe, CamelPOP3Stream *stream, gpointer data)
 	default:
 		break;
 	}
-	camel_object_unref(mp);
+	g_object_unref (mp);
 	g_checksum_get_digest (checksum, digest, &length);
 	g_checksum_free (checksum);
 
@@ -386,7 +383,7 @@ pop3_get_message_time_from_cache (CamelFolder *folder, const gchar *uid, time_t
 		message = camel_mime_message_new ();
 		if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)message, stream) == -1) {
 			g_warning (_("Cannot get message %s: %s"), uid, g_strerror (errno));
-			camel_object_unref ((CamelObject *)message);
+			g_object_unref (message);
 			message = NULL;
 		}
 
@@ -394,12 +391,12 @@ pop3_get_message_time_from_cache (CamelFolder *folder, const gchar *uid, time_t
 			res = TRUE;
 			*message_time = message->date + message->date_offset;
 
-			camel_object_unref ((CamelObject *)message);
+			g_object_unref (message);
 		}
 	}
 
 	if (stream) {
-		camel_object_unref (stream);
+		g_object_unref (stream);
 	}
 	return res;
 }
@@ -513,7 +510,7 @@ done:
 		fi->err = 0;
 	}
 
-	camel_object_unref((CamelObject *)fi->stream);
+	g_object_unref (fi->stream);
 	fi->stream = NULL;
 }
 
@@ -596,7 +593,7 @@ pop3_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 			stream = camel_stream_mem_new();
 
 		/* ref it, the cache storage routine unref's when done */
-		camel_object_ref((CamelObject *)stream);
+		g_object_ref (stream);
 		fi->stream = stream;
 		fi->err = EIO;
 		pcr = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_tocache, fi, "RETR %u\r\n", fi->id);
@@ -659,11 +656,11 @@ pop3_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				_("Cannot get message %s: %s"),
 				uid, g_strerror (errno));
-		camel_object_unref((CamelObject *)message);
+		g_object_unref (message);
 		message = NULL;
 	}
 done:
-	camel_object_unref((CamelObject *)stream);
+	g_object_unref (stream);
 fail:
 	camel_operation_end(NULL);
 
diff --git a/camel/providers/pop3/camel-pop3-folder.h b/camel/providers/pop3/camel-pop3-folder.h
index 16fde5c..e40fe76 100644
--- a/camel/providers/pop3/camel-pop3-folder.h
+++ b/camel/providers/pop3/camel-pop3-folder.h
@@ -24,18 +24,36 @@
  */
 
 #ifndef CAMEL_POP3_FOLDER_H
-#define CAMEL_POP3_FOLDER_H 1
-
-#include "camel-folder.h"
-
-#define CAMEL_POP3_FOLDER_TYPE     (camel_pop3_folder_get_type ())
-#define CAMEL_POP3_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_POP3_FOLDER_TYPE, CamelPOP3Folder))
-#define CAMEL_POP3_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_POP3_FOLDER_TYPE, CamelPOP3FolderClass))
-#define CAMEL_IS_POP3_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_POP3_FOLDER_TYPE))
+#define CAMEL_POP3_FOLDER_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_POP3_FOLDER \
+	(camel_pop3_folder_get_type ())
+#define CAMEL_POP3_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_POP3_FOLDER, CamelPOP3Folder))
+#define CAMEL_POP3_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_POP3_FOLDER, CamelPOP3FolderClass))
+#define CAMEL_IS_POP3_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_POP3_FOLDER))
+#define CAMEL_IS_POP3_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_POP3_FOLDER))
+#define CAMEL_POP3_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_POP3_FOLDER, CamelPOP3FolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
+typedef struct _CamelPOP3Folder CamelPOP3Folder;
+typedef struct _CamelPOP3FolderClass CamelPOP3FolderClass;
+typedef struct _CamelPOP3FolderInfo CamelPOP3FolderInfo;
+
+struct _CamelPOP3FolderInfo {
 	guint32 id;
 	guint32 size;
 	guint32 flags;
@@ -44,28 +62,24 @@ typedef struct {
 	gint err;
 	struct _CamelPOP3Command *cmd;
 	struct _CamelStream *stream;
-} CamelPOP3FolderInfo;
+};
 
-typedef struct {
-	CamelFolder parent_object;
+struct _CamelPOP3Folder {
+	CamelFolder parent;
 
 	GPtrArray *uids;
 	GHashTable *uids_uid;	/* messageinfo by uid */
 	GHashTable *uids_id;	/* messageinfo by id */
-} CamelPOP3Folder;
+};
 
-typedef struct {
+struct _CamelPOP3FolderClass {
 	CamelFolderClass parent_class;
-
-	/* Virtual methods */
-
-} CamelPOP3FolderClass;
+};
 
 /* public methods */
 CamelFolder *camel_pop3_folder_new (CamelStore *parent, CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_pop3_folder_get_type (void);
+GType camel_pop3_folder_get_type (void);
 
 gint camel_pop3_delete_old(CamelFolder *folder, gint days_to_delete, CamelException *ex);
 
diff --git a/camel/providers/pop3/camel-pop3-provider.c b/camel/providers/pop3/camel-pop3-provider.c
index 379ae52..8a37f72 100644
--- a/camel/providers/pop3/camel-pop3-provider.c
+++ b/camel/providers/pop3/camel-pop3-provider.c
@@ -30,10 +30,6 @@
 #include <glib/gi18n-lib.h>
 
 #include "camel-pop3-store.h"
-#include "camel-provider.h"
-#include "camel-sasl.h"
-#include "camel-session.h"
-#include "camel-url.h"
 
 static guint pop3_url_hash (gconstpointer key);
 static gint pop3_url_equal (gconstpointer a, gconstpointer b);
@@ -96,7 +92,7 @@ camel_provider_module_init(void)
 {
 	CamelServiceAuthType *auth;
 
-	pop3_provider.object_types[CAMEL_PROVIDER_STORE] = camel_pop3_store_get_type();
+	pop3_provider.object_types[CAMEL_PROVIDER_STORE] = camel_pop3_store_get_type ();
 	pop3_provider.url_hash = pop3_url_hash;
 	pop3_provider.url_equal = pop3_url_equal;
 
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index 89be794..2dcd356 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -37,32 +37,14 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-data-cache.h"
-#include "camel-exception.h"
-#include "camel-net-utils.h"
-#include "camel-operation.h"
-#include "camel-pop3-engine.h"
 #include "camel-pop3-folder.h"
 #include "camel-pop3-store.h"
-#include "camel-sasl.h"
-#include "camel-session.h"
-#include "camel-stream-buffer.h"
-#include "camel-tcp-stream-raw.h"
-#include "camel-tcp-stream.h"
-#include "camel-url.h"
-#include "camel-utf8.h"
-
-#ifdef HAVE_SSL
-#include "camel-tcp-stream-ssl.h"
-#endif
 
 /* Specified in RFC 1939 */
 #define POP3_PORT "110"
 #define POP3S_PORT "995"
 
-static CamelStoreClass *parent_class = NULL;
-
-static void finalize (CamelObject *object);
+static gpointer parent_class;
 
 static gboolean pop3_connect (CamelService *service, CamelException *ex);
 static gboolean pop3_disconnect (CamelService *service, gboolean clean, CamelException *ex);
@@ -76,64 +58,63 @@ static CamelFolder *get_trash  (CamelStore *store, CamelException *ex);
 static gboolean pop3_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex);
 
 static void
-camel_pop3_store_class_init (CamelPOP3StoreClass *camel_pop3_store_class)
+pop3_store_finalize (GObject *object)
 {
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_pop3_store_class);
-	CamelStoreClass *camel_store_class =
-		CAMEL_STORE_CLASS (camel_pop3_store_class);
+	CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (object);
 
-	parent_class = CAMEL_STORE_CLASS (camel_type_get_global_classfuncs (camel_store_get_type ()));
+	/* force disconnect so we dont have it run later, after we've cleaned up some stuff */
+	/* SIGH */
 
-	/* virtual method overload */
-	camel_service_class->query_auth_types = query_auth_types;
-	camel_service_class->connect = pop3_connect;
-	camel_service_class->disconnect = pop3_disconnect;
+	camel_service_disconnect((CamelService *)pop3_store, TRUE, NULL);
 
-	camel_store_class->get_folder = get_folder;
-	camel_store_class->get_trash = get_trash;
-	camel_store_class->can_refresh_folder = pop3_can_refresh_folder;
+	if (pop3_store->engine)
+		g_object_unref (pop3_store->engine);
+	if (pop3_store->cache)
+		g_object_unref (pop3_store->cache);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
-camel_pop3_store_init (gpointer object, gpointer klass)
+pop3_store_class_init (CamelPOP3StoreClass *class)
 {
-	;
-}
+	GObjectClass *object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
 
-CamelType
-camel_pop3_store_get_type (void)
-{
-	static CamelType camel_pop3_store_type = CAMEL_INVALID_TYPE;
-
-	if (!camel_pop3_store_type) {
-		camel_pop3_store_type = camel_type_register (CAMEL_STORE_TYPE,
-							     "CamelPOP3Store",
-							     sizeof (CamelPOP3Store),
-							     sizeof (CamelPOP3StoreClass),
-							     (CamelObjectClassInitFunc) camel_pop3_store_class_init,
-							     NULL,
-							     (CamelObjectInitFunc) camel_pop3_store_init,
-							     finalize);
-	}
+	parent_class = g_type_class_peek_parent (class);
 
-	return camel_pop3_store_type;
-}
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = pop3_store_finalize;
 
-static void
-finalize (CamelObject *object)
-{
-	CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (object);
-
-	/* force disconnect so we dont have it run later, after we've cleaned up some stuff */
-	/* SIGH */
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->query_auth_types = query_auth_types;
+	service_class->connect = pop3_connect;
+	service_class->disconnect = pop3_disconnect;
 
-	camel_service_disconnect((CamelService *)pop3_store, TRUE, NULL);
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_folder = get_folder;
+	store_class->get_trash = get_trash;
+	store_class->can_refresh_folder = pop3_can_refresh_folder;
+}
 
-	if (pop3_store->engine)
-		camel_object_unref((CamelObject *)pop3_store->engine);
-	if (pop3_store->cache)
-		camel_object_unref((CamelObject *)pop3_store->cache);
+GType
+camel_pop3_store_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STORE,
+			"CamelPOP3Store",
+			sizeof (CamelPOP3StoreClass),
+			(GClassInitFunc) pop3_store_class_init,
+			sizeof (CamelPOP3Store),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 enum {
@@ -185,14 +166,14 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 				service->url->host,
 				g_strerror (errno));
 
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 
 		return FALSE;
 	}
 
 	/* parent class connect initialization */
 	if (CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex) == FALSE) {
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 		return FALSE;
 	}
 
@@ -206,12 +187,12 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 			_("Failed to read a valid greeting from POP server %s"),
 			service->url->host);
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 		return FALSE;
 	}
 
 	if (ssl_mode != MODE_TLS) {
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 		return TRUE;
 	}
 
@@ -256,7 +237,7 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 	goto stls_exception;
 #endif /* HAVE_SSL */
 
-	camel_object_unref (tcp_stream);
+	g_object_unref (tcp_stream);
 
 	/* rfc2595, section 4 states that after a successful STLS
 	   command, the client MUST discard prior CAPA responses */
@@ -273,8 +254,8 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 		camel_pop3_engine_command_free (store->engine, pc);
 	}
 
-	camel_object_unref (CAMEL_OBJECT (store->engine));
-	camel_object_unref (CAMEL_OBJECT (tcp_stream));
+	g_object_unref (CAMEL_OBJECT (store->engine));
+	g_object_unref (CAMEL_OBJECT (tcp_stream));
 	store->engine = NULL;
 
 	return FALSE;
@@ -422,7 +403,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);
@@ -438,7 +419,7 @@ try_sasl(CamelPOP3Store *store, const gchar *mech, CamelException *ex)
 			goto ioerror;
 
 	}
-	camel_object_unref((CamelObject *)sasl);
+	g_object_unref (sasl);
 	return 0;
 
  ioerror:
@@ -450,7 +431,7 @@ try_sasl(CamelPOP3Store *store, const gchar *mech, CamelException *ex)
 				      CAMEL_SERVICE (store)->url->host, g_strerror (errno));
 	}
  done:
-	camel_object_unref((CamelObject *)sasl);
+	g_object_unref (sasl);
 	return -1;
 }
 
@@ -589,7 +570,7 @@ pop3_connect (CamelService *service, CamelException *ex)
 
 		root = camel_session_get_storage_path (session, service, ex);
 		if (root) {
-			store->cache = camel_data_cache_new(root, 0, ex);
+			store->cache = camel_data_cache_new(root, ex);
 			g_free(root);
 			if (store->cache) {
 				/* Default cache expiry - 1 week or not visited in a day */
@@ -655,7 +636,7 @@ pop3_disconnect (CamelService *service, gboolean clean, CamelException *ex)
 	if (!CAMEL_SERVICE_CLASS (parent_class)->disconnect (service, clean, ex))
 		return FALSE;
 
-	camel_object_unref((CamelObject *)store->engine);
+	g_object_unref (store->engine);
 	store->engine = NULL;
 
 	return TRUE;
@@ -669,6 +650,7 @@ get_folder (CamelStore *store, const gchar *folder_name, guint32 flags, CamelExc
 				      _("No such folder '%s'."), folder_name);
 		return NULL;
 	}
+
 	return camel_pop3_folder_new (store, ex);
 }
 
diff --git a/camel/providers/pop3/camel-pop3-store.h b/camel/providers/pop3/camel-pop3-store.h
index 3fa141f..31440d3 100644
--- a/camel/providers/pop3/camel-pop3-store.h
+++ b/camel/providers/pop3/camel-pop3-store.h
@@ -24,33 +24,51 @@
  */
 
 #ifndef CAMEL_POP3_STORE_H
-#define CAMEL_POP3_STORE_H 1
+#define CAMEL_POP3_STORE_H
+
+#include <camel/camel.h>
 
-#include <camel/camel-types.h>
-#include <camel/camel-store.h>
 #include "camel-pop3-engine.h"
 
-#define CAMEL_POP3_STORE_TYPE     (camel_pop3_store_get_type ())
-#define CAMEL_POP3_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_POP3_STORE_TYPE, CamelPOP3Store))
-#define CAMEL_POP3_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_POP3_STORE_TYPE, CamelPOP3StoreClass))
-#define CAMEL_IS_POP3_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_POP3_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_POP3_STORE \
+	(camel_pop3_store_get_type ())
+#define CAMEL_POP3_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_POP3_STORE, CamelPOP3Store))
+#define CAMEL_POP3_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_POP3_STORE, CamelPOP3StoreClass))
+#define CAMEL_IS_POP3_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_POP3_STORE))
+#define CAMEL_IS_POP3_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_POP3_STORE))
+#define CAMEL_POP3_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_POP3_STORE, CamelPOP3StoreClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelStore parent_object;
+typedef struct _CamelPOP3Store CamelPOP3Store;
+typedef struct _CamelPOP3StoreClass CamelPOP3StoreClass;
+
+struct _CamelPOP3Store {
+	CamelStore parent;
 
 	CamelPOP3Engine *engine; /* pop processing engine */
 
-	struct _CamelDataCache *cache;
+	CamelDataCache *cache;
 
 	guint delete_after;
-} CamelPOP3Store;
+};
 
-typedef struct {
+struct _CamelPOP3StoreClass {
 	CamelStoreClass parent_class;
+};
 
-} CamelPOP3StoreClass;
+GType camel_pop3_store_get_type (void);
 
 /* public methods */
 void camel_pop3_store_expunge (CamelPOP3Store *store, CamelException *ex);
@@ -60,9 +78,6 @@ enum { CAMEL_POP3_OK, CAMEL_POP3_ERR, CAMEL_POP3_FAIL };
 gint camel_pop3_command (CamelPOP3Store *store, gchar **ret, CamelException *ex, gchar *fmt, ...);
 gchar *camel_pop3_command_get_additional_data (CamelPOP3Store *store, gint total, CamelException *ex);
 
-/* Standard Camel function */
-CamelType camel_pop3_store_get_type (void);
-
 G_END_DECLS
 
 #endif /* CAMEL_POP3_STORE_H */
diff --git a/camel/providers/pop3/camel-pop3-stream.c b/camel/providers/pop3/camel-pop3-stream.c
index 7357fa5..7413f60 100644
--- a/camel/providers/pop3/camel-pop3-stream.c
+++ b/camel/providers/pop3/camel-pop3-stream.c
@@ -31,38 +31,58 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
-
 #include "camel-pop3-stream.h"
 
-extern gint camel_verbose_debug;
 #define dd(x) (camel_verbose_debug?(x):0)
 
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_POP3_STREAM_CLASS(CAMEL_OBJECT_GET_CLASS(so))
+static gpointer parent_class;
 
 #define CAMEL_POP3_STREAM_SIZE (4096)
 #define CAMEL_POP3_STREAM_LINE (1024) /* maximum line size */
 
+static void
+pop3_stream_dispose (GObject *object)
+{
+	CamelPOP3Stream *stream = CAMEL_POP3_STREAM (object);
+
+	if (stream->source != NULL) {
+		g_object_unref (stream->source);
+		stream->source = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+pop3_stream_finalize (GObject *object)
+{
+	CamelPOP3Stream *stream = CAMEL_POP3_STREAM (object);
+
+	g_free (stream->buf);
+	g_free (stream->linebuf);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
 static gint
-stream_fill(CamelPOP3Stream *is)
+stream_fill (CamelPOP3Stream *is)
 {
 	gint left = 0;
 
 	if (is->source) {
 		left = is->end - is->ptr;
-		memmove(is->buf, is->ptr, left);
+		memmove (is->buf, is->ptr, left);
 		is->end = is->buf + left;
 		is->ptr = is->buf;
-		left = camel_stream_read(is->source, (gchar *) is->end, CAMEL_POP3_STREAM_SIZE - (is->end - is->buf));
+		left = camel_stream_read (is->source, (gchar *) is->end, CAMEL_POP3_STREAM_SIZE - (is->end - is->buf));
 		if (left > 0) {
 			is->end += left;
 			is->end[0] = '\n';
 			return is->end - is->ptr;
 		} else {
-			dd(printf("POP3_STREAM_FILL(ERROR): '%s'\n", g_strerror (errno)));
+			dd (printf ("POP3_STREAM_FILL (ERROR): '%s'\n", g_strerror (errno)));
 			return -1;
 		}
 	}
@@ -71,7 +91,7 @@ stream_fill(CamelPOP3Stream *is)
 }
 
 static gssize
-stream_read(CamelStream *stream, gchar *buffer, gsize n)
+stream_read (CamelStream *stream, gchar *buffer, gsize n)
 {
 	CamelPOP3Stream *is = (CamelPOP3Stream *)stream;
 	gchar *o, *oe;
@@ -94,7 +114,7 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 	case 0:		/* start of line, always read at least 3 chars */
 		while (e - p < 3) {
 			is->ptr = p;
-			if (stream_fill(is) == -1)
+			if (stream_fill (is) == -1)
 				return -1;
 			p = is->ptr;
 			e = is->end;
@@ -104,7 +124,7 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 				is->ptr = p+3;
 				is->mode = CAMEL_POP3_STREAM_EOD;
 				is->state = 0;
-				dd(printf("POP3_STREAM_READ(%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
+				dd (printf ("POP3_STREAM_READ (%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
 				return o-buffer;
 			}
 			p++;
@@ -118,7 +138,7 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 				/* end of input sentinal check */
 				if (p > e) {
 					is->ptr = e;
-					if (stream_fill(is) == -1)
+					if (stream_fill (is) == -1)
 						return -1;
 					p = is->ptr;
 					e = is->end;
@@ -137,40 +157,40 @@ stream_read(CamelStream *stream, gchar *buffer, gsize n)
 	is->ptr = p;
 	is->state = state;
 
-	dd(printf("POP3_STREAM_READ(%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
+	dd (printf ("POP3_STREAM_READ (%d):\n%.*s\n", (gint)(o-buffer), (gint)(o-buffer), buffer));
 
 	return o-buffer;
 }
 
 static gssize
-stream_write(CamelStream *stream, const gchar *buffer, gsize n)
+stream_write (CamelStream *stream, const gchar *buffer, gsize n)
 {
 	CamelPOP3Stream *is = (CamelPOP3Stream *)stream;
 
 	if (strncmp (buffer, "PASS ", 5) != 0)
-		dd(printf("POP3_STREAM_WRITE(%d):\n%.*s\n", (gint)n, (gint)n, buffer));
+		dd (printf ("POP3_STREAM_WRITE (%d):\n%.*s\n", (gint)n, (gint)n, buffer));
 	else
-		dd(printf("POP3_STREAM_WRITE(%d):\nPASS xxxxxxxx\n", (gint)n));
+		dd (printf ("POP3_STREAM_WRITE (%d):\nPASS xxxxxxxx\n", (gint)n));
 
-	return camel_stream_write(is->source, buffer, n);
+	return camel_stream_write (is->source, buffer, n);
 }
 
 static gint
-stream_close(CamelStream *stream)
+stream_close (CamelStream *stream)
 {
 	/* nop? */
 	return 0;
 }
 
 static gint
-stream_flush(CamelStream *stream)
+stream_flush (CamelStream *stream)
 {
 	/* nop? */
 	return 0;
 }
 
 static gboolean
-stream_eos(CamelStream *stream)
+stream_eos (CamelStream *stream)
 {
 	CamelPOP3Stream *is = (CamelPOP3Stream *)stream;
 
@@ -178,34 +198,39 @@ stream_eos(CamelStream *stream)
 }
 
 static gint
-stream_reset(CamelStream *stream)
+stream_reset (CamelStream *stream)
 {
 	/* nop?  reset literal mode? */
 	return 0;
 }
 
 static void
-camel_pop3_stream_class_init (CamelStreamClass *camel_pop3_stream_class)
+pop3_stream_class_init (CamelStreamClass *class)
 {
-	CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_pop3_stream_class;
-
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
-
-	/* virtual method definition */
-	camel_stream_class->read = stream_read;
-	camel_stream_class->write = stream_write;
-	camel_stream_class->close = stream_close;
-	camel_stream_class->flush = stream_flush;
-	camel_stream_class->eos = stream_eos;
-	camel_stream_class->reset = stream_reset;
+	GObjectClass *object_class;
+	CamelStreamClass *stream_class;
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = pop3_stream_dispose;
+	object_class->finalize = pop3_stream_finalize;
+
+	stream_class = CAMEL_STREAM_CLASS (class);
+	stream_class->read = stream_read;
+	stream_class->write = stream_write;
+	stream_class->close = stream_close;
+	stream_class->flush = stream_flush;
+	stream_class->eos = stream_eos;
+	stream_class->reset = stream_reset;
 }
 
 static void
-camel_pop3_stream_init(CamelPOP3Stream *is, CamelPOP3StreamClass *isclass)
+pop3_stream_init (CamelPOP3Stream *is)
 {
 	/* +1 is room for appending a 0 if we need to for a line */
-	is->ptr = is->end = is->buf = g_malloc(CAMEL_POP3_STREAM_SIZE+1);
-	is->lineptr = is->linebuf = g_malloc(CAMEL_POP3_STREAM_LINE+1);
+	is->ptr = is->end = is->buf = g_malloc (CAMEL_POP3_STREAM_SIZE+1);
+	is->lineptr = is->linebuf = g_malloc (CAMEL_POP3_STREAM_LINE+1);
 	is->lineend = is->linebuf + CAMEL_POP3_STREAM_LINE;
 
 	/* init sentinal */
@@ -215,32 +240,22 @@ camel_pop3_stream_init(CamelPOP3Stream *is, CamelPOP3StreamClass *isclass)
 	is->mode = CAMEL_POP3_STREAM_LINE;
 }
 
-static void
-camel_pop3_stream_finalise(CamelPOP3Stream *is)
-{
-	g_free(is->buf);
-	g_free(is->linebuf);
-	if (is->source)
-		camel_object_unref((CamelObject *)is->source);
-}
-
-CamelType
+GType
 camel_pop3_stream_get_type (void)
 {
-	static CamelType camel_pop3_stream_type = CAMEL_INVALID_TYPE;
-
-	if (camel_pop3_stream_type == CAMEL_INVALID_TYPE) {
-		camel_pop3_stream_type = camel_type_register( camel_stream_get_type(),
-							    "CamelPOP3Stream",
-							    sizeof( CamelPOP3Stream ),
-							    sizeof( CamelPOP3StreamClass ),
-							    (CamelObjectClassInitFunc) camel_pop3_stream_class_init,
-							    NULL,
-							    (CamelObjectInitFunc) camel_pop3_stream_init,
-							    (CamelObjectFinalizeFunc) camel_pop3_stream_finalise );
-	}
-
-	return camel_pop3_stream_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_STREAM,
+			"CamelPOP3Stream",
+			sizeof (CamelPOP3StreamClass),
+			(GClassInitFunc) pop3_stream_class_init,
+			sizeof (CamelPOP3Stream),
+			(GInstanceInitFunc) pop3_stream_init,
+			0);
+
+	return type;
 }
 
 /**
@@ -252,20 +267,19 @@ camel_pop3_stream_get_type (void)
  * Return value: the stream
  **/
 CamelStream *
-camel_pop3_stream_new(CamelStream *source)
+camel_pop3_stream_new (CamelStream *source)
 {
 	CamelPOP3Stream *is;
 
-	is = (CamelPOP3Stream *)camel_object_new(camel_pop3_stream_get_type ());
-	camel_object_ref((CamelObject *)source);
-	is->source = source;
+	is = g_object_new (CAMEL_TYPE_POP3_STREAM, NULL);
+	is->source = g_object_ref (source);
 
 	return (CamelStream *)is;
 }
 
 /* Get one line from the pop3 stream */
 gint
-camel_pop3_stream_line(CamelPOP3Stream *is, guchar **data, guint *len)
+camel_pop3_stream_line (CamelPOP3Stream *is, guchar **data, guint *len)
 {
 	register guchar c, *p, *o, *oe;
 	gint newlen, oldlen;
@@ -287,7 +301,7 @@ camel_pop3_stream_line(CamelPOP3Stream *is, guchar **data, guint *len)
 		/* need at least 3 chars in buffer */
 		while (e-p < 3) {
 			is->ptr = p;
-			if (stream_fill(is) == -1)
+			if (stream_fill (is) == -1)
 				return -1;
 			p = is->ptr;
 			e = is->end;
@@ -302,7 +316,7 @@ camel_pop3_stream_line(CamelPOP3Stream *is, guchar **data, guint *len)
 				*len = 0;
 				is->linebuf[0] = 0;
 
-				dd(printf("POP3_STREAM_LINE(END)\n"));
+				dd (printf ("POP3_STREAM_LINE (END)\n"));
 
 				return 0;
 			}
@@ -317,7 +331,7 @@ camel_pop3_stream_line(CamelPOP3Stream *is, guchar **data, guint *len)
 				/* sentinal? */
 				if (p> e) {
 					is->ptr = e;
-					if (stream_fill(is) == -1)
+					if (stream_fill (is) == -1)
 						return -1;
 					p = is->ptr;
 					e = is->end;
@@ -327,7 +341,7 @@ camel_pop3_stream_line(CamelPOP3Stream *is, guchar **data, guint *len)
 					*len = o - is->linebuf;
 					*o = 0;
 
-					dd(printf("POP3_STREAM_LINE(%d): '%s'\n", *len, *data));
+					dd (printf ("POP3_STREAM_LINE (%d): '%s'\n", *len, *data));
 
 					return 1;
 				}
@@ -339,7 +353,7 @@ camel_pop3_stream_line(CamelPOP3Stream *is, guchar **data, guint *len)
 		/* limit this for bad server data? */
 		oldlen = o - is->linebuf;
 		newlen = (is->lineend - is->linebuf) * 3 / 2;
-		is->lineptr = is->linebuf = g_realloc(is->linebuf, newlen);
+		is->lineptr = is->linebuf = g_realloc (is->linebuf, newlen);
 		is->lineend = is->linebuf + newlen;
 		oe = is->lineend - 1;
 		o = is->linebuf + oldlen;
@@ -349,7 +363,7 @@ camel_pop3_stream_line(CamelPOP3Stream *is, guchar **data, guint *len)
 }
 
 /* returns -1 on error, 0 if last lot of data, >0 if more remaining */
-gint camel_pop3_stream_gets(CamelPOP3Stream *is, guchar **start, guint *len)
+gint camel_pop3_stream_gets (CamelPOP3Stream *is, guchar **start, guint *len)
 {
 	gint max;
 	guchar *end;
@@ -358,31 +372,31 @@ gint camel_pop3_stream_gets(CamelPOP3Stream *is, guchar **start, guint *len)
 
 	max = is->end - is->ptr;
 	if (max == 0) {
-		max = stream_fill(is);
+		max = stream_fill (is);
 		if (max <= 0)
 			return max;
 	}
 
 	*start = is->ptr;
-	end = memchr(is->ptr, '\n', max);
+	end = memchr (is->ptr, '\n', max);
 	if (end)
 		max = (end - is->ptr) + 1;
 	*start = is->ptr;
 	*len = max;
 	is->ptr += max;
 
-	dd(printf("POP3_STREAM_GETS(%s,%d): '%.*s'\n", end==NULL?"more":"last", *len, (gint)*len, *start));
+	dd (printf ("POP3_STREAM_GETS (%s,%d): '%.*s'\n", end==NULL?"more":"last", *len, (gint)*len, *start));
 
 	return end == NULL?1:0;
 }
 
-void camel_pop3_stream_set_mode(CamelPOP3Stream *is, camel_pop3_stream_mode_t mode)
+void camel_pop3_stream_set_mode (CamelPOP3Stream *is, camel_pop3_stream_mode_t mode)
 {
 	is->mode = mode;
 }
 
 /* returns -1 on erorr, 0 if last data, >0 if more data left */
-gint camel_pop3_stream_getd(CamelPOP3Stream *is, guchar **start, guint *len)
+gint camel_pop3_stream_getd (CamelPOP3Stream *is, guchar **start, guint *len)
 {
 	guchar *p, *e, *s;
 	gint state;
@@ -393,7 +407,7 @@ gint camel_pop3_stream_getd(CamelPOP3Stream *is, guchar **start, guint *len)
 		return 0;
 
 	if (is->mode == CAMEL_POP3_STREAM_LINE) {
-		g_warning("pop3_stream reading data in line mode\n");
+		g_warning ("pop3_stream reading data in line mode\n");
 		return 0;
 	}
 
@@ -403,7 +417,7 @@ gint camel_pop3_stream_getd(CamelPOP3Stream *is, guchar **start, guint *len)
 
 	while (e - p < 3) {
 		is->ptr = p;
-		if (stream_fill(is) == -1)
+		if (stream_fill (is) == -1)
 			return -1;
 		p = is->ptr;
 		e = is->end;
@@ -423,7 +437,7 @@ gint camel_pop3_stream_getd(CamelPOP3Stream *is, guchar **start, guint *len)
 					is->mode = CAMEL_POP3_STREAM_EOD;
 					is->state = 0;
 
-					dd(printf("POP3_STREAM_GETD(%s,%d): '%.*s'\n", "last", *len, (gint)*len, *start));
+					dd (printf ("POP3_STREAM_GETD (%s,%d): '%.*s'\n", "last", *len, (gint)*len, *start));
 
 					return 0;
 				}
@@ -438,7 +452,7 @@ gint camel_pop3_stream_getd(CamelPOP3Stream *is, guchar **start, guint *len)
 					*start = s;
 					is->state = 1;
 
-					dd(printf("POP3_STREAM_GETD(%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
+					dd (printf ("POP3_STREAM_GETD (%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
 
 					return 1;
 				}
@@ -463,7 +477,7 @@ gint camel_pop3_stream_getd(CamelPOP3Stream *is, guchar **start, guint *len)
 	*len = p-s;
 	*start = s;
 
-	dd(printf("POP3_STREAM_GETD(%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
+	dd (printf ("POP3_STREAM_GETD (%s,%d): '%.*s'\n", "more", *len, (gint)*len, *start));
 
 	return 1;
 }
diff --git a/camel/providers/pop3/camel-pop3-stream.h b/camel/providers/pop3/camel-pop3-stream.h
index a019172..8aaa085 100644
--- a/camel/providers/pop3/camel-pop3-stream.h
+++ b/camel/providers/pop3/camel-pop3-stream.h
@@ -21,19 +21,34 @@
 /* This is *identical* to the camel-nntp-stream, so should probably
    work out a way to merge them */
 
-#ifndef _CAMEL_POP3_STREAM_H
-#define _CAMEL_POP3_STREAM_H
-
-#include <camel/camel-stream.h>
-
-#define CAMEL_POP3_STREAM(obj)         CAMEL_CHECK_CAST (obj, camel_pop3_stream_get_type (), CamelPOP3Stream)
-#define CAMEL_POP3_STREAM_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_pop3_stream_get_type (), CamelPOP3StreamClass)
-#define CAMEL_IS_POP3_STREAM(obj)      CAMEL_CHECK_TYPE (obj, camel_pop3_stream_get_type ())
+#ifndef CAMEL_POP3_STREAM_H
+#define CAMEL_POP3_STREAM_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_POP3_STREAM \
+	(camel_pop3_stream_get_type ())
+#define CAMEL_POP3_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_POP3_STREAM, CamelPOP3Stream))
+#define CAMEL_POP3_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_POP3_STREAM, CamelPOP3StreamClass))
+#define CAMEL_IS_POP3_STREAM(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_POP3_STREAM))
+#define CAMEL_IS_POP3_STREAM_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_POP3_STREAM))
+#define CAMEL_POP3_STREAM_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_POP3_STREAM, CamelPOP3StreamClass))
 
 G_BEGIN_DECLS
 
-typedef struct _CamelPOP3StreamClass CamelPOP3StreamClass;
 typedef struct _CamelPOP3Stream CamelPOP3Stream;
+typedef struct _CamelPOP3StreamClass CamelPOP3StreamClass;
 
 typedef enum {
 	CAMEL_POP3_STREAM_LINE,
@@ -57,7 +72,7 @@ struct _CamelPOP3StreamClass {
 	CamelStreamClass parent_class;
 };
 
-CamelType		 camel_pop3_stream_get_type	(void);
+GType		 camel_pop3_stream_get_type	(void);
 
 CamelStream     *camel_pop3_stream_new		(CamelStream *source);
 
@@ -69,4 +84,4 @@ gint		 camel_pop3_stream_getd		(CamelPOP3Stream *is, guchar **start, guint *len)
 
 G_END_DECLS
 
-#endif /* ! _CAMEL_POP3_STREAM_H */
+#endif /* CAMEL_POP3_STREAM_H */
diff --git a/camel/providers/sendmail/camel-sendmail-provider.c b/camel/providers/sendmail/camel-sendmail-provider.c
index 9858e70..da0aa28 100644
--- a/camel/providers/sendmail/camel-sendmail-provider.c
+++ b/camel/providers/sendmail/camel-sendmail-provider.c
@@ -26,12 +26,10 @@
 #include <config.h>
 #endif
 
+#include <camel/camel.h>
 #include <glib/gi18n-lib.h>
 
-#include "camel-provider.h"
 #include "camel-sendmail-transport.h"
-#include "camel-session.h"
-#include "camel-url.h"
 
 static CamelProvider sendmail_provider = {
 	"sendmail",
@@ -52,7 +50,7 @@ static CamelProvider sendmail_provider = {
 void
 camel_provider_module_init(void)
 {
-	sendmail_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_sendmail_transport_get_type();
+	sendmail_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_sendmail_transport_get_type ();
 
 	sendmail_provider.url_hash = camel_url_hash;
 	sendmail_provider.url_equal = camel_url_equal;
diff --git a/camel/providers/sendmail/camel-sendmail-transport.c b/camel/providers/sendmail/camel-sendmail-transport.c
index 7038f7c..0818c7d 100644
--- a/camel/providers/sendmail/camel-sendmail-transport.c
+++ b/camel/providers/sendmail/camel-sendmail-transport.c
@@ -35,13 +35,7 @@
 
 #include <glib/gi18n-lib.h>
 
-#include "camel-data-wrapper.h"
-#include "camel-exception.h"
-#include "camel-mime-filter-crlf.h"
-#include "camel-mime-message.h"
 #include "camel-sendmail-transport.h"
-#include "camel-stream-filter.h"
-#include "camel-stream-fs.h"
 
 static gchar *get_name (CamelService *service, gboolean brief);
 
@@ -51,35 +45,34 @@ static gboolean sendmail_send_to (CamelTransport *transport,
 				  CamelException *ex);
 
 static void
-camel_sendmail_transport_class_init (CamelSendmailTransportClass *camel_sendmail_transport_class)
+sendmail_transport_class_init (CamelSendmailTransportClass *class)
 {
-	CamelTransportClass *camel_transport_class =
-		CAMEL_TRANSPORT_CLASS (camel_sendmail_transport_class);
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_sendmail_transport_class);
-
-	/* virtual method overload */
-	camel_service_class->get_name = get_name;
-	camel_transport_class->send_to = sendmail_send_to;
+	CamelServiceClass *service_class;
+	CamelTransportClass *transport_class;
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->get_name = get_name;
+
+	transport_class = CAMEL_TRANSPORT_CLASS (class);
+	transport_class->send_to = sendmail_send_to;
 }
 
-CamelType
+GType
 camel_sendmail_transport_get_type (void)
 {
-	static CamelType camel_sendmail_transport_type = CAMEL_INVALID_TYPE;
-
-	if (camel_sendmail_transport_type == CAMEL_INVALID_TYPE)	{
-		camel_sendmail_transport_type =
-			camel_type_register (CAMEL_TRANSPORT_TYPE, "CamelSendmailTransport",
-					     sizeof (CamelSendmailTransport),
-					     sizeof (CamelSendmailTransportClass),
-					     (CamelObjectClassInitFunc) camel_sendmail_transport_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) NULL,
-					     NULL);
-	}
-
-	return camel_sendmail_transport_type;
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID)
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_TRANSPORT,
+			"CamelSendmailTransport",
+			sizeof (CamelSendmailTransportClass),
+			(GClassInitFunc) sendmail_transport_class_init,
+			sizeof (CamelSendmailTransport),
+			(GInstanceInitFunc) NULL,
+			0);
+
+	return type;
 }
 
 static gboolean
@@ -90,7 +83,7 @@ sendmail_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	struct _camel_header_raw *header, *savedbcc, *n, *tail;
 	const gchar *from_addr, *addr, **argv;
 	gint i, len, fd[2], nullfd, wstat;
-	CamelStreamFilter *filter;
+	CamelStream *filter;
 	CamelMimeFilter *crlf;
 	sigset_t mask, omask;
 	CamelStream *out;
@@ -124,7 +117,7 @@ sendmail_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	savedbcc = NULL;
 	tail = (struct _camel_header_raw *) &savedbcc;
 
-	header = (struct _camel_header_raw *) &CAMEL_MIME_PART (message)->headers;
+	header = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (message));
 	n = header->next;
 	while (n != NULL) {
 		if (!g_ascii_strcasecmp (n->name, "Bcc")) {
@@ -193,16 +186,16 @@ sendmail_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	out = camel_stream_fs_new_with_fd (fd[1]);
 
 	/* workaround for lame sendmail implementations that can't handle CRLF eoln sequences */
-	filter = camel_stream_filter_new_with_stream (out);
+	filter = camel_stream_filter_new (out);
 	crlf = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_DECODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
-	camel_stream_filter_add (filter, crlf);
-	camel_object_unref (crlf);
-	camel_object_unref (out);
+	camel_stream_filter_add (CAMEL_STREAM_FILTER (filter), crlf);
+	g_object_unref (crlf);
+	g_object_unref (out);
 
-	out = (CamelStream *) filter;
+	out = filter;
 	if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), out) == -1
 	    || camel_stream_close (out) == -1) {
-		camel_object_unref (CAMEL_OBJECT (out));
+		g_object_unref (CAMEL_OBJECT (out));
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Could not send message: %s"),
 				      g_strerror (errno));
@@ -219,7 +212,7 @@ sendmail_send_to (CamelTransport *transport, CamelMimeMessage *message,
 		return FALSE;
 	}
 
-	camel_object_unref (CAMEL_OBJECT (out));
+	g_object_unref (CAMEL_OBJECT (out));
 
 	/* Wait for sendmail to exit. */
 	while (waitpid (pid, &wstat, 0) == -1 && errno == EINTR)
diff --git a/camel/providers/sendmail/camel-sendmail-transport.h b/camel/providers/sendmail/camel-sendmail-transport.h
index 0f963d2..7ab978c 100644
--- a/camel/providers/sendmail/camel-sendmail-transport.h
+++ b/camel/providers/sendmail/camel-sendmail-transport.h
@@ -24,29 +24,43 @@
  */
 
 #ifndef CAMEL_SENDMAIL_TRANSPORT_H
-#define CAMEL_SENDMAIL_TRANSPORT_H 1
+#define CAMEL_SENDMAIL_TRANSPORT_H
 
-#include "camel-transport.h"
+#include <camel/camel.h>
 
-#define CAMEL_SENDMAIL_TRANSPORT_TYPE     (camel_sendmail_transport_get_type ())
-#define CAMEL_SENDMAIL_TRANSPORT(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SENDMAIL_TRANSPORT_TYPE, CamelSendmailTransport))
-#define CAMEL_SENDMAIL_TRANSPORT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SENDMAIL_TRANSPORT_TYPE, CamelSendmailTransportClass))
-#define CAMEL_IS_SENDMAIL_TRANSPORT(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SENDMAIL_TRANSPORT_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_SENDMAIL_TRANSPORT \
+	(camel_sendmail_transport_get_type ())
+#define CAMEL_SENDMAIL_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SENDMAIL_TRANSPORT, CamelSendmailTransport))
+#define CAMEL_SENDMAIL_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SENDMAIL_TRANSPORT, CamelSendmailTransportClass))
+#define CAMEL_IS_SENDMAIL_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SENDMAIL_TRANSPORT))
+#define CAMEL_IS_SENDMAIL_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SENDMAIL_TRANSPORT))
+#define CAMEL_SENDMAIL_TRANSPORT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SENDMAIL_TRANSPORT, CamelSendmailTransportClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelTransport parent_object;
+typedef struct _CamelSendmailTransport CamelSendmailTransport;
+typedef struct _CamelSendmailTransportClass CamelSendmailTransportClass;
 
-} CamelSendmailTransport;
+struct _CamelSendmailTransport {
+	CamelTransport parent;
+};
 
-typedef struct {
+struct _CamelSendmailTransportClass {
 	CamelTransportClass parent_class;
+};
 
-} CamelSendmailTransportClass;
-
-/* Standard Camel function */
-CamelType camel_sendmail_transport_get_type (void);
+GType camel_sendmail_transport_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/providers/smtp/camel-smtp-provider.c b/camel/providers/smtp/camel-smtp-provider.c
index 1daec9c..0136828 100644
--- a/camel/providers/smtp/camel-smtp-provider.c
+++ b/camel/providers/smtp/camel-smtp-provider.c
@@ -25,13 +25,10 @@
 #include <config.h>
 #endif
 
+#include <camel/camel.h>
 #include <glib/gi18n-lib.h>
 
-#include "camel-provider.h"
-#include "camel-sasl.h"
-#include "camel-session.h"
 #include "camel-smtp-transport.h"
-#include "camel-url.h"
 
 static guint smtp_url_hash (gconstpointer key);
 static gint smtp_url_equal (gconstpointer a, gconstpointer b);
diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c
index 41d398b..6c9308b 100644
--- a/camel/providers/smtp/camel-smtp-transport.c
+++ b/camel/providers/smtp/camel-smtp-transport.c
@@ -36,31 +36,11 @@
 
 #include <glib/gi18n-lib.h>
 
-#undef MIN
-#undef MAX
-
-#include "camel-exception.h"
-#include "camel-mime-filter-progress.h"
-#include "camel-mime-filter-crlf.h"
-#include "camel-mime-message.h"
-#include "camel-mime-part.h"
-#include "camel-multipart.h"
-#include "camel-net-utils.h"
-#include "camel-operation.h"
-#include "camel-sasl.h"
-#include "camel-session.h"
 #include "camel-smtp-transport.h"
-#include "camel-stream-buffer.h"
-#include "camel-stream-filter.h"
-#include "camel-stream-null.h"
-#include "camel-tcp-stream-raw.h"
-#include "camel-tcp-stream.h"
 
-#ifdef HAVE_SSL
-#include "camel-tcp-stream-ssl.h"
-#endif
+#undef MIN
+#undef MAX
 
-extern gint camel_verbose_debug;
 #define d(x) (camel_verbose_debug ? (x) : 0)
 
 /* Specified in RFC 821 */
@@ -72,9 +52,6 @@ static gboolean smtp_send_to (CamelTransport *transport, CamelMimeMessage *messa
 			      CamelAddress *from, CamelAddress *recipients, CamelException *ex);
 
 /* support prototypes */
-static void smtp_construct (CamelService *service, CamelSession *session,
-			    CamelProvider *provider, CamelURL *url,
-			    CamelException *ex);
 static gboolean smtp_connect (CamelService *service, CamelException *ex);
 static gboolean smtp_disconnect (CamelService *service, gboolean clean, CamelException *ex);
 static GHashTable *esmtp_get_authtypes (const guchar *buffer);
@@ -93,65 +70,51 @@ static gboolean smtp_quit (CamelSmtpTransport *transport, CamelException *ex);
 static void smtp_set_exception (CamelSmtpTransport *transport, gboolean disconnect, const gchar *respbuf,
 				const gchar *message, CamelException *ex);
 
-/* private data members */
-static CamelTransportClass *parent_class = NULL;
+static gpointer parent_class;
 
 static void
-camel_smtp_transport_class_init (CamelSmtpTransportClass *camel_smtp_transport_class)
+smtp_transport_class_init (CamelSmtpTransportClass *class)
 {
-	CamelTransportClass *camel_transport_class =
-		CAMEL_TRANSPORT_CLASS (camel_smtp_transport_class);
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_smtp_transport_class);
+	CamelTransportClass *transport_class;
+	CamelServiceClass *service_class;
 
-	parent_class = CAMEL_TRANSPORT_CLASS (camel_type_get_global_classfuncs (camel_transport_get_type ()));
+	parent_class = g_type_class_peek_parent (class);
 
-	/* virtual method overload */
-	camel_service_class->construct = smtp_construct;
-	camel_service_class->connect = smtp_connect;
-	camel_service_class->disconnect = smtp_disconnect;
-	camel_service_class->query_auth_types = query_auth_types;
-	camel_service_class->get_name = get_name;
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->connect = smtp_connect;
+	service_class->disconnect = smtp_disconnect;
+	service_class->query_auth_types = query_auth_types;
+	service_class->get_name = get_name;
 
-	camel_transport_class->send_to = smtp_send_to;
+	transport_class = CAMEL_TRANSPORT_CLASS (class);
+	transport_class->send_to = smtp_send_to;
 }
 
 static void
-camel_smtp_transport_init (gpointer object)
+smtp_transport_init (CamelSmtpTransport *smtp)
 {
-	CamelSmtpTransport *smtp = CAMEL_SMTP_TRANSPORT (object);
-
 	smtp->flags = 0;
 	smtp->connected = FALSE;
 }
 
-CamelType
+GType
 camel_smtp_transport_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_TRANSPORT_TYPE,
-					    "CamelSmtpTransport",
-					    sizeof (CamelSmtpTransport),
-					    sizeof (CamelSmtpTransportClass),
-					    (CamelObjectClassInitFunc) camel_smtp_transport_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_smtp_transport_init,
-					    NULL);
-	}
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_type_register_static_simple (
+			CAMEL_TYPE_TRANSPORT,
+			"CamelSmtpTransport",
+			sizeof (CamelSmtpTransportClass),
+			(GClassInitFunc) smtp_transport_class_init,
+			sizeof (CamelSmtpTransport),
+			(GInstanceInitFunc) smtp_transport_init,
+			0);
 
 	return type;
 }
 
-static void
-smtp_construct (CamelService *service, CamelSession *session,
-		CamelProvider *provider, CamelURL *url,
-		CamelException *ex)
-{
-	CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
-}
-
 static const gchar *
 smtp_error_string (gint error)
 {
@@ -274,7 +237,7 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 					      _("Could not connect to %s: %s"),
 					      service->url->host, g_strerror (errno));
 
-		camel_object_unref (tcp_stream);
+		g_object_unref (tcp_stream);
 
 		return FALSE;
 	}
@@ -384,9 +347,9 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
 
  exception_cleanup:
 
-	camel_object_unref (transport->istream);
+	g_object_unref (transport->istream);
 	transport->istream = NULL;
-	camel_object_unref (transport->ostream);
+	g_object_unref (transport->ostream);
 	transport->ostream = NULL;
 
 	transport->connected = FALSE;
@@ -468,10 +431,10 @@ 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);
+		g_object_unref (sasl);
 
 		if (!truth)
 			return FALSE;
@@ -614,12 +577,12 @@ smtp_disconnect (CamelService *service, gboolean clean, CamelException *ex)
 	}
 
 	if (transport->istream) {
-		camel_object_unref (transport->istream);
+		g_object_unref (transport->istream);
 		transport->istream = NULL;
 	}
 
 	if (transport->ostream) {
-		camel_object_unref (transport->ostream);
+		g_object_unref (transport->ostream);
 		transport->ostream = NULL;
 	}
 
@@ -1121,7 +1084,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));
@@ -1185,7 +1148,7 @@ smtp_auth (CamelSmtpTransport *transport, const gchar *mech, CamelException *ex)
 	if (strncmp (respbuf, "235", 3) != 0)
 		goto lose;
 
-	camel_object_unref (sasl);
+	g_object_unref (sasl);
 	camel_operation_end (NULL);
 
 	return TRUE;
@@ -1203,7 +1166,7 @@ smtp_auth (CamelSmtpTransport *transport, const gchar *mech, CamelException *ex)
 				     _("Bad authentication response from server.\n"));
 	}
 
-	camel_object_unref (sasl);
+	g_object_unref (sasl);
 	camel_operation_end (NULL);
 
 	g_free (respbuf);
@@ -1304,7 +1267,7 @@ smtp_data (CamelSmtpTransport *transport, CamelMimeMessage *message, CamelExcept
 {
 	struct _camel_header_raw *header, *savedbcc, *n, *tail;
 	CamelBestencEncoding enctype = CAMEL_BESTENC_8BIT;
-	CamelStreamFilter *filtered_stream;
+	CamelStream *filtered_stream;
 	gchar *cmdbuf, *respbuf = NULL;
 	CamelMimeFilter *filter;
 	CamelStreamNull *null;
@@ -1356,7 +1319,7 @@ smtp_data (CamelSmtpTransport *transport, CamelMimeMessage *message, CamelExcept
 	savedbcc = NULL;
 	tail = (struct _camel_header_raw *) &savedbcc;
 
-	header = (struct _camel_header_raw *) &CAMEL_MIME_PART (message)->headers;
+	header = camel_mime_part_get_raw_headers (CAMEL_MIME_PART (message));
 	n = header->next;
 	while (n != NULL) {
 		if (!g_ascii_strcasecmp (n->name, "Bcc")) {
@@ -1373,23 +1336,29 @@ smtp_data (CamelSmtpTransport *transport, CamelMimeMessage *message, CamelExcept
 
 	/* find out how large the message is... */
 	null = CAMEL_STREAM_NULL (camel_stream_null_new ());
-	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), CAMEL_STREAM (null));
+	camel_data_wrapper_write_to_stream (
+		CAMEL_DATA_WRAPPER (message), CAMEL_STREAM (null));
 
-	filtered_stream = camel_stream_filter_new_with_stream (transport->ostream);
+	filtered_stream = camel_stream_filter_new (transport->ostream);
 
 	/* setup progress reporting for message sending... */
 	filter = camel_mime_filter_progress_new (NULL, null->written);
-	camel_stream_filter_add (filtered_stream, filter);
-	camel_object_unref (filter);
-	camel_object_unref (null);
+	camel_stream_filter_add (
+		CAMEL_STREAM_FILTER (filtered_stream), filter);
+	g_object_unref (filter);
+	g_object_unref (null);
 
 	/* setup LF->CRLF conversion */
-	filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS);
-	camel_stream_filter_add (filtered_stream, filter);
-	camel_object_unref (filter);
+	filter = camel_mime_filter_crlf_new (
+		CAMEL_MIME_FILTER_CRLF_ENCODE,
+		CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS);
+	camel_stream_filter_add (
+		CAMEL_STREAM_FILTER (filtered_stream), filter);
+	g_object_unref (filter);
 
 	/* write the message */
-	ret = camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), CAMEL_STREAM (filtered_stream));
+	ret = camel_data_wrapper_write_to_stream (
+		CAMEL_DATA_WRAPPER (message), filtered_stream);
 
 	/* restore the bcc headers */
 	header->next = savedbcc;
@@ -1399,15 +1368,15 @@ smtp_data (CamelSmtpTransport *transport, CamelMimeMessage *message, CamelExcept
 				      _("DATA command failed: %s: mail not sent"),
 				      g_strerror (errno));
 
-		camel_object_unref (filtered_stream);
+		g_object_unref (filtered_stream);
 
 		camel_service_disconnect ((CamelService *) transport, FALSE, NULL);
 
 		return FALSE;
 	}
 
-	camel_stream_flush (CAMEL_STREAM (filtered_stream));
-	camel_object_unref (filtered_stream);
+	camel_stream_flush (filtered_stream);
+	g_object_unref (filtered_stream);
 
 	/* terminate the message body */
 
diff --git a/camel/providers/smtp/camel-smtp-transport.h b/camel/providers/smtp/camel-smtp-transport.h
index 1390f26..86b5474 100644
--- a/camel/providers/smtp/camel-smtp-transport.h
+++ b/camel/providers/smtp/camel-smtp-transport.h
@@ -23,15 +23,28 @@
  */
 
 #ifndef CAMEL_SMTP_TRANSPORT_H
-#define CAMEL_SMTP_TRANSPORT_H 1
-
-#include "camel-transport.h"
-#include "camel-tcp-stream.h"
-
-#define CAMEL_SMTP_TRANSPORT_TYPE     (camel_smtp_transport_get_type ())
-#define CAMEL_SMTP_TRANSPORT(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SMTP_TRANSPORT_TYPE, CamelSmtpTransport))
-#define CAMEL_SMTP_TRANSPORT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SMTP_TRANSPORT_TYPE, CamelSmtpTransportClass))
-#define CAMEL_IS_SMTP_TRANSPORT(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SMTP_TRANSPORT_TYPE))
+#define CAMEL_SMTP_TRANSPORT_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_SMTP_TRANSPORT \
+	(camel_smtp_transport_get_type ())
+#define CAMEL_SMTP_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_SMTP_TRANSPORT, CamelSmtpTransport))
+#define CAMEL_SMTP_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_SMTP_TRANSPORT, CamelSmtpTransportClass))
+#define CAMEL_IS_SMTP_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_SMTP_TRANSPORT))
+#define CAMEL_IS_SMTP_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_SMTP_TRANSPORT))
+#define CAMEL_SMTP_TRANSPORT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_SMTP_TRANSPORT, CamelSmtpTransportClass))
 
 #define CAMEL_SMTP_TRANSPORT_IS_ESMTP               (1 << 0)
 #define CAMEL_SMTP_TRANSPORT_8BITMIME               (1 << 1)
@@ -42,8 +55,11 @@
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelTransport parent_object;
+typedef struct _CamelSmtpTransport CamelSmtpTransport;
+typedef struct _CamelSmtpTransportClass CamelSmtpTransportClass;
+
+struct _CamelSmtpTransport {
+	CamelTransport parent;
 
 	CamelStream *istream, *ostream;
 
@@ -54,15 +70,13 @@ typedef struct {
 	socklen_t localaddrlen;
 
 	GHashTable *authtypes;
-} CamelSmtpTransport;
+};
 
-typedef struct {
+struct _CamelSmtpTransportClass {
 	CamelTransportClass parent_class;
+};
 
-} CamelSmtpTransportClass;
-
-/* Standard Camel function */
-CamelType camel_smtp_transport_get_type (void);
+GType camel_smtp_transport_get_type (void);
 
 G_END_DECLS
 
diff --git a/camel/tests/folder/test1.c b/camel/tests/folder/test1.c
index 6261b1d..29a37ad 100644
--- a/camel/tests/folder/test1.c
+++ b/camel/tests/folder/test1.c
@@ -47,7 +47,7 @@ gint main(gint argc, gchar **argv)
 		g_free(path);
 	}
 
-	camel_object_unref((CamelObject *)session);
+	g_object_unref (session);
 	camel_exception_free(ex);
 
 	return 0;
diff --git a/camel/tests/folder/test10.c b/camel/tests/folder/test10.c
index 2c980b5..175dc30 100644
--- a/camel/tests/folder/test10.c
+++ b/camel/tests/folder/test10.c
@@ -43,11 +43,11 @@ worker(gpointer d)
 		folder = camel_store_get_folder(store, "testbox", CAMEL_STORE_FOLDER_CREATE, ex);
 		camel_exception_clear(ex);
 		if (testid == 0) {
-			camel_object_unref(folder);
-			camel_object_unref(store);
+			g_object_unref (folder);
+			g_object_unref (store);
 		} else {
-			camel_object_unref(store);
-			camel_object_unref(folder);
+			g_object_unref (store);
+			g_object_unref (folder);
 		}
 	}
 
@@ -97,7 +97,7 @@ gint main(gint argc, gchar **argv)
 		camel_test_end();
 	}
 
-	camel_object_unref((CamelObject *)session);
+	g_object_unref (session);
 	camel_exception_free(ex);
 
 	return 0;
diff --git a/camel/tests/folder/test4.c b/camel/tests/folder/test4.c
index 411b0c5..a24b5b9 100644
--- a/camel/tests/folder/test4.c
+++ b/camel/tests/folder/test4.c
@@ -48,7 +48,7 @@ gint main(gint argc, gchar **argv)
 		/*camel_test_fatal();*/
 	}
 
-	camel_object_unref((CamelObject *)session);
+	g_object_unref (session);
 	camel_exception_free(ex);
 
 	return 0;
diff --git a/camel/tests/folder/test5.c b/camel/tests/folder/test5.c
index f2a0a8f..d2cbbe4 100644
--- a/camel/tests/folder/test5.c
+++ b/camel/tests/folder/test5.c
@@ -48,7 +48,7 @@ gint main(gint argc, gchar **argv)
 		camel_test_fatal();
 	}
 
-	camel_object_unref((CamelObject *)session);
+	g_object_unref (session);
 	camel_exception_free(ex);
 
 	return 0;
diff --git a/camel/tests/folder/test8.c b/camel/tests/folder/test8.c
index f2c2e1c..b4cf7ff 100644
--- a/camel/tests/folder/test8.c
+++ b/camel/tests/folder/test8.c
@@ -90,7 +90,7 @@ worker(gpointer d)
 
 		content = g_strdup_printf("Test message %08x contents\n\n", id+i);
 		push("comparing content '%s': '%s'", res->pdata[0], content);
-		test_message_compare_content(camel_medium_get_content_object((CamelMedium *)msg), content, strlen(content));
+		test_message_compare_content(camel_medium_get_content((CamelMedium *)msg), content, strlen(content));
 		test_free(content);
 		pull();
 
@@ -200,7 +200,7 @@ gint main(gint argc, gchar **argv)
 		}
 	}
 
-	camel_object_unref((CamelObject *)session);
+	g_object_unref (session);
 	camel_exception_free(ex);
 
 	return 0;
diff --git a/camel/tests/folder/test9.c b/camel/tests/folder/test9.c
index 326064c..ad46335 100644
--- a/camel/tests/folder/test9.c
+++ b/camel/tests/folder/test9.c
@@ -81,7 +81,7 @@ static CamelFolder *get_folder(CamelFilterDriver *d, const gchar *uri, gpointer
 
 	for (i = 0; i < G_N_ELEMENTS (mailboxes); i++)
 		if (!strcmp(mailboxes[i].name, uri)) {
-			camel_object_ref((CamelObject *)mailboxes[i].folder);
+			g_object_ref (mailboxes[i].folder);
 			return mailboxes[i].folder;
 		}
 	return NULL;
diff --git a/camel/tests/lib/camel-test-provider.c b/camel/tests/lib/camel-test-provider.c
index 03e13f6..f2904f1 100644
--- a/camel/tests/lib/camel-test-provider.c
+++ b/camel/tests/lib/camel-test-provider.c
@@ -5,7 +5,7 @@
 
 #include "camel-provider.h"
 
-void camel_test_provider_init(gint argc, gchar **argv)
+void test_provider_init(gint argc, gchar **argv)
 {
 	gchar *name, *path;
 	gint i;
diff --git a/camel/tests/lib/camel-test-provider.h b/camel/tests/lib/camel-test-provider.h
index f9f19ba..2ab7ba1 100644
--- a/camel/tests/lib/camel-test-provider.h
+++ b/camel/tests/lib/camel-test-provider.h
@@ -1,6 +1,6 @@
 
-#ifndef _CAMEL_TEST_PROVIDER_H
-#define _CAMEL_TEST_PROVIDER_H
+#ifndef CAMEL_TEST_PROVIDER_H
+#define CAMEL_TEST_PROVIDER_H
 
 #include <glib.h>
 
diff --git a/camel/tests/lib/camel-test.c b/camel/tests/lib/camel-test.c
index 9cf38a6..06ebcd8 100644
--- a/camel/tests/lib/camel-test.c
+++ b/camel/tests/lib/camel-test.c
@@ -96,7 +96,7 @@ current_state(void)
 	return info;
 }
 
-void camel_test_init(gint argc, gchar **argv)
+void test_init(gint argc, gchar **argv)
 {
 	struct stat st;
 	gchar *path;
@@ -120,7 +120,7 @@ void camel_test_init(gint argc, gchar **argv)
 	camel_init (path, FALSE);
 	g_free (path);
 
-	camel_type_init ();
+	type_init ();
 
 	info_table = g_hash_table_new(0, 0);
 
@@ -153,7 +153,7 @@ void camel_test_start(const gchar *what)
 	s = current_state();
 
 	if (!setup)
-		camel_test_init(0, 0);
+		test_init(0, 0);
 
 	ok = 1;
 
diff --git a/camel/tests/lib/camel-test.h b/camel/tests/lib/camel-test.h
index facd942..74c3f4c 100644
--- a/camel/tests/lib/camel-test.h
+++ b/camel/tests/lib/camel-test.h
@@ -34,7 +34,7 @@ static void check_msg(gint truth, gchar *fmt, ...)
 
 #define check_unref(object, expected) do { \
 	check_count(object, expected); \
-	camel_object_unref(CAMEL_OBJECT(object)); \
+	g_object_unref(CAMEL_OBJECT(object)); \
 	if (expected == 1) { \
 		object = NULL; \
 	} \
diff --git a/camel/tests/lib/folders.c b/camel/tests/lib/folders.c
index aaae49e..3d752c4 100644
--- a/camel/tests/lib/folders.c
+++ b/camel/tests/lib/folders.c
@@ -107,7 +107,7 @@ test_folder_message(CamelFolder *folder, const gchar *uid)
 	/* cross check with info */
 	test_message_info(msg, info);
 
-	camel_object_unref((CamelObject *)msg);
+	g_object_unref (msg);
 
 	/* see if it is in the summary (only once) */
 	s = camel_folder_get_summary(folder);
diff --git a/camel/tests/lib/messages.c b/camel/tests/lib/messages.c
index d4dc028..0ddf1fb 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;
 	}
 
@@ -83,7 +83,7 @@ test_message_set_content_simple(CamelMimePart *part, gint how, const gchar *type
                 camel_data_wrapper_set_mime_type (dw, type);
 
 		camel_data_wrapper_construct_from_stream(dw, (CamelStream *)content);
-		camel_medium_set_content_object((CamelMedium *)part, dw);
+		camel_medium_set_content((CamelMedium *)part, dw);
 
 		check_unref(content, 2);
 		check_unref(dw, 2);
@@ -101,7 +101,7 @@ test_message_write_file(CamelMimeMessage *msg, const gchar *name)
 	ret = camel_stream_close((CamelStream *)file);
 
 	check(((CamelObject *)file)->ref_count == 1);
-	camel_object_unref((CamelObject *)file);
+	g_object_unref (file);
 
 	return ret;
 }
@@ -118,7 +118,7 @@ test_message_read_file(const gchar *name)
 	camel_data_wrapper_construct_from_stream((CamelDataWrapper *)msg2, (CamelStream *)file);
 	/* file's refcount may be > 1 if the message is real big */
 	check(CAMEL_OBJECT(file)->ref_count >=1);
-	camel_object_unref((CamelObject *)file);
+	g_object_unref (file);
 
 	return msg2;
 }
@@ -211,7 +211,7 @@ test_message_compare (CamelMimeMessage *msg)
 		printf("msg2:\n");
 		test_message_dump_structure(msg2);
 
-		content = camel_medium_get_content_object ((CamelMedium *) msg);
+		content = camel_medium_get_content ((CamelMedium *) msg);
 	}
 
 	check_unref(msg2, 1);
@@ -222,8 +222,8 @@ test_message_compare (CamelMimeMessage *msg)
 
 	check_msg (memcmp (mem1->buffer->data, mem2->buffer->data, mem1->buffer->len) == 0, "msg/stream compare");
 
-	camel_object_unref (mem1);
-	camel_object_unref (mem2);
+	g_object_unref (mem1);
+	g_object_unref (mem2);
 
 	return 0;
 }
@@ -253,19 +253,19 @@ message_dump_rec(CamelMimeMessage *msg, CamelMimePart *part, gint depth)
 	s[depth] = 0;
 
 	mime_type = camel_data_wrapper_get_mime_type((CamelDataWrapper *)part);
-	printf("%sPart <%s>\n", s, ((CamelObject *)part)->klass->name);
+	printf("%sPart <%s>\n", s, ((CamelObject *)part)->class->name);
 	printf("%sContent-Type: %s\n", s, mime_type);
 	g_free(mime_type);
 	printf("%s encoding: %s\n", s, camel_transfer_encoding_to_string(((CamelDataWrapper *)part)->encoding));
 	printf("%s part encoding: %s\n", s, camel_transfer_encoding_to_string(part->encoding));
 
-	containee = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+	containee = camel_medium_get_content (CAMEL_MEDIUM (part));
 
 	if (containee == NULL)
 		return;
 
 	mime_type = camel_data_wrapper_get_mime_type(containee);
-	printf("%sContent <%s>\n", s, ((CamelObject *)containee)->klass->name);
+	printf("%sContent <%s>\n", s, ((CamelObject *)containee)->class->name);
 	printf ("%sContent-Type: %s\n", s, mime_type);
 	g_free (mime_type);
 	printf("%s encoding: %s\n", s, camel_transfer_encoding_to_string(((CamelDataWrapper *)containee)->encoding));
diff --git a/camel/tests/lib/session.c b/camel/tests/lib/session.c
index a3d3d2b..0ef047c 100644
--- a/camel/tests/lib/session.c
+++ b/camel/tests/lib/session.c
@@ -11,22 +11,21 @@ class_init (CamelTestSessionClass *camel_test_session_class)
 		CAMEL_SESSION_CLASS (camel_test_session_class);
 }
 
-CamelType
+GType
 camel_test_session_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (type == CAMEL_INVALID_TYPE) {
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
 		type = camel_type_register (
-			camel_session_get_type (),
+			CAMEL_TYPE_SESSION,
 			"CamelTestSession",
 			sizeof (CamelTestSession),
 			sizeof (CamelTestSessionClass),
-			(CamelObjectClassInitFunc) class_init,
+			(GClassInitFunc) class_init,
 			NULL,
 			NULL,
 			NULL);
-	}
 
 	return type;
 }
@@ -36,8 +35,7 @@ camel_test_session_new (const gchar *path)
 {
 	CamelSession *session;
 
-	session = CAMEL_SESSION (camel_object_new (CAMEL_TEST_SESSION_TYPE));
-
+	session = g_object_new (CAMEL_TYPE_TEST_SESSION, NULL);
 	camel_session_construct (session, path);
 
 	return session;
diff --git a/camel/tests/lib/session.h b/camel/tests/lib/session.h
index d2943b1..9838338 100644
--- a/camel/tests/lib/session.h
+++ b/camel/tests/lib/session.h
@@ -1,19 +1,38 @@
 #include <camel/camel-session.h>
 
-#define CAMEL_TEST_SESSION_TYPE     (camel_test_session_get_type ())
-#define CAMEL_TEST_SESSION(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_TEST_SESSION_TYPE, CamelTestSession))
-#define CAMEL_TEST_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TEST_SESSION_TYPE, CamelTestSessionClass))
-#define CAMEL_TEST_IS_SESSION(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TEST_SESSION_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_TEST_SESSION \
+	(camel_test_session_get_type ())
+#define CAMEL_TEST_SESSION(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_TEST_SESSION, CamelTestSession))
+#define CAMEL_TEST_SESSION_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_TEST_SESSION, CamelTestSessionClass))
+#define CAMEL_IS_TEST_SESSION(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_TEST_SESSION))
+#define CAMEL_IS_TEST_SESSION_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_TEST_SESSION))
+#define CAMEL_TEST_SESSION_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_TEST_SESSION, CamelTestSessionClass))
 
-typedef struct _CamelTestSession {
-	CamelSession parent_object;
+G_BEGIN_DECLS
 
-} CamelTestSession;
+typedef struct _CamelTestSession CamelTestSession;
+typedef struct _CamelTestSessionClass CamelTestSessionClass;
 
-typedef struct _CamelTestSessionClass {
-	CamelSessionClass parent_class;
+struct _CamelTestSession {
+	CamelSession parent;
+};
 
-} CamelTestSessionClass;
+struct _CamelTestSessionClass {
+	CamelSessionClass parent_class;
+};
 
-CamelType camel_test_session_get_type (void);
+GType camel_test_session_get_type (void);
 CamelSession *camel_test_session_new (const gchar *path);
+
+G_END_DECLS
diff --git a/camel/tests/lib/streams.c b/camel/tests/lib/streams.c
index cc1e5d1..d4916ac 100644
--- a/camel/tests/lib/streams.c
+++ b/camel/tests/lib/streams.c
@@ -151,7 +151,7 @@ test_seekable_substream_writepart(CamelStream *s, gint type)
 		len = (ss->bound_end-ss->bound_start) % sizeof(teststring);
 		check(camel_stream_write(s, teststring, len) == len);
 		check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_end);
-		if (type == 0) {
+		if (G_UNLIKELY (type == G_TYPE_INVALID)) {
 			check(camel_stream_write(s, teststring, sizeof(teststring)) == 0);
 			check(camel_stream_eos(s));
 			check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_end);
diff --git a/camel/tests/message/test1.c b/camel/tests/message/test1.c
index 333d177..e4c2ac6 100644
--- a/camel/tests/message/test1.c
+++ b/camel/tests/message/test1.c
@@ -130,7 +130,7 @@ gint main(gint argc, gchar **argv)
 			pull();
 
 			push("compare original content");
-			test_message_compare_content(camel_medium_get_content_object((CamelMedium *)msg), text, len);
+			test_message_compare_content(camel_medium_get_content((CamelMedium *)msg), text, len);
 			pull();
 
 			push("save message to test1.msg");
@@ -144,7 +144,7 @@ gint main(gint argc, gchar **argv)
 			pull();
 
 			push("compare read with original content");
-			test_message_compare_content(camel_medium_get_content_object((CamelMedium *)msg2), text, len);
+			test_message_compare_content(camel_medium_get_content((CamelMedium *)msg2), text, len);
 			check_unref(msg2, 1);
 			pull();
 
@@ -183,7 +183,7 @@ gint main(gint argc, gchar **argv)
 			pull();
 
 			push("compare read with original content");
-			test_message_compare_content(camel_medium_get_content_object((CamelMedium *)msg2), text, len);
+			test_message_compare_content(camel_medium_get_content((CamelMedium *)msg2), text, len);
 			check_unref(msg2, 1);
 			pull();
 
diff --git a/camel/tests/message/test3.c b/camel/tests/message/test3.c
index 92f512d..e1ca811 100644
--- a/camel/tests/message/test3.c
+++ b/camel/tests/message/test3.c
@@ -33,7 +33,7 @@ gint main(gint argc, gchar **argv)
 	camel_multipart_set_boundary(mp, "_=,.XYZ_Kangaroo_Meat_is_!_ABADF00D");
 	check(strcmp(camel_multipart_get_boundary(mp), "_=,.XYZ_Kangaroo_Meat_is_!_ABADF00D") == 0);
 
-	camel_medium_set_content_object((CamelMedium *)msg, (CamelDataWrapper *)mp);
+	camel_medium_set_content ((CamelMedium *)msg, (CamelDataWrapper *)mp);
 	check(camel_multipart_get_number(mp) == 0);
 	check(camel_multipart_get_part(mp, 0) == NULL);
 	check(camel_multipart_get_part(mp, 1) == NULL);
@@ -105,7 +105,7 @@ gint main(gint argc, gchar **argv)
 	pull();
 
 	push("compre content of multipart");
-	mp2 = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)msg2);
+	mp2 = (CamelMultipart *)camel_medium_get_content((CamelMedium *)msg2);
 	check(mp2 != NULL);
 	check(CAMEL_IS_MULTIPART(mp2));
 	check(camel_multipart_get_number(mp2) == 3);
@@ -118,11 +118,11 @@ gint main(gint argc, gchar **argv)
 	check_msg(mp2->postface == NULL || strlen(mp2->postface) == 0, "postface: '%s'", mp2->postface);
 	camel_test_fatal();
 
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 0))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 0))),
 				     "content part 1", strlen("content part 1"));
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 1))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 1))),
 				     "content part 3", strlen("content part 3"));
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 2))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 2))),
 				     "content part 2", strlen("content part 2"));
 	pull();
 
@@ -132,7 +132,7 @@ gint main(gint argc, gchar **argv)
 	msg3 = test_message_read_file("test3-2.msg");
 
 	push("comparing again");
-	mp2 = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)msg3);
+	mp2 = (CamelMultipart *)camel_medium_get_content((CamelMedium *)msg3);
 	check(mp2 != NULL);
 	check(CAMEL_IS_MULTIPART(mp2));
 	check(camel_multipart_get_number(mp2) == 3);
@@ -142,11 +142,11 @@ gint main(gint argc, gchar **argv)
 
 	check_msg(mp2->postface == NULL || strlen(mp2->postface) == 0, "postface: '%s'", mp2->postface);
 
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 0))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 0))),
 				     "content part 1", strlen("content part 1"));
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 1))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 1))),
 				     "content part 3", strlen("content part 3"));
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 2))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 2))),
 				     "content part 2", strlen("content part 2"));
 	pull();
 	pull();
@@ -166,7 +166,7 @@ gint main(gint argc, gchar **argv)
 	test_message_write_file(msg, "test3-3.msg");
 	msg2 = test_message_read_file("test3-3.msg");
 
-	mp2 = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)msg2);
+	mp2 = (CamelMultipart *)camel_medium_get_content((CamelMedium *)msg2);
 	check(mp2 != NULL);
 	check(CAMEL_IS_MULTIPART(mp2));
 	check(camel_multipart_get_number(mp2) == 3);
@@ -174,11 +174,11 @@ gint main(gint argc, gchar **argv)
 	check(strcmp(camel_multipart_get_boundary(mp2), "_=,.XYZ_Kangaroo_Meat_is_!_ABADF00D") == 0);
 	check(mp2->preface && strcmp(mp2->preface, "pre-text\nLines.") == 0);
 	check(mp2->postface && strcmp(mp2->postface, "post-text, no lines.\nOne line.\n") == 0);
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 0))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 0))),
 					   "content part 1", strlen("content part 1"));
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 1))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 1))),
 				     "content part 3", strlen("content part 3"));
-	test_message_compare_content(camel_medium_get_content_object(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 2))),
+	test_message_compare_content(camel_medium_get_content(CAMEL_MEDIUM(camel_multipart_get_part(mp2, 2))),
 				     "content part 2", strlen("content part 2"));
 	pull();
 	check_unref(msg2, 1);
diff --git a/camel/tests/message/test4.c b/camel/tests/message/test4.c
index 3b21070..432bb30 100644
--- a/camel/tests/message/test4.c
+++ b/camel/tests/message/test4.c
@@ -48,7 +48,7 @@ dump_mime_struct (CamelMimePart *mime_part, gint depth)
 		i++;
 	}
 
-	content = camel_medium_get_content_object ((CamelMedium *) mime_part);
+	content = camel_medium_get_content ((CamelMedium *) mime_part);
 
 	mime_type = camel_data_wrapper_get_mime_type (content);
 	printf ("Content-Type: %s\n", mime_type);
@@ -113,8 +113,8 @@ gint main (gint argc, gchar **argv)
 		/*dump_mime_struct ((CamelMimePart *) message, 0);*/
 		test_message_compare (message);
 
-		camel_object_unref (message);
-		camel_object_unref (stream);
+		g_object_unref (message);
+		g_object_unref (stream);
 
 		pull ();
 	}
diff --git a/camel/tests/mime-filter/test-charset.c b/camel/tests/mime-filter/test-charset.c
index 60aaffb..644807e 100644
--- a/camel/tests/mime-filter/test-charset.c
+++ b/camel/tests/mime-filter/test-charset.c
@@ -68,7 +68,7 @@ main (gint argc, gchar **argv)
 		}
 		g_free (outfile);
 
-		if (!(filter = camel_stream_filter_new_with_stream (CAMEL_STREAM (source)))) {
+		if (!(filter = camel_stream_filter_new (CAMEL_STREAM (source)))) {
 			camel_test_fail ("Couldn't create CamelStreamFilter??");
 			continue;
 		}
@@ -77,7 +77,7 @@ main (gint argc, gchar **argv)
 		ext = strchr (charset, '.');
 		*((gchar *) ext) = '\0';
 
-		if (!(f = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "UTF-8"))) {
+		if (!(f = camel_mime_filter_charset_new (charset, "UTF-8"))) {
 			camel_test_fail ("Couldn't create CamelMimeFilterCharset??");
 			g_free (charset);
 			continue;
@@ -85,7 +85,7 @@ main (gint argc, gchar **argv)
 		g_free (charset);
 
 		camel_stream_filter_add (filter, f);
-		camel_object_unref (f);
+		g_object_unref (f);
 
 		camel_test_push ("Running filter and comparing to correct result");
 
@@ -131,9 +131,9 @@ main (gint argc, gchar **argv)
 
 		/* inefficient */
 		camel_test_push ("Cleaning up");
-		camel_object_unref (CAMEL_OBJECT (filter));
-		camel_object_unref (CAMEL_OBJECT (correct));
-		camel_object_unref (CAMEL_OBJECT (source));
+		g_object_unref (CAMEL_OBJECT (filter));
+		g_object_unref (CAMEL_OBJECT (correct));
+		g_object_unref (CAMEL_OBJECT (source));
 		camel_test_pull ();
 
 		camel_test_end ();
diff --git a/camel/tests/mime-filter/test-crlf.c b/camel/tests/mime-filter/test-crlf.c
index e87a1a6..954733b 100644
--- a/camel/tests/mime-filter/test-crlf.c
+++ b/camel/tests/mime-filter/test-crlf.c
@@ -85,7 +85,7 @@ main (gint argc, gchar **argv)
 			}
 			g_free (outfile);
 
-			filter = camel_stream_filter_new_with_stream (CAMEL_STREAM (source));
+			filter = camel_stream_filter_new (CAMEL_STREAM (source));
 			if (!filter) {
 				camel_test_fail ("Couldn't create CamelStreamFilter??");
 				continue;
@@ -144,10 +144,10 @@ main (gint argc, gchar **argv)
 
 			/* inefficient */
 			camel_test_push ("Cleaning up");
-			camel_object_unref (CAMEL_OBJECT (filter));
-			camel_object_unref (CAMEL_OBJECT (correct));
-			camel_object_unref (CAMEL_OBJECT (source));
-			camel_object_unref (CAMEL_OBJECT (sh));
+			g_object_unref (CAMEL_OBJECT (filter));
+			g_object_unref (CAMEL_OBJECT (correct));
+			g_object_unref (CAMEL_OBJECT (source));
+			g_object_unref (CAMEL_OBJECT (sh));
 			camel_test_pull ();
 
 			camel_test_pull ();
diff --git a/camel/tests/mime-filter/test-tohtml.c b/camel/tests/mime-filter/test-tohtml.c
index 2495a95..4ae6a14 100644
--- a/camel/tests/mime-filter/test-tohtml.c
+++ b/camel/tests/mime-filter/test-tohtml.c
@@ -48,7 +48,7 @@ test_filter(CamelMimeFilter *f, const gchar *inname, const gchar *outname)
 
 	in = (CamelStreamMem *)camel_stream_mem_new();
 
-	filter = (CamelStream *)camel_stream_filter_new_with_stream(indisk);
+	filter = camel_stream_filter_new (indisk);
 	check_count(indisk, 2);
 	id = camel_stream_filter_add((CamelStreamFilter *)filter, f);
 	check_count(f, 2);
@@ -75,7 +75,7 @@ test_filter(CamelMimeFilter *f, const gchar *inname, const gchar *outname)
 	camel_test_push("writing through filter stream");
 
 	in = (CamelStreamMem *)camel_stream_mem_new();
-	filter = (CamelStream *)camel_stream_filter_new_with_stream((CamelStream *)in);
+	filter = camel_stream_filter_new ((CamelStream *)in);
 	check_count(in, 2);
 	id = camel_stream_filter_add((CamelStreamFilter *)filter, f);
 	check_count(f, 2);
diff --git a/camel/tests/mime-filter/test1.c b/camel/tests/mime-filter/test1.c
index 93bfb9e..e3506f5 100644
--- a/camel/tests/mime-filter/test1.c
+++ b/camel/tests/mime-filter/test1.c
@@ -77,7 +77,7 @@ main (gint argc, gchar **argv)
 			camel_test_push("Chunk size %d\n", step);
 
 			out = (CamelStreamMem *)camel_stream_mem_new();
-			filter = camel_stream_filter_new_with_stream((CamelStream *)out);
+			filter = camel_stream_filter_new ((CamelStream *)out);
 			sh = camel_mime_filter_canon_new(tests[i].flags);
 			check(camel_stream_filter_add(filter, sh) != -1);
 			check_unref(sh, 2);
diff --git a/camel/tests/misc/split.c b/camel/tests/misc/split.c
index fd78a27..f459248 100644
--- a/camel/tests/misc/split.c
+++ b/camel/tests/misc/split.c
@@ -4,7 +4,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib.h>
 #include <libedataserver/e-sexp.h>
 #include <camel/camel-exception.h>
 #include <camel/camel-search-private.h>
diff --git a/camel/tests/misc/utf7.c b/camel/tests/misc/utf7.c
index 45d8d7b..dfbe534 100644
--- a/camel/tests/misc/utf7.c
+++ b/camel/tests/misc/utf7.c
@@ -4,7 +4,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib.h>
 #include <camel/camel-utf8.h>
 #include <camel/camel-exception.h>
 
diff --git a/camel/tests/smime/pgp-mime.c b/camel/tests/smime/pgp-mime.c
index 8ba1603..0c5e046 100644
--- a/camel/tests/smime/pgp-mime.c
+++ b/camel/tests/smime/pgp-mime.c
@@ -42,9 +42,9 @@ static gchar test_msg[] = "Since we need to make sure that\nFrom lines work okay
 "the basics at least...\n";
 
 #define CAMEL_PGP_SESSION_TYPE     (camel_pgp_session_get_type ())
-#define CAMEL_PGP_SESSION(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_PGP_SESSION_TYPE, CamelPgpSession))
-#define CAMEL_PGP_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_PGP_SESSION_TYPE, CamelPgpSessionClass))
-#define CAMEL_PGP_IS_SESSION(o)    (CAMEL_CHECK_TYPE((o), CAMEL_PGP_SESSION_TYPE))
+#define CAMEL_PGP_SESSION(obj)     (G_TYPE_CHECK_INSTANCE_CAST((obj), CAMEL_PGP_SESSION_TYPE, CamelPgpSession))
+#define CAMEL_PGP_SESSION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), CAMEL_PGP_SESSION_TYPE, CamelPgpSessionClass))
+#define CAMEL_PGP_IS_SESSION(o)    (G_TYPE_CHECK_INSTANCE_TYPE((o), CAMEL_PGP_SESSION_TYPE))
 
 typedef struct _CamelPgpSession {
 	CamelSession parent_object;
@@ -73,26 +73,24 @@ class_init (CamelPgpSessionClass *camel_pgp_session_class)
 	CamelSessionClass *camel_session_class =
 		CAMEL_SESSION_CLASS (camel_pgp_session_class);
 
-	/* virtual method override */
 	camel_session_class->get_password = get_password;
 }
 
-static CamelType
+static GType
 camel_pgp_session_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (type == CAMEL_INVALID_TYPE) {
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
 		type = camel_type_register (
-			camel_test_session_get_type (),
+			CAMEL_TYPE_TEST_SESSION,
 			"CamelPgpSession",
 			sizeof (CamelPgpSession),
 			sizeof (CamelPgpSessionClass),
-			(CamelObjectClassInitFunc) class_init,
+			(GClassInitFunc) class_init,
 			NULL,
-			(CamelObjectInitFunc) init,
+			(GInstanceInitFunc) init,
 			NULL);
-	}
 
 	return type;
 }
@@ -109,8 +107,7 @@ camel_pgp_session_new (const gchar *path)
 {
 	CamelSession *session;
 
-	session = CAMEL_SESSION (camel_object_new (CAMEL_PGP_SESSION_TYPE));
-
+	session = g_object_new (CAMEL_TYPE_PGP_SESSION, NULL);
 	camel_session_construct (session, path);
 
 	return session;
@@ -163,7 +160,7 @@ gint main (gint argc, gchar **argv)
 	check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex));
 	camel_test_pull ();
 
-	camel_object_unref (mime_part);
+	g_object_unref (mime_part);
 	camel_exception_clear (ex);
 
 	camel_test_push ("PGP/MIME verify");
@@ -173,7 +170,7 @@ gint main (gint argc, gchar **argv)
 	camel_cipher_validity_free (valid);
 	camel_test_pull ();
 
-	camel_object_unref (mps);
+	g_object_unref (mps);
 	camel_exception_clear (ex);
 
 	mime_part = camel_mime_part_new ();
@@ -191,17 +188,17 @@ gint main (gint argc, gchar **argv)
 	camel_test_pull ();
 
 	camel_exception_clear (ex);
-	camel_object_unref (mime_part);
+	g_object_unref (mime_part);
 
 	camel_test_push ("PGP/MIME decrypt");
 	mime_part = camel_multipart_encrypted_decrypt (mpe, ctx, ex);
 	check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex));
-	camel_object_unref (mime_part);
-	camel_object_unref (mpe);
+	g_object_unref (mime_part);
+	g_object_unref (mpe);
 	camel_test_pull ();
 
-	camel_object_unref (CAMEL_OBJECT (ctx));
-	camel_object_unref (CAMEL_OBJECT (session));
+	g_object_unref (CAMEL_OBJECT (ctx));
+	g_object_unref (CAMEL_OBJECT (session));
 
 	camel_test_end ();
 
diff --git a/camel/tests/smime/pgp.c b/camel/tests/smime/pgp.c
index 5585a71..f184802 100644
--- a/camel/tests/smime/pgp.c
+++ b/camel/tests/smime/pgp.c
@@ -36,9 +36,9 @@
 #include "session.h"
 
 #define CAMEL_PGP_SESSION_TYPE     (camel_pgp_session_get_type ())
-#define CAMEL_PGP_SESSION(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_PGP_SESSION_TYPE, CamelPgpSession))
-#define CAMEL_PGP_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_PGP_SESSION_TYPE, CamelPgpSessionClass))
-#define CAMEL_PGP_IS_SESSION(o)    (CAMEL_CHECK_TYPE((o), CAMEL_PGP_SESSION_TYPE))
+#define CAMEL_PGP_SESSION(obj)     (G_TYPE_CHECK_INSTANCE_CAST((obj), CAMEL_PGP_SESSION_TYPE, CamelPgpSession))
+#define CAMEL_PGP_SESSION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), CAMEL_PGP_SESSION_TYPE, CamelPgpSessionClass))
+#define CAMEL_PGP_IS_SESSION(o)    (G_TYPE_CHECK_INSTANCE_TYPE((o), CAMEL_PGP_SESSION_TYPE))
 
 typedef struct _CamelPgpSession {
 	CamelSession parent_object;
@@ -67,26 +67,24 @@ class_init (CamelPgpSessionClass *camel_pgp_session_class)
 	CamelSessionClass *camel_session_class =
 		CAMEL_SESSION_CLASS (camel_pgp_session_class);
 
-	/* virtual method override */
 	camel_session_class->get_password = get_password;
 }
 
-static CamelType
+static GType
 camel_pgp_session_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (type == CAMEL_INVALID_TYPE) {
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
 		type = camel_type_register (
 			camel_test_session_get_type (),
 			"CamelPgpSession",
 			sizeof (CamelPgpSession),
 			sizeof (CamelPgpSessionClass),
-			(CamelObjectClassInitFunc) class_init,
+			(GClassInitFunc) class_init,
 			NULL,
-			(CamelObjectInitFunc) init,
+			(GInstanceInitFunc) init,
 			NULL);
-	}
 
 	return type;
 }
@@ -103,8 +101,7 @@ camel_pgp_session_new (const gchar *path)
 {
 	CamelSession *session;
 
-	session = CAMEL_SESSION (camel_object_new (CAMEL_PGP_SESSION_TYPE));
-
+	session = g_object_new (CAMEL_TYPE_PGP_SESSION, NULL);
 	camel_session_construct (session, path);
 
 	return session;
@@ -161,9 +158,9 @@ gint main (gint argc, gchar **argv)
 	conpart = camel_mime_part_new();
 	dw = camel_data_wrapper_new();
 	camel_data_wrapper_construct_from_stream(dw, stream1);
-	camel_medium_set_content_object((CamelMedium *)conpart, dw);
-	camel_object_unref(stream1);
-	camel_object_unref(dw);
+	camel_medium_set_content((CamelMedium *)conpart, dw);
+	g_object_unref (stream1);
+	g_object_unref (dw);
 
 	sigpart = camel_mime_part_new();
 
@@ -185,8 +182,8 @@ gint main (gint argc, gchar **argv)
 	camel_cipher_validity_free (valid);
 	camel_test_pull ();
 
-	camel_object_unref(conpart);
-	camel_object_unref(sigpart);
+	g_object_unref (conpart);
+	g_object_unref (sigpart);
 
 	stream1 = camel_stream_mem_new ();
 	camel_stream_write (stream1, "Hello, I am a test of encryption/decryption.", 44);
@@ -196,9 +193,9 @@ gint main (gint argc, gchar **argv)
 	dw = camel_data_wrapper_new();
 	camel_stream_reset(stream1);
 	camel_data_wrapper_construct_from_stream(dw, stream1);
-	camel_medium_set_content_object((CamelMedium *)conpart, dw);
-	camel_object_unref(stream1);
-	camel_object_unref(dw);
+	camel_medium_set_content((CamelMedium *)conpart, dw);
+	g_object_unref (stream1);
+	g_object_unref (dw);
 
 	encpart = camel_mime_part_new();
 
@@ -234,16 +231,16 @@ gint main (gint argc, gchar **argv)
 	g_free (before);
 	g_free (after);
 
-	camel_object_unref(stream1);
-	camel_object_unref(stream2);
-	camel_object_unref(conpart);
-	camel_object_unref(encpart);
-	camel_object_unref(outpart);
+	g_object_unref (stream1);
+	g_object_unref (stream2);
+	g_object_unref (conpart);
+	g_object_unref (encpart);
+	g_object_unref (outpart);
 
 	camel_test_pull ();
 
-	camel_object_unref (CAMEL_OBJECT (ctx));
-	camel_object_unref (CAMEL_OBJECT (session));
+	g_object_unref (CAMEL_OBJECT (ctx));
+	g_object_unref (CAMEL_OBJECT (session));
 
 	camel_test_end ();
 
diff --git a/camel/tests/smime/pkcs7.c b/camel/tests/smime/pkcs7.c
index ca9f270..2ab2513 100644
--- a/camel/tests/smime/pkcs7.c
+++ b/camel/tests/smime/pkcs7.c
@@ -9,9 +9,9 @@
 #include "camel-test.h"
 
 #define CAMEL_TEST_SESSION_TYPE     (camel_test_session_get_type ())
-#define CAMEL_TEST_SESSION(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_TEST_SESSION_TYPE, CamelTestSession))
-#define CAMEL_TEST_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TEST_SESSION_TYPE, CamelTestSessionClass))
-#define CAMEL_TEST_IS_SESSION(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TEST_SESSION_TYPE))
+#define CAMEL_TEST_SESSION(obj)     (G_TYPE_CHECK_INSTANCE_CAST((obj), CAMEL_TEST_SESSION_TYPE, CamelTestSession))
+#define CAMEL_TEST_SESSION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), CAMEL_TEST_SESSION_TYPE, CamelTestSessionClass))
+#define CAMEL_TEST_IS_SESSION(o)    (G_TYPE_CHECK_INSTANCE_TYPE((o), CAMEL_TEST_SESSION_TYPE))
 
 typedef struct _CamelTestSession {
 	CamelSession parent_object;
@@ -39,26 +39,24 @@ class_init (CamelTestSessionClass *camel_test_session_class)
 	CamelSessionClass *camel_session_class =
 		CAMEL_SESSION_CLASS (camel_test_session_class);
 
-	/* virtual method override */
 	camel_session_class->get_password = get_password;
 }
 
-static CamelType
+static GType
 camel_test_session_get_type (void)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	static GType type = G_TYPE_INVALID;
 
-	if (type == CAMEL_INVALID_TYPE) {
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
 		type = camel_type_register (
-			camel_test_session_get_type (),
+			CAMEL_TEST_SESSION_TYPE,
 			"CamelTestSession",
 			sizeof (CamelTestSession),
 			sizeof (CamelTestSessionClass),
-			(CamelObjectClassInitFunc) class_init,
+			(GClassInitFunc) class_init,
 			NULL,
-			(CamelObjectInitFunc) init,
+			(GInstanceInitFunc) init,
 			NULL);
-	}
 
 	return type;
 }
@@ -75,8 +73,7 @@ camel_test_session_new (const gchar *path)
 {
 	CamelSession *session;
 
-	session = CAMEL_SESSION (camel_object_new (CAMEL_TEST_SESSION_TYPE));
-
+	session = g_object_new (CAMEL_TYPE_TEST_SESSION, NULL);
 	camel_session_construct (session, path);
 
 	return session;
@@ -129,8 +126,8 @@ gint main (gint argc, gchar **argv)
 	camel_cipher_validity_free (valid);
 	camel_test_pull ();
 
-	camel_object_unref (CAMEL_OBJECT (stream1));
-	camel_object_unref (CAMEL_OBJECT (stream2));
+	g_object_unref (CAMEL_OBJECT (stream1));
+	g_object_unref (CAMEL_OBJECT (stream2));
 
 	stream1 = camel_stream_mem_new ();
 	stream2 = camel_stream_mem_new ();
@@ -165,8 +162,8 @@ gint main (gint argc, gchar **argv)
 	g_free (after);
 	camel_test_pull ();
 
-	camel_object_unref (CAMEL_OBJECT (ctx));
-	camel_object_unref (CAMEL_OBJECT (session));
+	g_object_unref (CAMEL_OBJECT (ctx));
+	g_object_unref (CAMEL_OBJECT (session));
 
 	camel_test_end ();
 
diff --git a/docs/reference/camel/Makefile.am b/docs/reference/camel/Makefile.am
index cec7d65..c629021 100644
--- a/docs/reference/camel/Makefile.am
+++ b/docs/reference/camel/Makefile.am
@@ -14,7 +14,7 @@ HTML_DIR = $(datadir)/gtk-doc/html
 SCAN_OPTIONS = --deprecated-guards="CAMEL_DISABLE_DEPRECATED"
 
 # Extra options to pass to gtkdoc-scangobj
-SCANGOBJ_OPTIONS=--type-init-func="camel_init (\".\", 0)"
+SCANGOBJ_OPTIONS = --type-init-func="g_thread_init (NULL); g_type_init ()"
 
 # Extra options to supply to gtkdoc-mkdb
 MKDB_OPTIONS = --sgml-mode --output-format=xml --ignore-files=trio
@@ -26,8 +26,9 @@ GTKDOC_CFLAGS = 		\
 	-I$(top_builddir)/camel	\
 	$(GLIB_CFLAGS)
 
-GTKDOC_LIBS = 					\
-	$(top_builddir)/camel/libcamel-2.0.la	\
+GTKDOC_LIBS = 						\
+	$(top_builddir)/camel/libcamel-1.2.la		\
+	$(top_builddir)/camel/libcamel-provider-1.2.la	\
 	$(GLIB_LIBS)
 
 # Extra SGML files that are included by $(DOC_MAIN_SGML_FILE)
diff --git a/docs/reference/camel/camel-docs.sgml b/docs/reference/camel/camel-docs.sgml
index ca14144..feaca86 100644
--- a/docs/reference/camel/camel-docs.sgml
+++ b/docs/reference/camel/camel-docs.sgml
@@ -117,7 +117,6 @@
 <!ENTITY CamelVeeStore SYSTEM "xml/camel-vee-store.xml">
 <!ENTITY CamelVeeSummary SYSTEM "xml/camel-vee-summary.xml">
 <!ENTITY CamelVTrashFolder SYSTEM "xml/camel-vtrash-folder.xml">
-
 <!ENTITY index-Class-Tree SYSTEM "tree_index.sgml">
 ]>
 
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index 49e5ad0..0033a34 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -15,9 +15,13 @@ camel_address_remove
 <SUBSECTION Standard>
 CAMEL_ADDRESS
 CAMEL_IS_ADDRESS
+CAMEL_TYPE_ADDRESS
 CAMEL_ADDRESS_CLASS
+CAMEL_IS_ADDRESS_CLASS
+CAMEL_ADDRESS_GET_CLASS
 CamelAddressClass
 <SUBSECTION Private>
+CamelAddressPrivate
 camel_address_get_type
 </SECTION>
 
@@ -54,9 +58,17 @@ camel_key_file_delete
 camel_key_file_write
 camel_key_file_read
 <SUBSECTION Standard>
+CAMEL_BLOCK_FILE
+CAMEL_IS_BLOCK_FILE
+CAMEL_TYPE_BLOCK_FILE
+CAMEL_BLOCK_FILE_CLASS
+CAMEL_IS_BLOCK_FILE_CLASS
+CAMEL_BLOCK_FILE_GET_CLASS
 CamelBlockFileClass
 CamelKeyFileClass
 <SUBSECTION Private>
+CamelBlockFilePrivate
+CamelKeyFilePrivate
 camel_block_file_get_type
 camel_key_file_get_type
 </SECTION>
@@ -96,10 +108,13 @@ camel_cert_set_trust
 <SUBSECTION Standard>
 CAMEL_CERTDB
 CAMEL_IS_CERTDB
-CAMEL_CERTDB_TYPE
+CAMEL_TYPE_CERTDB
 CAMEL_CERTDB_CLASS
+CAMEL_IS_CERTDB_CLASS
+CAMEL_CERTDB_GET_CLASS
 CamelCertDBClass
 <SUBSECTION Private>
+CamelCertDBPrivate
 camel_certdb_get_type
 </SECTION>
 
@@ -114,7 +129,7 @@ camel_cipher_validity_sign_t
 camel_cipher_validity_encrypt_t
 camel_cipher_validity_mode_t
 camel_cipher_context_new
-camel_cipher_context_construct
+camel_cipher_context_get_session
 camel_cipher_id_to_hash
 camel_cipher_hash_to_id
 camel_cipher_sign
@@ -139,10 +154,13 @@ camel_cipher_canonical_to_stream
 <SUBSECTION Standard>
 CAMEL_CIPHER_CONTEXT
 CAMEL_IS_CIPHER_CONTEXT
-CAMEL_CIPHER_CONTEXT_TYPE
+CAMEL_TYPE_CIPHER_CONTEXT
 CAMEL_CIPHER_CONTEXT_CLASS
+CAMEL_IS_CIPHER_CONTEXT_CLASS
+CAMEL_CIPHER_CONTEXT_GET_CLASS
 CamelCipherContextClass
 <SUBSECTION Private>
+CamelCipherContextPrivate
 camel_cipher_context_get_type
 </SECTION>
 
@@ -151,6 +169,8 @@ camel_cipher_context_get_type
 <TITLE>CamelDataCache</TITLE>
 CamelDataCache
 camel_data_cache_new
+camel_data_cache_get_path
+camel_data_cache_set_path
 camel_data_cache_set_expire_age
 camel_data_cache_set_expire_access
 camel_data_cache_rename
@@ -162,10 +182,13 @@ camel_data_cache_get_filename
 <SUBSECTION Standard>
 CAMEL_DATA_CACHE
 CAMEL_IS_DATA_CACHE
-CAMEL_DATA_CACHE_TYPE
+CAMEL_TYPE_DATA_CACHE
 CAMEL_DATA_CACHE_CLASS
+CAMEL_IS_DATA_CACHE_CLASS
+CAMEL_DATA_CACHE_GET_CLASS
 CamelDataCacheClass
 <SUBSECTION Private>
+CamelDataCachePrivate
 camel_data_cache_get_type
 </SECTION>
 
@@ -185,10 +208,13 @@ camel_data_wrapper_is_offline
 <SUBSECTION Standard>
 CAMEL_DATA_WRAPPER
 CAMEL_IS_DATA_WRAPPER
-CAMEL_DATA_WRAPPER_TYPE
+CAMEL_TYPE_DATA_WRAPPER
 CAMEL_DATA_WRAPPER_CLASS
+CAMEL_IS_DATA_WRAPPER_CLASS
+CAMEL_DATA_WRAPPER_GET_CLASS
 CamelDataWrapperClass
 <SUBSECTION Private>
+CamelDataWrapperPrivate
 camel_data_wrapper_get_type
 </SECTION>
 
@@ -274,9 +300,13 @@ camel_digest_folder_new
 <SUBSECTION Standard>
 CAMEL_DIGEST_FOLDER
 CAMEL_IS_DIGEST_FOLDER
+CAMEL_TYPE_DIGEST_FOLDER
 CAMEL_DIGEST_FOLDER_CLASS
+CAMEL_IS_DIGEST_FOLDER_CLASS
+CAMEL_DIGEST_FOLDER_GET_CLASS
 CamelDigestFolderClass
 <SUBSECTION Private>
+CamelDigestFolderPrivate
 camel_digest_folder_get_type
 </SECTION>
 
@@ -288,7 +318,10 @@ camel_digest_store_new
 <SUBSECTION Standard>
 CAMEL_DIGEST_STORE
 CAMEL_IS_DIGEST_STORE
+CAMEL_TYPE_DIGEST_STORE
 CAMEL_DIGEST_STORE_CLASS
+CAMEL_IS_DIGEST_STORE_CLASS
+CAMEL_DIGEST_STORE_GET_CLASS
 CamelDigestStoreClass
 <SUBSECTION Private>
 camel_digest_store_get_type
@@ -302,7 +335,10 @@ camel_digest_summary_new
 <SUBSECTION Standard>
 CAMEL_DIGEST_SUMMARY
 CAMEL_IS_DIGEST_SUMMARY
+CAMEL_TYPE_DIGEST_SUMMARY
 CAMEL_DIGEST_SUMMARY_CLASS
+CAMEL_IS_DIGEST_SUMMARY_CLASS
+CAMEL_DIGEST_SUMMARY_GET_CLASS
 CamelDigestSummaryClass
 <SUBSECTION Private>
 camel_digest_summary_get_type
@@ -323,8 +359,10 @@ camel_disco_diary_uidmap_lookup
 <SUBSECTION Standard>
 CAMEL_DISCO_DIARY
 CAMEL_IS_DISCO_DIARY
-CAMEL_DISCO_DIARY_TYPE
+CAMEL_TYPE_DISCO_DIARY
 CAMEL_DISCO_DIARY_CLASS
+CAMEL_IS_DISCO_DIARY_CLASS
+CAMEL_DISCO_DIARY_GET_CLASS
 CamelDiscoDiaryClass
 <SUBSECTION Private>
 camel_disco_diary_get_type
@@ -340,14 +378,38 @@ camel_disco_folder_prepare_for_offline
 <SUBSECTION Standard>
 CAMEL_DISCO_FOLDER
 CAMEL_IS_DISCO_FOLDER
-CAMEL_DISCO_FOLDER_TYPE
+CAMEL_TYPE_DISCO_FOLDER
 CAMEL_DISCO_FOLDER_CLASS
+CAMEL_IS_DISCO_FOLDER_CLASS
+CAMEL_DISCO_FOLDER_GET_CLASS
 CamelDiscoFolderClass
 <SUBSECTION Private>
 camel_disco_folder_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-disco-store</FILE>
+<TITLE>CamelDiscoStore</TITLE>
+CamelDiscoStore
+CamelDiscoStoreStatus
+camel_disco_store_status
+camel_disco_store_set_status
+camel_disco_store_can_work_offline
+camel_disco_store_check_online
+camel_disco_store_prepare_for_offline
+<SUBSECTION Standard>
+CAMEL_DISCO_STORE
+CAMEL_IS_DISCO_STORE
+CAMEL_TYPE_DISCO_STORE
+CAMEL_DISCO_STORE_CLASS
+CAMEL_IS_DISCO_STORE_CLASS
+CAMEL_DISCO_STORE_GET_CLASS
+CamelDiscoStoreClass
+<SUBSECTION Private>
+camel_disco_store_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-filter-driver</FILE>
 <TITLE>CamelFilterDriver</TITLE>
 CamelFilterDriver
@@ -372,10 +434,13 @@ camel_filter_driver_rule_get
 <SUBSECTION Standard>
 CAMEL_FILTER_DRIVER
 CAMEL_IS_FILTER_DRIVER
-CAMEL_FILTER_DRIVER_TYPE
+CAMEL_TYPE_FILTER_DRIVER
 CAMEL_FILTER_DRIVER_CLASS
+CAMEL_IS_FILTER_DRIVER_CLASS
+CAMEL_FILTER_DRIVER_GET_CLASS
 CamelFilterDriverClass
 <SUBSECTION Private>
+CamelFilterDriverPrivate
 camel_filter_driver_get_type
 </SECTION>
 
@@ -460,10 +525,13 @@ camel_folder_change_info_recent_uid
 <SUBSECTION Standard>
 CAMEL_FOLDER
 CAMEL_IS_FOLDER
-CAMEL_FOLDER_TYPE
+CAMEL_TYPE_FOLDER
 CAMEL_FOLDER_CLASS
+CAMEL_IS_FOLDER_CLASS
+CAMEL_FOLDER_GET_CLASS
 CamelFolderClass
 <SUBSECTION Private>
+CamelFolderPrivate
 camel_folder_get_type
 </SECTION>
 
@@ -483,10 +551,13 @@ camel_folder_search_free_result
 <SUBSECTION Standard>
 CAMEL_FOLDER_SEARCH
 CAMEL_IS_FOLDER_SEARCH
-CAMEL_FOLDER_SEARCH_TYPE
+CAMEL_TYPE_FOLDER_SEARCH
 CAMEL_FOLDER_SEARCH_CLASS
+CAMEL_IS_FOLDER_SEARCH_CLASS
+CAMEL_FOLDER_SEARCH_GET_CLASS
 CamelFolderSearchClass
 <SUBSECTION Private>
+CamelFolderSearchPrivate
 camel_folder_search_get_type
 </SECTION>
 
@@ -605,10 +676,13 @@ camel_folder_summary_migrate_infos
 <SUBSECTION Standard>
 CAMEL_FOLDER_SUMMARY
 CAMEL_IS_FOLDER_SUMMARY
-CAMEL_FOLDER_SUMMARY_TYPE
+CAMEL_TYPE_FOLDER_SUMMARY
 CAMEL_FOLDER_SUMMARY_CLASS
+CAMEL_IS_FOLDER_SUMMARY_CLASS
+CAMEL_FOLDER_SUMMARY_GET_CLASS
 CamelFolderSummaryClass
 <SUBSECTION Private>
+CamelFolderSummaryPrivate
 camel_folder_summary_get_type
 </SECTION>
 
@@ -617,14 +691,18 @@ camel_folder_summary_get_type
 <TITLE>CamelGpgContext</TITLE>
 CamelGpgContext
 camel_gpg_context_new
+camel_gpg_context_get_always_trust
 camel_gpg_context_set_always_trust
 <SUBSECTION Standard>
 CAMEL_GPG_CONTEXT
 CAMEL_IS_GPG_CONTEXT
-CAMEL_GPG_CONTEXT_TYPE
+CAMEL_TYPE_GPG_CONTEXT
 CAMEL_GPG_CONTEXT_CLASS
+CAMEL_IS_GPG_CONTEXT_CLASS
+CAMEL_GPG_CONTEXT_GET_CLASS
 CamelGpgContextClass
 <SUBSECTION Private>
+CamelGpgContextPrivate
 camel_gpg_context_get_type
 </SECTION>
 
@@ -643,9 +721,13 @@ camel_html_parser_attr_list
 <SUBSECTION Standard>
 CAMEL_HTML_PARSER
 CAMEL_IS_HTML_PARSER
+CAMEL_TYPE_HTML_PARSER
 CAMEL_HTML_PARSER_CLASS
+CAMEL_IS_HTML_PARSER_CLASS
+CAMEL_HTML_PARSER_GET_CLASS
 CamelHTMLParserClass
 <SUBSECTION Private>
+CamelHTMLParserPrivate
 camel_html_parser_get_type
 </SECTION>
 
@@ -663,8 +745,10 @@ camel_http_stream_get_content_type
 <SUBSECTION Standard>
 CAMEL_HTTP_STREAM
 CAMEL_IS_HTTP_STREAM
-CAMEL_HTTP_STREAM_TYPE
+CAMEL_TYPE_HTTP_STREAM
 CAMEL_HTTP_STREAM_CLASS
+CAMEL_IS_HTTP_STREAM_CLASS
+CAMEL_HTTP_STREAM_GET_CLASS
 CamelHttpStreamClass
 <SUBSECTION Private>
 camel_http_stream_get_type
@@ -704,20 +788,31 @@ camel_index_names
 <SUBSECTION Standard>
 CAMEL_INDEX
 CAMEL_IS_INDEX
-camel_index_get_type
+CAMEL_TYPE_INDEX
 CAMEL_INDEX_CLASS
-CAMEL_INDEX_NAME
-CAMEL_IS_INDEX_NAME
-camel_index_name_get_type
-CAMEL_INDEX_NAME_CLASS
+CAMEL_IS_INDEX_CLASS
+CAMEL_INDEX_GET_CLASS
 CAMEL_INDEX_CURSOR
 CAMEL_IS_INDEX_CURSOR
-camel_index_cursor_get_type
+CAMEL_TYPE_INDEX_CURSOR
 CAMEL_INDEX_CURSOR_CLASS
+CAMEL_IS_INDEX_CURSOR_CLASS
+CAMEL_INDEX_CURSOR_GET_CLASS
+CAMEL_INDEX_NAME
+CAMEL_IS_INDEX_NAME
+CAMEL_TYPE_INDEX_NAME
+CAMEL_INDEX_NAME_CLASS
+CAMEL_IS_INDEX_NAME_CLASS
+CAMEL_INDEX_NAME_GET_CLASS
 CamelIndexClass
 CamelIndexCursorClass
 CamelIndexNameClass
 <SUBSECTION Private>
+CamelIndexPrivate
+CamelIndexCursorPrivate
+CamelIndexNamePrivate
+camel_index_get_type
+camel_index_cursor_get_type
 camel_index_name_get_type
 </SECTION>
 
@@ -735,9 +830,13 @@ camel_internet_address_format_address
 <SUBSECTION Standard>
 CAMEL_INTERNET_ADDRESS
 CAMEL_IS_INTERNET_ADDRESS
+CAMEL_TYPE_INTERNET_ADDRESS
 CAMEL_INTERNET_ADDRESS_CLASS
+CAMEL_IS_INTERNET_ADDRESS_CLASS
+CAMEL_INTERNET_ADDRESS_GET_CLASS
 CamelInternetAddressClass
 <SUBSECTION Private>
+CamelInternetAddressPrivate
 camel_internet_address_get_type
 </SECTION>
 
@@ -752,31 +851,60 @@ camel_medium_remove_header
 camel_medium_get_header
 camel_medium_get_headers
 camel_medium_free_headers
-camel_medium_get_content_object
-camel_medium_set_content_object
+camel_medium_get_content
+camel_medium_set_content
 <SUBSECTION Standard>
 CAMEL_MEDIUM
 CAMEL_IS_MEDIUM
-CAMEL_MEDIUM_TYPE
+CAMEL_TYPE_MEDIUM
 CAMEL_MEDIUM_CLASS
+CAMEL_IS_MEDIUM_CLASS
+CAMEL_MEDIUM_GET_CLASS
 CamelMediumClass
 <SUBSECTION Private>
+CamelMediumPrivate
 camel_medium_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-mime-filter</FILE>
+<TITLE>CamelMimeFilter</TITLE>
+CamelMimeFilter
+camel_mime_filter_new
+camel_mime_filter_filter
+camel_mime_filter_complete
+camel_mime_filter_reset
+camel_mime_filter_backup
+camel_mime_filter_set_size
+<SUBSECTION Standard>
+CAMEL_MIME_FILTER
+CAMEL_IS_MIME_FILTER
+CAMEL_TYPE_MIME_FILTER
+CAMEL_MIME_FILTER_CLASS
+CAMEL_IS_MIME_FILTER_CLASS
+CAMEL_MIME_FILTER_GET_CLASS
+CamelMimeFilterClass
+<SUBSECTION Private>
+CamelMimeFilterPrivate
+camel_mime_filter_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-mime-filter-basic</FILE>
 <TITLE>CamelMimeFilterBasic</TITLE>
 CamelMimeFilterBasic
 CamelMimeFilterBasicType
 camel_mime_filter_basic_new
-camel_mime_filter_basic_new_type
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_BASIC
 CAMEL_IS_MIME_FILTER_BASIC
+CAMEL_TYPE_MIME_FILTER_BASIC
 CAMEL_MIME_FILTER_BASIC_CLASS
+CAMEL_IS_MIME_FILTER_BASIC_CLASS
+CAMEL_MIME_FILTER_BASIC_GET_CLASS
 CamelMimeFilterBasicClass
 <SUBSECTION Private>
+CamelMimeFilterBasicPrivate
 camel_mime_filter_basic_get_type
 </SECTION>
 
@@ -793,9 +921,13 @@ camel_mime_filter_bestenc_set_flags
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_BESTENC
 CAMEL_IS_MIME_FILTER_BESTENC
+CAMEL_TYPE_MIME_FILTER_BESTENC
 CAMEL_MIME_FILTER_BESTENC_CLASS
+CAMEL_IS_MIME_FILTER_BESTENC_CLASS
+CAMEL_MIME_FILTER_BESTENC_GET_CLASS
 CamelMimeFilterBestencClass
 <SUBSECTION Private>
+CamelMimeFilterBestencPrivate
 camel_mime_filter_bestenc_get_type
 </SECTION>
 
@@ -807,10 +939,13 @@ camel_mime_filter_canon_new
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_CANON
 CAMEL_IS_MIME_FILTER_CANON
-CAMEL_MIME_FILTER_CANON_TYPE
+CAMEL_TYPE_MIME_FILTER_CANON
 CAMEL_MIME_FILTER_CANON_CLASS
+CAMEL_IS_MIME_FILTER_CANON_CLASS
+CAMEL_MIME_FILTER_CANON_GET_CLASS
 CamelMimeFilterCanonClass
 <SUBSECTION Private>
+CamelMimeFilterCanonPrivate
 camel_mime_filter_canon_get_type
 </SECTION>
 
@@ -819,13 +954,16 @@ camel_mime_filter_canon_get_type
 <TITLE>CamelMimeFilterCharset</TITLE>
 CamelMimeFilterCharset
 camel_mime_filter_charset_new
-camel_mime_filter_charset_new_convert
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_CHARSET
 CAMEL_IS_MIME_FILTER_CHARSET
+CAMEL_TYPE_MIME_FILTER_CHARSET
 CAMEL_MIME_FILTER_CHARSET_CLASS
+CAMEL_IS_MIME_FILTER_CHARSET_CLASS
+CAMEL_MIME_FILTER_CHARSET_GET_CLASS
 CamelMimeFilterCharsetClass
 <SUBSECTION Private>
+CamelMimeFilterCharsetPrivate
 camel_mime_filter_charset_get_type
 </SECTION>
 
@@ -839,10 +977,13 @@ camel_mime_filter_crlf_new
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_CRLF
 CAMEL_IS_MIME_FILTER_CRLF
-CAMEL_MIME_FILTER_CRLF_TYPE
+CAMEL_TYPE_MIME_FILTER_CRLF
 CAMEL_MIME_FILTER_CRLF_CLASS
+CAMEL_IS_MIME_FILTER_CRLF_CLASS
+CAMEL_MIME_FILTER_CRLF_GET_CLASS
 CamelMimeFilterCRLFClass
 <SUBSECTION Private>
+CamelMimeFilterCRLFPrivate
 camel_mime_filter_crlf_get_type
 </SECTION>
 
@@ -858,8 +999,11 @@ CAMEL_MIME_FILTER_ENRICHED
 CAMEL_IS_MIME_FILTER_ENRICHED
 CAMEL_TYPE_MIME_FILTER_ENRICHED
 CAMEL_MIME_FILTER_ENRICHED_CLASS
+CAMEL_IS_MIME_FILTER_ENRICHED_CLASS
+CAMEL_MIME_FILTER_ENRICHED_GET_CLASS
 CamelMimeFilterEnrichedClass
 <SUBSECTION Private>
+CamelMimeFilterEnrichedPrivate
 camel_mime_filter_enriched_get_type
 </SECTION>
 
@@ -871,9 +1015,13 @@ camel_mime_filter_from_new
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_FROM
 CAMEL_IS_MIME_FILTER_FROM
+CAMEL_TYPE_MIME_FILTER_FROM
 CAMEL_MIME_FILTER_FROM_CLASS
+CAMEL_IS_MIME_FILTER_FROM_CLASS
+CAMEL_MIME_FILTER_FROM_GET_CLASS
 CamelMimeFilterFromClass
 <SUBSECTION Private>
+CamelMimeFilterFromPrivate
 camel_mime_filter_from_get_type
 </SECTION>
 
@@ -892,6 +1040,7 @@ CAMEL_IS_MIME_FILTER_GZIP_CLASS
 CAMEL_MIME_FILTER_GZIP_GET_CLASS
 CamelMimeFilterGZipClass
 <SUBSECTION Private>
+CamelMimeFilterGZipPrivate
 camel_mime_filter_gzip_get_type
 </SECTION>
 
@@ -903,9 +1052,13 @@ camel_mime_filter_html_new
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_HTML
 CAMEL_IS_MIME_FILTER_HTML
+CAMEL_TYPE_MIME_FILTER_HTML
 CAMEL_MIME_FILTER_HTML_CLASS
+CAMEL_IS_MIME_FILTER_HTML_CLASS
+CAMEL_MIME_FILTER_HTML_GET_CLASS
 CamelMimeFilterHTMLClass
 <SUBSECTION Private>
+CamelMimeFilterHTMLPrivate
 camel_mime_filter_html_get_type
 </SECTION>
 
@@ -914,15 +1067,18 @@ camel_mime_filter_html_get_type
 <TITLE>CamelMimeFilterIndex</TITLE>
 CamelMimeFilterIndex
 camel_mime_filter_index_new
-camel_mime_filter_index_new_index
 camel_mime_filter_index_set_name
 camel_mime_filter_index_set_index
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_INDEX
 CAMEL_IS_MIME_FILTER_INDEX
+CAMEL_TYPE_MIME_FILTER_INDEX
 CAMEL_MIME_FILTER_INDEX_CLASS
+CAMEL_IS_MIME_FILTER_INDEX_CLASS
+CAMEL_MIME_FILTER_INDEX_GET_CLASS
 CamelMimeFilterIndexClass
 <SUBSECTION Private>
+CamelMimeFilterIndexPrivate
 camel_mime_filter_index_get_type
 </SECTION>
 
@@ -934,10 +1090,13 @@ camel_mime_filter_linewrap_new
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_LINEWRAP
 CAMEL_IS_MIME_FILTER_LINEWRAP
-CAMEL_MIME_FILTER_LINEWRAP_TYPE
+CAMEL_TYPE_MIME_FILTER_LINEWRAP
 CAMEL_MIME_FILTER_LINEWRAP_CLASS
+CAMEL_IS_MIME_FILTER_LINEWRAP_CLASS
+CAMEL_MIME_FILTER_LINEWRAP_GET_CLASS
 CamelMimeFilterLinewrapClass
 <SUBSECTION Private>
+CamelMimeFilterLinewrapPrivate
 camel_mime_filter_linewrap_get_type
 </SECTION>
 
@@ -947,28 +1106,51 @@ camel_mime_filter_linewrap_get_type
 CamelMimeFilterPgp
 camel_mime_filter_pgp_new
 <SUBSECTION Standard>
-CAMEL_MIME_FILTER_PGP_TYPE
 CAMEL_MIME_FILTER_PGP
-CAMEL_MIME_FILTER_PGP_CLASS
 CAMEL_IS_MIME_FILTER_PGP
+CAMEL_TYPE_MIME_FILTER_PGP
+CAMEL_MIME_FILTER_PGP_CLASS
+CAMEL_IS_MIME_FILTER_PGP_CLASS
+CAMEL_MIME_FILTER_PGP_GET_CLASS
 CamelMimeFilterPgpClass
 <SUBSECTION Private>
+CamelMimeFilterPgpPrivate
 camel_mime_filter_pgp_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-mime-filter-progress</FILE>
+<TITLE>CamelMimeFilterProgress</TITLE>
+CamelMimeFilterProgress
+camel_mime_filter_progress_new
+<SUBSECTION Standard>
+CAMEL_MIME_FILTER_PROGRESS
+CAMEL_IS_MIME_FILTER_PROGRESS
+CAMEL_TYPE_MIME_FILTER_PROGRESS
+CAMEL_MIME_FILTER_PROGRESS_CLASS
+CAMEL_IS_MIME_FILTER_PROGRESS_CLASS
+CAMEL_MIME_FILTER_PROGRESS_GET_CLASS
+CamelMimeFilterProgressClass
+<SUBSECTION Private>
+CamelMimeFilterProgressPrivate
+camel_mime_filter_progress_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-mime-filter-save</FILE>
 <TITLE>CamelMimeFilterSave</TITLE>
 CamelMimeFilterSave
 camel_mime_filter_save_new
-camel_mime_filter_save_new_with_stream
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_SAVE
 CAMEL_IS_MIME_FILTER_SAVE
-CAMEL_MIME_FILTER_SAVE_TYPE
+CAMEL_TYPE_MIME_FILTER_SAVE
 CAMEL_MIME_FILTER_SAVE_CLASS
+CAMEL_IS_MIME_FILTER_SAVE_CLASS
+CAMEL_MIME_FILTER_SAVE_GET_CLASS
 CamelMimeFilterSaveClass
 <SUBSECTION Private>
+CamelMimeFilterSavePrivate
 camel_mime_filter_save_get_type
 </SECTION>
 
@@ -991,9 +1173,13 @@ camel_text_to_html
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_TOHTML
 CAMEL_IS_MIME_FILTER_TOHTML
+CAMEL_TYPE_MIME_FILTER_TOHTML
 CAMEL_MIME_FILTER_TOHTML_CLASS
+CAMEL_IS_MIME_FILTER_TOHTML_CLASS
+CAMEL_MIME_FILTER_TOHTML_GET_CLASS
 CamelMimeFilterToHTMLClass
 <SUBSECTION Private>
+CamelMimeFilterToHTMLPrivate
 camel_mime_filter_tohtml_get_type
 </SECTION>
 
@@ -1007,9 +1193,13 @@ camel_mime_filter_windows_real_charset
 <SUBSECTION Standard>
 CAMEL_MIME_FILTER_WINDOWS
 CAMEL_IS_MIME_FILTER_WINDOWS
+CAMEL_TYPE_MIME_FILTER_WINDOWS
 CAMEL_MIME_FILTER_WINDOWS_CLASS
+CAMEL_IS_MIME_FILTER_WINDOWS_CLASS
+CAMEL_MIME_FILTER_WINDOWS_GET_CLASS
 CamelMimeFilterWindowsClass
 <SUBSECTION Private>
+CamelMimeFilterWindowsPrivate
 camel_mime_filter_windows_get_type
 </SECTION>
 
@@ -1045,44 +1235,11 @@ CAMEL_IS_MIME_FILTER_YENC_CLASS
 CAMEL_MIME_FILTER_YENC_GET_CLASS
 CamelMimeFilterYencClass
 <SUBSECTION Private>
+CamelMimeFilterYencPrivate
 camel_mime_filter_yenc_get_type
 </SECTION>
 
 <SECTION>
-<FILE>camel-mime-filter</FILE>
-<TITLE>CamelMimeFilter</TITLE>
-CamelMimeFilter
-camel_mime_filter_new
-camel_mime_filter_filter
-camel_mime_filter_complete
-camel_mime_filter_reset
-camel_mime_filter_backup
-camel_mime_filter_set_size
-<SUBSECTION Standard>
-CAMEL_MIME_FILTER
-CAMEL_IS_MIME_FILTER
-CAMEL_MIME_FILTER_TYPE
-CAMEL_MIME_FILTER_CLASS
-CamelMimeFilterClass
-<SUBSECTION Private>
-camel_mime_filter_get_type
-</SECTION>
-
-<SECTION>
-<FILE>camel-mime-filter-progress</FILE>
-<TITLE>CamelMimeFilterProgress</TITLE>
-CamelMimeFilterProgress
-camel_mime_filter_progress_new
-<SUBSECTION Standard>
-CAMEL_MIME_FILTER_PROGRESS
-CAMEL_MIME_FILTER_PROGRESS_CLASS
-CAMEL_IS_MIME_FILTER_PROGRESS
-CamelMimeFilterProgressClass
-<SUBSECTION Private>
-camel_mime_filter_progress_get_type
-</SECTION>
-
-<SECTION>
 <FILE>camel-mime-message</FILE>
 <TITLE>CamelMimeMessage</TITLE>
 CamelMimeMessage
@@ -1119,8 +1276,10 @@ camel_mime_message_dump
 <SUBSECTION Standard>
 CAMEL_MIME_MESSAGE
 CAMEL_IS_MIME_MESSAGE
-CAMEL_MIME_MESSAGE_TYPE
+CAMEL_TYPE_MIME_MESSAGE
 CAMEL_MIME_MESSAGE_CLASS
+CAMEL_IS_MIME_MESSAGE_CLASS
+CAMEL_MIME_MESSAGE_GET_CLASS
 CamelMimeMessageClass
 <SUBSECTION Private>
 camel_mime_message_get_type
@@ -1162,9 +1321,13 @@ camel_mime_parser_tell_start_boundary
 <SUBSECTION Standard>
 CAMEL_MIME_PARSER
 CAMEL_IS_MIME_PARSER
+CAMEL_TYPE_MIME_PARSER
 CAMEL_MIME_PARSER_CLASS
+CAMEL_IS_MIME_PARSER_CLASS
+CAMEL_MIME_PARSER_GET_CLASS
 CamelMimeParserClass
 <SUBSECTION Private>
+CamelMimeParserPrivate
 camel_mime_parser_get_type
 </SECTION>
 
@@ -1181,8 +1344,8 @@ camel_mime_part_set_filename
 camel_mime_part_get_filename
 camel_mime_part_set_content_id
 camel_mime_part_get_content_id
-camel_mime_part_set_content_MD5
-camel_mime_part_get_content_MD5
+camel_mime_part_set_content_md5
+camel_mime_part_get_content_md5
 camel_mime_part_set_content_location
 camel_mime_part_get_content_location
 camel_mime_part_set_encoding
@@ -1191,6 +1354,7 @@ camel_mime_part_set_content_languages
 camel_mime_part_get_content_languages
 camel_mime_part_set_content_type
 camel_mime_part_get_content_type
+camel_mime_part_get_raw_headers
 camel_mime_part_construct_from_parser
 camel_mime_part_set_content
 camel_mime_part_get_content_size
@@ -1199,10 +1363,13 @@ camel_mime_message_build_preview
 <SUBSECTION Standard>
 CAMEL_MIME_PART
 CAMEL_IS_MIME_PART
-CAMEL_MIME_PART_TYPE
+CAMEL_TYPE_MIME_PART
 CAMEL_MIME_PART_CLASS
+CAMEL_IS_MIME_PART_CLASS
+CAMEL_MIME_PART_GET_CLASS
 CamelMimePartClass
 <SUBSECTION Private>
+CamelMimePartPrivate
 camel_mime_part_get_type
 </SECTION>
 
@@ -1222,6 +1389,34 @@ camel_msgport_prfd
 </SECTION>
 
 <SECTION>
+<FILE>camel-multipart</FILE>
+<TITLE>CamelMultipart</TITLE>
+CamelMultipart
+camel_multipart_new
+camel_multipart_add_part
+camel_multipart_add_part_at
+camel_multipart_remove_part
+camel_multipart_remove_part_at
+camel_multipart_get_part
+camel_multipart_get_number
+camel_multipart_set_boundary
+camel_multipart_get_boundary
+camel_multipart_set_preface
+camel_multipart_set_postface
+camel_multipart_construct_from_parser
+<SUBSECTION Standard>
+CAMEL_MULTIPART
+CAMEL_IS_MULTIPART
+CAMEL_TYPE_MULTIPART
+CAMEL_MULTIPART_CLASS
+CAMEL_IS_MULTIPART_CLASS
+CAMEL_MULTIPART_GET_CLASS
+CamelMultipartClass
+<SUBSECTION Private>
+camel_multipart_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-multipart-encrypted</FILE>
 <TITLE>CamelMultipartEncrypted</TITLE>
 CamelMultipartEncrypted
@@ -1229,8 +1424,10 @@ camel_multipart_encrypted_new
 <SUBSECTION Standard>
 CAMEL_MULTIPART_ENCRYPTED
 CAMEL_IS_MULTIPART_ENCRYPTED
-CAMEL_MULTIPART_ENCRYPTED_TYPE
+CAMEL_TYPE_MULTIPART_ENCRYPTED
 CAMEL_MULTIPART_ENCRYPTED_CLASS
+CAMEL_IS_MULTIPART_ENCRYPTED_CLASS
+CAMEL_MULTIPART_ENCRYPTED_GET_CLASS
 CamelMultipartEncryptedClass
 <SUBSECTION Private>
 camel_multipart_encrypted_get_type
@@ -1245,40 +1442,16 @@ camel_multipart_signed_get_content_stream
 <SUBSECTION Standard>
 CAMEL_MULTIPART_SIGNED
 CAMEL_IS_MULTIPART_SIGNED
-CAMEL_MULTIPART_SIGNED_TYPE
+CAMEL_TYPE_MULTIPART_SIGNED
 CAMEL_MULTIPART_SIGNED_CLASS
+CAMEL_IS_MULTIPART_SIGNED_CLASS
+CAMEL_MULTIPART_SIGNED_GET_CLASS
 CamelMultipartSignedClass
 <SUBSECTION Private>
 camel_multipart_signed_get_type
 </SECTION>
 
 <SECTION>
-<FILE>camel-multipart</FILE>
-<TITLE>CamelMultipart</TITLE>
-CamelMultipart
-camel_multipart_new
-camel_multipart_add_part
-camel_multipart_add_part_at
-camel_multipart_remove_part
-camel_multipart_remove_part_at
-camel_multipart_get_part
-camel_multipart_get_number
-camel_multipart_set_boundary
-camel_multipart_get_boundary
-camel_multipart_set_preface
-camel_multipart_set_postface
-camel_multipart_construct_from_parser
-<SUBSECTION Standard>
-CAMEL_MULTIPART
-CAMEL_IS_MULTIPART
-CAMEL_MULTIPART_TYPE
-CAMEL_MULTIPART_CLASS
-CamelMultipartClass
-<SUBSECTION Private>
-camel_multipart_get_type
-</SECTION>
-
-<SECTION>
 <FILE>camel-news-address</FILE>
 <TITLE>CamelNewsAddress</TITLE>
 CamelNewsAddress
@@ -1286,61 +1459,49 @@ camel_news_address_new
 <SUBSECTION Standard>
 CAMEL_NEWS_ADDRESS
 CAMEL_IS_NEWS_ADDRESS
+CAMEL_TYPE_NEWS_ADDRESS
 CAMEL_NEWS_ADDRESS_CLASS
+CAMEL_IS_NEWS_ADDRESS_CLASS
+CAMEL_NEWS_ADDRESS_GET_CLASS
 CamelNewsAddressClass
 <SUBSECTION Private>
+CamelNewsAddressPrivate
 camel_news_address_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-nntp-address</FILE>
+<TITLE>CamelNNTPAddress</TITLE>
+CamelNNTPAddress
+camel_nntp_address_new
+camel_nntp_address_add
+camel_nntp_address_get
+<SUBSECTION Standard>
+CAMEL_NNTP_ADDRESS
+CAMEL_IS_NNTP_ADDRESS
+CAMEL_TYPE_NNTP_ADDRESS
+CAMEL_NNTP_ADDRESS_CLASS
+CAMEL_IS_NNTP_ADDRESS_CLASS
+CAMEL_NNTP_ADDRESS_GET_CLASS
+CamelNNTPAddressClass
+<SUBSECTION Private>
+CamelNNTPAddressPrivate
+camel_nntp_address_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-object</FILE>
 <TITLE>CamelObject</TITLE>
-CAMEL_OBJECT_TRACK_INSTANCES
-CamelType
 CamelObject
-CAMEL_CHECK_CAST
-CAMEL_CHECK_CLASS_CAST
-CAMEL_CHECK_TYPE
-CAMEL_CHECK_CLASS_TYPE
-camel_object_type
-CAMEL_OBJECT_TYPE
-CAMEL_OBJECT_GET_TYPE
 CamelObjectHookID
 CamelObjectMeta
-camel_interface_type
-CAMEL_INTERFACE_TYPE
-CamelInterface
-CamelObjectClassInitFunc
-CamelObjectClassFinalizeFunc
-CamelObjectInitFunc
-CamelObjectFinalizeFunc
 CamelObjectEventPrepFunc
 CamelObjectEventHookFunc
-CAMEL_INVALID_TYPE
-CamelObjectFlags
-camel_type_init
-camel_type_register
-camel_interface_register
-camel_type_get_global_classfuncs
-camel_type_to_name
-camel_name_to_type
 camel_object_class_add_event
-camel_object_class_add_interface
-camel_object_class_dump_tree
-camel_object_cast
-camel_object_is
-camel_object_class_cast
-camel_object_class_is
-camel_interface_cast
-camel_interface_is
-camel_object_new
-camel_object_ref
-camel_object_unref
 camel_object_hook_event
 camel_object_remove_event
 camel_object_unhook_event
 camel_object_trigger_event
-camel_object_get_interface
 camel_object_set
 camel_object_setv
 camel_object_get
@@ -1364,17 +1525,10 @@ camel_object_bag_rekey
 camel_object_bag_list
 camel_object_bag_remove
 camel_object_bag_destroy
-CAMEL_MAKE_CLASS
-CamelIteratorVTable
-CamelIterator
-camel_iterator_new
-camel_iterator_free
-camel_iterator_next
-camel_iterator_reset
-camel_iterator_length
 <SUBSECTION Standard>
 CAMEL_OBJECT
 CAMEL_IS_OBJECT
+CAMEL_TYPE_OBJECT
 CAMEL_OBJECT_CLASS
 CAMEL_IS_OBJECT_CLASS
 CAMEL_OBJECT_GET_CLASS
@@ -1384,6 +1538,118 @@ camel_object_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-offline-folder</FILE>
+<TITLE>CamelOfflineFolder</TITLE>
+CamelOfflineFolder
+camel_offline_folder_downsync
+<SUBSECTION Standard>
+CAMEL_OFFLINE_FOLDER
+CAMEL_IS_OFFLINE_FOLDER
+CAMEL_TYPE_OFFLINE_FOLDER
+CAMEL_OFFLINE_FOLDER_CLASS
+CAMEL_IS_OFFLINE_FOLDER_CLASS
+CAMEL_OFFLINE_FOLDER_GET_CLASS
+CamelOfflineFolderClass
+<SUBSECTION Private>
+camel_offline_folder_get_type
+</SECTION>
+
+<SECTION>
+<FILE>camel-offline-journal</FILE>
+<TITLE>CamelOfflineJournal</TITLE>
+CamelOfflineJournal
+CamelOfflineJournalEntry
+camel_offline_journal_construct
+camel_offline_journal_set_filename
+camel_offline_journal_write
+camel_offline_journal_replay
+<SUBSECTION Standard>
+CAMEL_OFFLINE_JOURNAL
+CAMEL_IS_OFFLINE_JOURNAL
+CAMEL_TYPE_OFFLINE_JOURNAL
+CAMEL_OFFLINE_JOURNAL_CLASS
+CAMEL_IS_OFFLINE_JOURNAL_CLASS
+CAMEL_OFFLINE_JOURNAL_GET_CLASS
+CamelOfflineJournalClass
+<SUBSECTION Private>
+camel_offline_journal_get_type
+</SECTION>
+
+<SECTION>
+<FILE>camel-offline-store</FILE>
+<TITLE>CamelOfflineStore</TITLE>
+CamelOfflineStore
+camel_offline_store_set_network_state
+camel_offline_store_get_network_state
+camel_offline_store_prepare_for_offline
+<SUBSECTION Standard>
+CAMEL_OFFLINE_STORE
+CAMEL_IS_OFFLINE_STORE
+CAMEL_TYPE_OFFLINE_STORE
+CAMEL_OFFLINE_STORE_CLASS
+CAMEL_IS_OFFLINE_STORE_CLASS
+CAMEL_OFFLINE_STORE_GET_CLASS
+CamelOfflineStoreClass
+<SUBSECTION Private>
+camel_offline_store_get_type
+</SECTION>
+
+<SECTION>
+<FILE>camel-partition-table</FILE>
+<TITLE>CamelPartitionTable</TITLE>
+<TITLE>CamelKeyTable</TITLE>
+camel_hash_t
+CamelPartitionKey
+CamelPartitionKeyBlock
+CamelPartitionMap
+CamelPartitionMapBlock
+CamelPartitionTable
+camel_partition_table_new
+camel_partition_table_sync
+camel_partition_table_add
+camel_partition_table_lookup
+camel_partition_table_remove
+CamelKeyBlock
+CamelKeyRootBlock
+CamelKeyKey
+CAMEL_KEY_TABLE_MAX_KEY
+CamelKeyTable
+camel_key_table_new
+camel_key_table_sync
+camel_key_table_add
+camel_key_table_set_data
+camel_key_table_set_flags
+camel_key_table_lookup
+camel_key_table_next
+<SUBSECTION Standard>
+CAMEL_KEY_FILE
+CAMEL_IS_KEY_FILE
+CAMEL_TYPE_KEY_FILE
+CAMEL_KEY_FILE_CLASS
+CAMEL_IS_KEY_FILE_CLASS
+CAMEL_KEY_FILE_GET_CLASS
+CAMEL_KEY_TABLE
+CAMEL_IS_KEY_TABLE
+CAMEL_TYPE_KEY_TABLE
+CAMEL_KEY_TABLE_CLASS
+CAMEL_IS_KEY_TABLE_CLASS
+CAMEL_KEY_TABLE_GET_CLASS
+CAMEL_PARTITION_TABLE
+CAMEL_IS_PARTITION_TABLE
+CAMEL_TYPE_PARTITION_TABLE
+CAMEL_PARTITION_TABLE_CLASS
+CAMEL_IS_PARTITION_TABLE_CLASS
+CAMEL_PARTITION_TABLE_GET_CLASS
+CamelPartitionTableClass
+CamelKeyTableClass
+<SUBSECTION Private>
+CamelKeyTablePrivate
+CamelPartitionTablePrivate
+camel_partition_table_get_type
+camel_key_table_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-provider</FILE>
 CamelProvider
 CamelProviderType
@@ -1449,6 +1715,33 @@ CAMEL_PROVIDER_IS_REMOTE
 </SECTION>
 
 <SECTION>
+<FILE>camel-sasl</FILE>
+<TITLE>CamelSasl</TITLE>
+CamelSasl
+camel_sasl_challenge
+camel_sasl_challenge_base64
+camel_sasl_new
+camel_sasl_get_authenticated
+camel_sasl_set_authenticated
+camel_sasl_get_mechanism
+camel_sasl_get_service
+camel_sasl_get_service_name
+camel_sasl_authtype_list
+camel_sasl_authtype
+<SUBSECTION Standard>
+CAMEL_SASL
+CAMEL_IS_SASL
+CAMEL_TYPE_SASL
+CAMEL_SASL_CLASS
+CAMEL_IS_SASL_CLASS
+CAMEL_SASL_GET_CLASS
+CamelSaslClass
+<SUBSECTION Private>
+CamelSaslPrivate
+camel_sasl_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-sasl-anonymous</FILE>
 <TITLE>CamelSaslAnonymous</TITLE>
 CamelSaslAnonymous
@@ -1458,8 +1751,10 @@ camel_sasl_anonymous_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_ANONYMOUS
 CAMEL_IS_SASL_ANONYMOUS
-CAMEL_SASL_ANONYMOUS_TYPE
+CAMEL_TYPE_SASL_ANONYMOUS
 CAMEL_SASL_ANONYMOUS_CLASS
+CAMEL_IS_SASL_ANONYMOUS_CLASS
+CAMEL_SASL_ANONYMOUS_GET_CLASS
 CamelSaslAnonymousClass
 <SUBSECTION Private>
 camel_sasl_anonymous_get_type
@@ -1473,10 +1768,13 @@ camel_sasl_cram_md5_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_CRAM_MD5
 CAMEL_IS_SASL_CRAM_MD5
-CAMEL_SASL_CRAM_MD5_TYPE
+CAMEL_TYPE_SASL_CRAM_MD5
 CAMEL_SASL_CRAM_MD5_CLASS
+CAMEL_IS_SASL_CRAM_MD5_CLASS
+CAMEL_SASL_CRAM_MD5_GET_CLASS
 CamelSaslCramMd5Class
 <SUBSECTION Private>
+CamelSaslCramMd5Private
 camel_sasl_cram_md5_get_type
 </SECTION>
 
@@ -1488,10 +1786,13 @@ camel_sasl_digest_md5_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_DIGEST_MD5
 CAMEL_IS_SASL_DIGEST_MD5
-CAMEL_SASL_DIGEST_MD5_TYPE
+CAMEL_TYPE_SASL_DIGEST_MD5
 CAMEL_SASL_DIGEST_MD5_CLASS
+CAMEL_IS_SASL_DIGEST_MD5_CLASS
+CAMEL_SASL_DIGEST_MD5_GET_CLASS
 CamelSaslDigestMd5Class
 <SUBSECTION Private>
+CamelSaslDigestMd5Private
 camel_sasl_digest_md5_get_type
 </SECTION>
 
@@ -1503,10 +1804,13 @@ camel_sasl_gssapi_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_GSSAPI
 CAMEL_IS_SASL_GSSAPI
-CAMEL_SASL_GSSAPI_TYPE
+CAMEL_TYPE_SASL_GSSAPI
 CAMEL_SASL_GSSAPI_CLASS
+CAMEL_IS_SASL_GSSAPI_CLASS
+CAMEL_SASL_GSSAPI_GET_CLASS
 CamelSaslGssapiClass
 <SUBSECTION Private>
+CamelSaslGssapiPrivate
 camel_sasl_gssapi_get_type
 </SECTION>
 
@@ -1518,10 +1822,13 @@ camel_sasl_login_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_LOGIN
 CAMEL_IS_SASL_LOGIN
-CAMEL_SASL_LOGIN_TYPE
+CAMEL_TYPE_SASL_LOGIN
 CAMEL_SASL_LOGIN_CLASS
+CAMEL_IS_SASL_LOGIN_CLASS
+CAMEL_SASL_LOGIN_GET_CLASS
 CamelSaslLoginClass
 <SUBSECTION Private>
+CamelSaslLoginPrivate
 camel_sasl_login_get_type
 </SECTION>
 
@@ -1533,10 +1840,13 @@ camel_sasl_ntlm_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_NTLM
 CAMEL_IS_SASL_NTLM
-CAMEL_SASL_NTLM_TYPE
+CAMEL_TYPE_SASL_NTLM
 CAMEL_SASL_NTLM_CLASS
+CAMEL_IS_SASL_NTLM_CLASS
+CAMEL_SASL_NTLM_GET_CLASS
 CamelSaslNTLMClass
 <SUBSECTION Private>
+CamelSaslNTLMPrivate
 camel_sasl_ntlm_get_type
 </SECTION>
 
@@ -1548,10 +1858,13 @@ camel_sasl_plain_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_PLAIN
 CAMEL_IS_SASL_PLAIN
-CAMEL_SASL_PLAIN_TYPE
+CAMEL_TYPE_SASL_PLAIN
 CAMEL_SASL_PLAIN_CLASS
+CAMEL_IS_SASL_PLAIN_CLASS
+CAMEL_SASL_PLAIN_GET_CLASS
 CamelSaslPlainClass
 <SUBSECTION Private>
+CamelSaslPlainPrivate
 camel_sasl_plain_get_type
 </SECTION>
 
@@ -1563,34 +1876,17 @@ camel_sasl_popb4smtp_authtype
 <SUBSECTION Standard>
 CAMEL_SASL_POPB4SMTP
 CAMEL_IS_SASL_POPB4SMTP
-CAMEL_SASL_POPB4SMTP_TYPE
+CAMEL_TYPE_SASL_POPB4SMTP
 CAMEL_SASL_POPB4SMTP_CLASS
+CAMEL_IS_SASL_POPB4SMTP_CLASS
+CAMEL_SASL_POPB4SMTP_GET_CLASS
 CamelSaslPOPB4SMTPClass
 <SUBSECTION Private>
+CamelSaslPOPB4SMTPPrivate
 camel_sasl_popb4smtp_get_type
 </SECTION>
 
 <SECTION>
-<FILE>camel-sasl</FILE>
-<TITLE>CamelSasl</TITLE>
-CamelSasl
-camel_sasl_challenge
-camel_sasl_challenge_base64
-camel_sasl_authenticated
-camel_sasl_new
-camel_sasl_authtype_list
-camel_sasl_authtype
-<SUBSECTION Standard>
-CAMEL_SASL
-CAMEL_IS_SASL
-CAMEL_SASL_TYPE
-CAMEL_SASL_CLASS
-CamelSaslClass
-<SUBSECTION Private>
-camel_sasl_get_type
-</SECTION>
-
-<SECTION>
 <FILE>camel-search-sql</FILE>
 camel_sexp_to_sql
 </SECTION>
@@ -1612,8 +1908,10 @@ camel_seekable_stream_set_bounds
 <SUBSECTION Standard>
 CAMEL_SEEKABLE_STREAM
 CAMEL_IS_SEEKABLE_STREAM
-CAMEL_SEEKABLE_STREAM_TYPE
+CAMEL_TYPE_SEEKABLE_STREAM
 CAMEL_SEEKABLE_STREAM_CLASS
+CAMEL_IS_SEEKABLE_STREAM_CLASS
+CAMEL_SEEKABLE_STREAM_GET_CLASS
 CamelSeekableStreamClass
 <SUBSECTION Private>
 camel_seekable_stream_get_type
@@ -1627,8 +1925,10 @@ camel_seekable_substream_new
 <SUBSECTION Standard>
 CAMEL_SEEKABLE_SUBSTREAM
 CAMEL_IS_SEEKABLE_SUBSTREAM
-CAMEL_SEEKABLE_SUBSTREAM_TYPE
+CAMEL_TYPE_SEEKABLE_SUBSTREAM
 CAMEL_SEEKABLE_SUBSTREAM_CLASS
+CAMEL_IS_SEEKABLE_SUBSTREAM_CLASS
+CAMEL_SEEKABLE_SUBSTREAM_GET_CLASS
 CamelSeekableSubstreamClass
 <SUBSECTION Private>
 camel_seekable_substream_get_type
@@ -1658,10 +1958,13 @@ camel_service_query_auth_types
 <SUBSECTION Standard>
 CAMEL_SERVICE
 CAMEL_IS_SERVICE
-CAMEL_SERVICE_TYPE
+CAMEL_TYPE_SERVICE
 CAMEL_SERVICE_CLASS
+CAMEL_IS_SERVICE_CLASS
+CAMEL_SERVICE_GET_CLASS
 CamelServiceClass
 <SUBSECTION Private>
+CamelServicePrivate
 camel_service_get_type
 </SECTION>
 
@@ -1701,10 +2004,13 @@ camel_session_forward_to
 <SUBSECTION Standard>
 CAMEL_SESSION
 CAMEL_IS_SESSION
-CAMEL_SESSION_TYPE
+CAMEL_TYPE_SESSION
 CAMEL_SESSION_CLASS
+CAMEL_IS_SESSION_CLASS
+CAMEL_SESSION_GET_CLASS
 CamelSessionClass
 <SUBSECTION Private>
+CamelSessionPrivate
 camel_session_get_type
 </SECTION>
 
@@ -1721,58 +2027,17 @@ camel_smime_context_describe_part
 <SUBSECTION Standard>
 CAMEL_SMIME_CONTEXT
 CAMEL_IS_SMIME_CONTEXT
-CAMEL_SMIME_CONTEXT_TYPE
+CAMEL_TYPE_SMIME_CONTEXT
 CAMEL_SMIME_CONTEXT_CLASS
+CAMEL_IS_SMIME_CONTEXT_CLASS
+CAMEL_SMIME_CONTEXT_GET_CLASS
 CamelSMIMEContextClass
 <SUBSECTION Private>
+CamelSMIMEContextPrivate
 camel_smime_context_get_type
 </SECTION>
 
 <SECTION>
-<FILE>camel-store-summary</FILE>
-<TITLE>CamelStoreSummary</TITLE>
-CamelStoreInfo
-CamelStoreInfoFlags
-CamelStoreSummary
-CAMEL_STORE_INFO_FOLDER_UNKNOWN
-CamelStoreSummaryFlags
-camel_store_summary_new
-camel_store_summary_set_filename
-camel_store_summary_set_uri_base
-camel_store_summary_load
-camel_store_summary_save
-camel_store_summary_header_load
-camel_store_summary_touch
-camel_store_summary_add
-camel_store_summary_add_from_path
-camel_store_summary_info_new
-camel_store_summary_info_new_from_path
-camel_store_summary_info_ref
-camel_store_summary_info_free
-camel_store_summary_remove
-camel_store_summary_remove_path
-camel_store_summary_remove_index
-camel_store_summary_clear
-camel_store_summary_count
-camel_store_summary_index
-camel_store_summary_path
-camel_store_summary_array
-camel_store_summary_array_free
-camel_store_info_string
-camel_store_info_set_string
-camel_store_info_path
-camel_store_info_uri
-camel_store_info_name
-<SUBSECTION Standard>
-CAMEL_STORE_SUMMARY
-CAMEL_IS_STORE_SUMMARY
-CAMEL_STORE_SUMMARY_CLASS
-CamelStoreSummaryClass
-<SUBSECTION Private>
-camel_store_summary_get_type
-</SECTION>
-
-<SECTION>
 <FILE>camel-store</FILE>
 <TITLE>CamelStore</TITLE>
 CamelStore
@@ -1837,22 +2102,69 @@ camel_store_unsubscribe_folder
 camel_store_noop
 camel_store_folder_uri_equal
 camel_store_can_refresh_folder
-CamelISubscribe
-camel_isubscribe_subscribed
-camel_isubscribe_subscribe
-camel_isubscribe_unsubscribe
 <SUBSECTION Standard>
 CAMEL_STORE
 CAMEL_IS_STORE
-CAMEL_STORE_TYPE
+CAMEL_TYPE_STORE
 CAMEL_STORE_CLASS
+CAMEL_IS_STORE_CLASS
+CAMEL_STORE_GET_CLASS
 CamelStoreClass
 <SUBSECTION Private>
+CamelStorePrivate
 camel_isubscribe_get_type
 camel_store_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-store-summary</FILE>
+<TITLE>CamelStoreSummary</TITLE>
+CamelStoreInfo
+CamelStoreInfoFlags
+CamelStoreSummary
+CAMEL_STORE_INFO_FOLDER_UNKNOWN
+CamelStoreSummaryFlags
+camel_store_summary_new
+camel_store_summary_set_filename
+camel_store_summary_set_uri_base
+camel_store_summary_load
+camel_store_summary_save
+camel_store_summary_header_load
+camel_store_summary_touch
+camel_store_summary_add
+camel_store_summary_add_from_path
+camel_store_summary_info_new
+camel_store_summary_info_new_from_path
+camel_store_summary_info_ref
+camel_store_summary_info_free
+camel_store_summary_remove
+camel_store_summary_remove_path
+camel_store_summary_remove_index
+camel_store_summary_clear
+camel_store_summary_count
+camel_store_summary_index
+camel_store_summary_path
+camel_store_summary_array
+camel_store_summary_array_free
+camel_store_info_string
+camel_store_info_set_string
+camel_store_info_path
+camel_store_info_uri
+camel_store_info_name
+<SUBSECTION Standard>
+CAMEL_STORE_SUMMARY
+CAMEL_IS_STORE_SUMMARY
+CAMEL_TYPE_STORE_SUMMARY
+CAMEL_STORE_SUMMARY_CLASS
+CAMEL_IS_STORE_SUMMARY_CLASS
+CAMEL_STORE_SUMMARY_GET_CLASS
+CamelStoreSummaryClass
+<SUBSECTION Private>
+CamelStoreSummaryPrivate
+camel_store_summary_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-stream</FILE>
 <TITLE>CamelStream</TITLE>
 CamelStream
@@ -1869,8 +2181,10 @@ camel_stream_write_to_stream
 <SUBSECTION Standard>
 CAMEL_STREAM
 CAMEL_IS_STREAM
-CAMEL_STREAM_TYPE
+CAMEL_TYPE_STREAM
 CAMEL_STREAM_CLASS
+CAMEL_IS_STREAM_CLASS
+CAMEL_STREAM_GET_CLASS
 CamelStreamClass
 <SUBSECTION Private>
 camel_stream_get_type
@@ -1888,10 +2202,13 @@ camel_stream_buffer_read_line
 <SUBSECTION Standard>
 CAMEL_STREAM_BUFFER
 CAMEL_IS_STREAM_BUFFER
-CAMEL_STREAM_BUFFER_TYPE
+CAMEL_TYPE_STREAM_BUFFER
 CAMEL_STREAM_BUFFER_CLASS
+CAMEL_IS_STREAM_BUFFER_CLASS
+CAMEL_STREAM_BUFFER_GET_CLASS
 CamelStreamBufferClass
 <SUBSECTION Private>
+CamelStreamBufferPrivate
 camel_stream_buffer_get_type
 </SECTION>
 
@@ -1899,15 +2216,20 @@ camel_stream_buffer_get_type
 <FILE>camel-stream-filter</FILE>
 <TITLE>CamelStreamFilter</TITLE>
 CamelStreamFilter
-camel_stream_filter_new_with_stream
+camel_stream_filter_new
 camel_stream_filter_add
 camel_stream_filter_remove
+camel_stream_filter_get_source
 <SUBSECTION Standard>
 CAMEL_STREAM_FILTER
 CAMEL_IS_STREAM_FILTER
+CAMEL_TYPE_STREAM_FILTER
 CAMEL_STREAM_FILTER_CLASS
+CAMEL_IS_STREAM_FILTER_CLASS
+CAMEL_STREAM_FILTER_GET_CLASS
 CamelStreamFilterClass
 <SUBSECTION Private>
+CamelStreamFilterPrivate
 camel_stream_filter_get_type
 </SECTION>
 
@@ -1919,13 +2241,17 @@ camel_stream_fs_new_with_name
 camel_stream_fs_new_with_name_and_bounds
 camel_stream_fs_new_with_fd
 camel_stream_fs_new_with_fd_and_bounds
+camel_stream_fs_get_fd
 <SUBSECTION Standard>
 CAMEL_STREAM_FS
 CAMEL_IS_STREAM_FS
-CAMEL_STREAM_FS_TYPE
+CAMEL_TYPE_STREAM_FS
 CAMEL_STREAM_FS_CLASS
+CAMEL_IS_STREAM_FS_CLASS
+CAMEL_STREAM_FS_GET_CLASS
 CamelStreamFsClass
 <SUBSECTION Private>
+CamelStreamFsPrivate
 camel_stream_fs_get_type
 </SECTION>
 
@@ -1942,8 +2268,10 @@ camel_stream_mem_set_buffer
 <SUBSECTION Standard>
 CAMEL_STREAM_MEM
 CAMEL_IS_STREAM_MEM
-CAMEL_STREAM_MEM_TYPE
+CAMEL_TYPE_STREAM_MEM
 CAMEL_STREAM_MEM_CLASS
+CAMEL_IS_STREAM_MEM_CLASS
+CAMEL_STREAM_MEM_GET_CLASS
 CamelStreamMemClass
 <SUBSECTION Private>
 camel_stream_mem_get_type
@@ -1957,7 +2285,10 @@ camel_stream_null_new
 <SUBSECTION Standard>
 CAMEL_STREAM_NULL
 CAMEL_IS_STREAM_NULL
+CAMEL_TYPE_STREAM_NULL
 CAMEL_STREAM_NULL_CLASS
+CAMEL_IS_STREAM_NULL_CLASS
+CAMEL_STREAM_NULL_GET_CLASS
 CamelStreamNullClass
 <SUBSECTION Private>
 camel_stream_null_get_type
@@ -1972,7 +2303,10 @@ camel_stream_process_connect
 <SUBSECTION Standard>
 CAMEL_STREAM_PROCESS
 CAMEL_IS_STREAM_PROCESS
+CAMEL_TYPE_STREAM_PROCESS
 CAMEL_STREAM_PROCESS_CLASS
+CAMEL_IS_STREAM_PROCESS_CLASS
+CAMEL_STREAM_PROCESS_GET_CLASS
 CamelStreamProcessClass
 <SUBSECTION Private>
 camel_stream_process_get_type
@@ -1987,16 +2321,42 @@ camel_stream_vfs_new_with_uri
 camel_stream_vfs_new_with_stream
 camel_stream_vfs_is_writable
 <SUBSECTION Standard>
-CAMEL_STREAM_VFS_TYPE
 CAMEL_STREAM_VFS
-CAMEL_STREAM_VFS_CLASS
 CAMEL_IS_STREAM_VFS
+CAMEL_TYPE_STREAM_VFS
+CAMEL_STREAM_VFS_CLASS
+CAMEL_IS_STREAM_VFS_CLASS
+CAMEL_STREAM_VFS_GET_CLASS
 CamelStreamVFSClass
 <SUBSECTION Private>
 camel_stream_vfs_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-tcp-stream</FILE>
+<TITLE>CamelTcpStream</TITLE>
+CamelTcpStream
+CamelSockOpt
+CamelLinger
+CamelSockOptData
+camel_tcp_stream_connect
+camel_tcp_stream_getsockopt
+camel_tcp_stream_setsockopt
+camel_tcp_stream_get_local_address
+camel_tcp_stream_get_remote_address
+<SUBSECTION Standard>
+CAMEL_TCP_STREAM
+CAMEL_IS_TCP_STREAM
+CAMEL_TYPE_TCP_STREAM
+CAMEL_TCP_STREAM_CLASS
+CAMEL_IS_TCP_STREAM_CLASS
+CAMEL_TCP_STREAM_GET_CLASS
+CamelTcpStreamClass
+<SUBSECTION Private>
+camel_tcp_stream_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-tcp-stream-raw</FILE>
 <TITLE>CamelTcpStreamRaw</TITLE>
 CamelTcpStreamRaw
@@ -2004,8 +2364,10 @@ camel_tcp_stream_raw_new
 <SUBSECTION Standard>
 CAMEL_TCP_STREAM_RAW
 CAMEL_IS_TCP_STREAM_RAW
-CAMEL_TCP_STREAM_RAW_TYPE
+CAMEL_TYPE_TCP_STREAM_RAW
 CAMEL_TCP_STREAM_RAW_CLASS
+CAMEL_IS_TCP_STREAM_RAW_CLASS
+CAMEL_TCP_STREAM_RAW_GET_CLASS
 CamelTcpStreamRawClass
 <SUBSECTION Private>
 camel_tcp_stream_raw_get_type
@@ -2024,36 +2386,17 @@ camel_tcp_stream_ssl_enable_ssl
 <SUBSECTION Standard>
 CAMEL_TCP_STREAM_SSL
 CAMEL_IS_TCP_STREAM_SSL
-CAMEL_TCP_STREAM_SSL_TYPE
+CAMEL_TYPE_TCP_STREAM_SSL
 CAMEL_TCP_STREAM_SSL_CLASS
+CAMEL_IS_TCP_STREAM_SSL_CLASS
+CAMEL_TCP_STREAM_SSL_GET_CLASS
 CamelTcpStreamSSLClass
 <SUBSECTION Private>
+CamelTcpStreamSSLPrivate
 camel_tcp_stream_ssl_get_type
 </SECTION>
 
 <SECTION>
-<FILE>camel-tcp-stream</FILE>
-<TITLE>CamelTcpStream</TITLE>
-CamelTcpStream
-CamelSockOpt
-CamelLinger
-CamelSockOptData
-camel_tcp_stream_connect
-camel_tcp_stream_getsockopt
-camel_tcp_stream_setsockopt
-camel_tcp_stream_get_local_address
-camel_tcp_stream_get_remote_address
-<SUBSECTION Standard>
-CAMEL_TCP_STREAM
-CAMEL_IS_TCP_STREAM
-CAMEL_TCP_STREAM_TYPE
-CAMEL_TCP_STREAM_CLASS
-CamelTcpStreamClass
-<SUBSECTION Private>
-camel_tcp_stream_get_type
-</SECTION>
-
-<SECTION>
 <FILE>camel-text-index</FILE>
 <TITLE>CamelTextIndex</TITLE>
 <TITLE>CamelTextIndexCursor</TITLE>
@@ -2074,12 +2417,37 @@ camel_text_index_validate
 <SUBSECTION Standard>
 CAMEL_TEXT_INDEX
 CAMEL_IS_TEXT_INDEX
+CAMEL_TYPE_TEXT_INDEX
 CAMEL_TEXT_INDEX_CLASS
+CAMEL_IS_TEXT_INDEX_CLASS
+CAMEL_TEXT_INDEX_GET_CLASS
+CAMEL_TEXT_INDEX_CURSOR
+CAMEL_IS_TEXT_INDEX_CURSOR
+CAMEL_TYPE_TEXT_INDEX_CURSOR
+CAMEL_TEXT_INDEX_CURSOR_CLASS
+CAMEL_IS_TEXT_INDEX_CURSOR_CLASS
+CAMEL_TEXT_INDEX_CURSOR_GET_CLASS
+CAMEL_TEXT_INDEX_KEY_CURSOR
+CAMEL_IS_TEXT_INDEX_KEY_CURSOR
+CAMEL_TYPE_TEXT_INDEX_KEY_CURSOR
+CAMEL_TEXT_INDEX_KEY_CURSOR_CLASS
+CAMEL_IS_TEXT_INDEX_KEY_CURSOR_CLASS
+CAMEL_TEXT_INDEX_KEY_CURSOR_GET_CLASS
+CAMEL_TEXT_INDEX_NAME
+CAMEL_IS_TEXT_INDEX_NAME
+CAMEL_TYPE_TEXT_INDEX_NAME
+CAMEL_TEXT_INDEX_NAME_CLASS
+CAMEL_IS_TEXT_INDEX_NAME_CLASS
+CAMEL_TEXT_INDEX_NAME_GET_CLASS
 CamelTextIndexClass
 CamelTextIndexCursorClass
 CamelTextIndexKeyCursorClass
 CamelTextIndexNameClass
 <SUBSECTION Private>
+CamelTextIndexPrivate
+CamelTextIndexCursorPrivate
+CamelTextIndexKeyCursorPrivate
+CamelTextIndexNamePrivate
 camel_text_index_get_type
 camel_text_index_cursor_get_type
 camel_text_index_key_cursor_get_type
@@ -2094,10 +2462,13 @@ camel_transport_send_to
 <SUBSECTION Standard>
 CAMEL_TRANSPORT
 CAMEL_IS_TRANSPORT
-CAMEL_TRANSPORT_TYPE
+CAMEL_TYPE_TRANSPORT
 CAMEL_TRANSPORT_CLASS
+CAMEL_IS_TRANSPORT_CLASS
+CAMEL_TRANSPORT_GET_CLASS
 CamelTransportClass
 <SUBSECTION Private>
+CamelTransportPrivate
 camel_transport_get_type
 </SECTION>
 
@@ -2130,9 +2501,13 @@ camel_vee_folder_sync_headers
 <SUBSECTION Standard>
 CAMEL_VEE_FOLDER
 CAMEL_IS_VEE_FOLDER
+CAMEL_TYPE_VEE_FOLDER
 CAMEL_VEE_FOLDER_CLASS
+CAMEL_IS_VEE_FOLDER_CLASS
+CAMEL_VEE_FOLDER_GET_CLASS
 CamelVeeFolderClass
 <SUBSECTION Private>
+CamelVeeFolderPrivate
 camel_vee_folder_get_type
 </SECTION>
 
@@ -2146,7 +2521,10 @@ camel_vee_store_new
 <SUBSECTION Standard>
 CAMEL_VEE_STORE
 CAMEL_IS_VEE_STORE
+CAMEL_TYPE_VEE_STORE
 CAMEL_VEE_STORE_CLASS
+CAMEL_IS_VEE_STORE_CLASS
+CAMEL_VEE_STORE_GET_CLASS
 CamelVeeStoreClass
 <SUBSECTION Private>
 camel_vee_store_get_type
@@ -2164,7 +2542,10 @@ camel_vee_summary_load_check_unread_vfolder
 <SUBSECTION Standard>
 CAMEL_VEE_SUMMARY
 CAMEL_IS_VEE_SUMMARY
+CAMEL_TYPE_VEE_SUMMARY
 CAMEL_VEE_SUMMARY_CLASS
+CAMEL_IS_VEE_SUMMARY_CLASS
+CAMEL_VEE_SUMMARY_GET_CLASS
 CamelVeeSummaryClass
 <SUBSECTION Private>
 camel_vee_summary_get_type
@@ -2181,104 +2562,16 @@ camel_vtrash_folder_new
 <SUBSECTION Standard>
 CAMEL_VTRASH_FOLDER
 CAMEL_IS_VTRASH_FOLDER
+CAMEL_TYPE_VTRASH_FOLDER
 CAMEL_VTRASH_FOLDER_CLASS
+CAMEL_IS_VTRASH_FOLDER_CLASS
+CAMEL_VTRASH_FOLDER_GET_CLASS
 CamelVTrashFolderClass
 <SUBSECTION Private>
 camel_vtrash_folder_get_type
 </SECTION>
 
 <SECTION>
-<FILE>camel-disco-store</FILE>
-<TITLE>CamelDiscoStore</TITLE>
-CamelDiscoStore
-CamelDiscoStoreStatus
-camel_disco_store_status
-camel_disco_store_set_status
-camel_disco_store_can_work_offline
-camel_disco_store_check_online
-camel_disco_store_prepare_for_offline
-<SUBSECTION Standard>
-CAMEL_DISCO_STORE
-CAMEL_IS_DISCO_STORE
-CAMEL_DISCO_STORE_TYPE
-CAMEL_DISCO_STORE_CLASS
-CamelDiscoStoreClass
-<SUBSECTION Private>
-camel_disco_store_get_type
-</SECTION>
-
-<SECTION>
-<FILE>camel-offline-journal</FILE>
-<TITLE>CamelOfflineJournal</TITLE>
-CamelOfflineJournal
-CamelOfflineJournalEntry
-camel_offline_journal_construct
-camel_offline_journal_set_filename
-camel_offline_journal_write
-camel_offline_journal_replay
-<SUBSECTION Standard>
-CAMEL_OFFLINE_JOURNAL
-CAMEL_IS_OFFLINE_JOURNAL
-CAMEL_TYPE_OFFLINE_JOURNAL
-CAMEL_OFFLINE_JOURNAL_CLASS
-CAMEL_IS_OFFLINE_JOURNAL_CLASS
-CAMEL_OFFLINE_JOURNAL_GET_CLASS
-CamelOfflineJournalClass
-<SUBSECTION Private>
-camel_offline_journal_get_type
-</SECTION>
-
-<SECTION>
-<FILE>camel-offline-folder</FILE>
-<TITLE>CamelOfflineFolder</TITLE>
-CamelOfflineFolder
-camel_offline_folder_downsync
-<SUBSECTION Standard>
-CAMEL_OFFLINE_FOLDER
-CAMEL_IS_OFFLINE_FOLDER
-CAMEL_OFFLINE_FOLDER_TYPE
-CAMEL_OFFLINE_FOLDER_CLASS
-CamelOfflineFolderClass
-<SUBSECTION Private>
-camel_offline_folder_get_type
-</SECTION>
-
-<SECTION>
-<FILE>camel-offline-store</FILE>
-<TITLE>CamelOfflineStore</TITLE>
-CamelOfflineStore
-camel_offline_store_set_network_state
-camel_offline_store_get_network_state
-camel_offline_store_prepare_for_offline
-<SUBSECTION Standard>
-CAMEL_OFFLINE_STORE
-CAMEL_IS_OFFLINE_STORE
-CAMEL_TYPE_OFFLINE_STORE
-CAMEL_OFFLINE_STORE_CLASS
-CAMEL_IS_OFFLINE_STORE_CLASS
-CAMEL_OFFLINE_STORE_GET_CLASS
-CamelOfflineStoreClass
-<SUBSECTION Private>
-camel_offline_store_get_type
-</SECTION>
-
-<SECTION>
-<FILE>camel-nntp-address</FILE>
-<TITLE>CamelNNTPAddress</TITLE>
-CamelNNTPAddress
-camel_nntp_address_new
-camel_nntp_address_add
-camel_nntp_address_get
-<SUBSECTION Standard>
-CAMEL_NNTP_ADDRESS
-CAMEL_IS_NNTP_ADDRESS
-CAMEL_NNTP_ADDRESS_CLASS
-CamelNNTPAddressClass
-<SUBSECTION Private>
-camel_nntp_address_get_type
-</SECTION>
-
-<SECTION>
 <FILE>camel-imap-folder</FILE>
 <TITLE>CamelImapFolder</TITLE>
 CamelImapFolder
@@ -2292,8 +2585,10 @@ imap_expunge_uids_resyncing
 <SUBSECTION Standard>
 CAMEL_IMAP_FOLDER
 CAMEL_IS_IMAP_FOLDER
-CAMEL_IMAP_FOLDER_TYPE
+CAMEL_TYPE_IMAP_FOLDER
 CAMEL_IMAP_FOLDER_CLASS
+CAMEL_IS_IMAP_FOLDER_CLASS
+CAMEL_IMAP_FOLDER_GET_CLASS
 CamelImapFolderClass
 <SUBSECTION Private>
 CamelImapFolderPrivate
@@ -2312,10 +2607,10 @@ camel_imap_journal_uidmap_add
 camel_imap_journal_uidmap_lookup
 camel_imap_journal_close_folders
 <SUBSECTION Standard>
-CAMEL_TYPE_IMAP_JOURNAL
 CAMEL_IMAP_JOURNAL
-CAMEL_IMAP_JOURNAL_CLASS
 CAMEL_IS_IMAP_JOURNAL
+CAMEL_TYPE_IMAP_JOURNAL
+CAMEL_IMAP_JOURNAL_CLASS
 CAMEL_IS_IMAP_JOURNAL_CLASS
 CAMEL_IMAP_JOURNAL_GET_CLASS
 CamelIMAPJournalClass
@@ -2343,8 +2638,10 @@ camel_imap_message_cache_filter_cached
 <SUBSECTION Standard>
 CAMEL_IMAP_MESSAGE_CACHE
 CAMEL_IS_IMAP_MESSAGE_CACHE
-CAMEL_IMAP_MESSAGE_CACHE_TYPE
+CAMEL_TYPE_IMAP_MESSAGE_CACHE
 CAMEL_IMAP_MESSAGE_CACHE_CLASS
+CAMEL_IS_IMAP_MESSAGE_CACHE_CLASS
+CAMEL_IMAP_MESSAGE_CACHE_GET_CLASS
 CamelImapMessageCacheClass
 <SUBSECTION Private>
 camel_imap_message_cache_get_type
@@ -2358,8 +2655,10 @@ camel_imap_search_new
 <SUBSECTION Standard>
 CAMEL_IMAP_SEARCH
 CAMEL_IS_IMAP_SEARCH
-CAMEL_IMAP_SEARCH_TYPE
+CAMEL_TYPE_IMAP_SEARCH
 CAMEL_IMAP_SEARCH_CLASS
+CAMEL_IS_IMAP_SEARCH_CLASS
+CAMEL_IMAP_SEARCH_GET_CLASS
 CamelImapSearchClass
 <SUBSECTION Private>
 camel_imap_search_get_type
@@ -2386,9 +2685,13 @@ camel_imap_store_info_full_name
 <SUBSECTION Standard>
 CAMEL_IMAP_STORE_SUMMARY
 CAMEL_IS_IMAP_STORE_SUMMARY
+CAMEL_TYPE_IMAP_STORE_SUMMARY
 CAMEL_IMAP_STORE_SUMMARY_CLASS
+CAMEL_IS_IMAP_STORE_SUMMARY_CLASS
+CAMEL_IMAP_STORE_SUMMARY_GET_CLASS
 CamelImapStoreSummaryClass
 <SUBSECTION Private>
+CamelImapStoreSummaryPrivate
 camel_imap_store_summary_get_type
 </SECTION>
 
@@ -2437,8 +2740,10 @@ camel_imap_store_readline
 <SUBSECTION Standard>
 CAMEL_IMAP_STORE
 CAMEL_IS_IMAP_STORE
-CAMEL_IMAP_STORE_TYPE
+CAMEL_TYPE_IMAP_STORE
 CAMEL_IMAP_STORE_CLASS
+CAMEL_IS_IMAP_STORE_CLASS
+CAMEL_IMAP_STORE_GET_CLASS
 CamelImapStoreClass
 <SUBSECTION Private>
 camel_imap_store_get_type
@@ -2457,7 +2762,10 @@ camel_imap_summary_add_offline_uncached
 <SUBSECTION Standard>
 CAMEL_IMAP_SUMMARY
 CAMEL_IS_IMAP_SUMMARY
+CAMEL_TYPE_IMAP_SUMMARY
 CAMEL_IMAP_SUMMARY_CLASS
+CAMEL_IS_IMAP_SUMMARY_CLASS
+CAMEL_IMAP_SUMMARY_GET_CLASS
 CamelImapSummaryClass
 <SUBSECTION Private>
 camel_imap_summary_get_type
@@ -2471,8 +2779,10 @@ camel_imap_wrapper_new
 <SUBSECTION Standard>
 CAMEL_IMAP_WRAPPER
 CAMEL_IS_IMAP_WRAPPER
-CAMEL_IMAP_WRAPPER_TYPE
+CAMEL_TYPE_IMAP_WRAPPER
 CAMEL_IMAP_WRAPPER_CLASS
+CAMEL_IS_IMAP_WRAPPER_CLASS
+CAMEL_IMAP_WRAPPER_GET_CLASS
 CamelImapWrapperClass
 <SUBSECTION Private>
 camel_imap_wrapper_get_type
@@ -2488,10 +2798,13 @@ gw_update_summary
 <SUBSECTION Standard>
 CAMEL_GROUPWISE_FOLDER
 CAMEL_IS_GROUPWISE_FOLDER
-CAMEL_GROUPWISE_FOLDER_TYPE
+CAMEL_TYPE_GROUPWISE_FOLDER
 CAMEL_GROUPWISE_FOLDER_CLASS
+CAMEL_IS_GROUPWISE_FOLDER_CLASS
+CAMEL_GROUPWISE_FOLDER_GET_CLASS
 CamelGroupwiseFolderClass
 <SUBSECTION Private>
+CamelGroupwiseFolderPrivate
 camel_groupwise_folder_get_type
 </SECTION>
 
@@ -2512,11 +2825,15 @@ camel_groupwise_store_summary_namespace_find_path
 camel_groupwise_store_summary_namespace_set
 camel_groupwise_store_info_full_name
 <SUBSECTION Standard>
-CAMEL_GW_STORE_SUMMARY
-CAMEL_IS_GW_STORE_SUMMARY
-CAMEL_GW_STORE_SUMMARY_CLASS
+CAMEL_GROUPWISE_STORE_SUMMARY
+CAMEL_IS_GROUPWISE_STORE_SUMMARY
+CAMEL_TYPE_GROUPWISE_STORE_SUMMARY
+CAMEL_GROUPWISE_STORE_SUMMARY_CLASS
+CAMEL_IS_GROUPWISE_STORE_SUMMARY_CLASS
+CAMEL_GROUPWISE_STORE_SUMMARY_GET_CLASS
 CamelGroupwiseStoreSummaryClass
 <SUBSECTION Private>
+CamelGroupwiseStoreSummaryPrivate
 camel_groupwise_store_summary_get_type
 </SECTION>
 
@@ -2539,8 +2856,10 @@ groupwise_store_set_current_folder
 <SUBSECTION Standard>
 CAMEL_GROUPWISE_STORE
 CAMEL_IS_GROUPWISE_STORE
-CAMEL_GROUPWISE_STORE_TYPE
+CAMEL_TYPE_GROUPWISE_STORE
 CAMEL_GROUPWISE_STORE_CLASS
+CAMEL_IS_GROUPWISE_STORE_CLASS
+CAMEL_GROUPWISE_STORE_GET_CLASS
 CamelGroupwiseStoreClass
 <SUBSECTION Private>
 camel_groupwise_store_get_type
@@ -2559,7 +2878,10 @@ groupwise_summary_clear
 <SUBSECTION Standard>
 CAMEL_GROUPWISE_SUMMARY
 CAMEL_IS_GROUPWISE_SUMMARY
+CAMEL_TYPE_GROUPWISE_SUMMARY
 CAMEL_GROUPWISE_SUMMARY_CLASS
+CAMEL_IS_GROUPWISE_SUMMARY_CLASS
+CAMEL_GROUPWISE_SUMMARY_GET_CLASS
 CamelGroupwiseSummaryClass
 <SUBSECTION Private>
 camel_groupwise_summary_get_type
@@ -2572,8 +2894,10 @@ CamelGroupwiseTransport
 <SUBSECTION Standard>
 CAMEL_GROUPWISE_TRANSPORT
 CAMEL_IS_GROUPWISE_TRANSPORT
-CAMEL_GROUPWISE_TRANSPORT_TYPE
+CAMEL_TYPE_GROUPWISE_TRANSPORT
 CAMEL_GROUPWISE_TRANSPORT_CLASS
+CAMEL_IS_GROUPWISE_TRANSPORT_CLASS
+CAMEL_GROUPWISE_TRANSPORT_GET_CLASS
 CamelGroupwiseTransportClass
 <SUBSECTION Private>
 camel_groupwise_transport_get_type
@@ -2667,8 +2991,10 @@ camel_imap4_search_new
 <SUBSECTION Standard>
 CAMEL_IMAP4_SEARCH
 CAMEL_IS_IMAP4_SEARCH
-CAMEL_IMAP4_SEARCH_TYPE
+CAMEL_TYPE_IMAP4_SEARCH
 CAMEL_IMAP4_SEARCH_CLASS
+CAMEL_IS_IMAP4_SEARCH_CLASS
+CAMEL_IMAP4_SEARCH_GET_CLASS
 CamelIMAP4SearchClass
 <SUBSECTION Private>
 camel_imap4_search_get_type
@@ -2688,9 +3014,13 @@ camel_imap4_store_summary_get_folder_info
 <SUBSECTION Standard>
 CAMEL_IMAP4_STORE_SUMMARY
 CAMEL_IS_IMAP4_STORE_SUMMARY
+CAMEL_TYPE_IMAP4_STORE_SUMMARY
 CAMEL_IMAP4_STORE_SUMMARY_CLASS
+CAMEL_IS_IMAP4_STORE_SUMMARY_CLASS
+CAMEL_IMAP4_STORE_SUMMARY_GET_CLASS
 CamelIMAP4StoreSummaryClass
 <SUBSECTION Private>
+CamelIMAP4StoreSummaryPrivate
 camel_imap4_store_summary_get_type
 </SECTION>
 
@@ -2727,6 +3057,8 @@ CAMEL_IMAP4_STREAM
 CAMEL_IS_IMAP4_STREAM
 CAMEL_TYPE_IMAP4_STREAM
 CAMEL_IMAP4_STREAM_CLASS
+CAMEL_IS_IMAP4_STREAM_CLASS
+CAMEL_IMAP4_STREAM_GET_CLASS
 CamelIMAP4StreamClass
 <SUBSECTION Private>
 camel_imap4_stream_get_type
@@ -2789,8 +3121,10 @@ camel_local_folder_unlock
 <SUBSECTION Standard>
 CAMEL_LOCAL_FOLDER
 CAMEL_IS_LOCAL_FOLDER
-CAMEL_LOCAL_FOLDER_TYPE
+CAMEL_TYPE_LOCAL_FOLDER
 CAMEL_LOCAL_FOLDER_CLASS
+CAMEL_IS_LOCAL_FOLDER_CLASS
+CAMEL_LOCAL_FOLDER_GET_CLASS
 CamelLocalFolderClass
 <SUBSECTION Private>
 CamelLocalFolderPrivate
@@ -2807,8 +3141,10 @@ camel_local_store_get_meta_path
 <SUBSECTION Standard>
 CAMEL_LOCAL_STORE
 CAMEL_IS_LOCAL_STORE
-CAMEL_LOCAL_STORE_TYPE
+CAMEL_TYPE_LOCAL_STORE
 CAMEL_LOCAL_STORE_CLASS
+CAMEL_IS_LOCAL_STORE_CLASS
+CAMEL_LOCAL_STORE_GET_CLASS
 CamelLocalStoreClass
 <SUBSECTION Private>
 camel_local_store_get_type
@@ -2831,7 +3167,10 @@ camel_local_summary_write_headers
 <SUBSECTION Standard>
 CAMEL_LOCAL_SUMMARY
 CAMEL_IS_LOCAL_SUMMARY
+CAMEL_TYPE_LOCAL_SUMMARY
 CAMEL_LOCAL_SUMMARY_CLASS
+CAMEL_IS_LOCAL_SUMMARY_CLASS
+CAMEL_LOCAL_SUMMARY_GET_CLASS
 CamelLocalSummaryClass
 <SUBSECTION Private>
 camel_local_summary_get_type
@@ -2845,8 +3184,10 @@ camel_maildir_folder_new
 <SUBSECTION Standard>
 CAMEL_MAILDIR_FOLDER
 CAMEL_IS_MAILDIR_FOLDER
-CAMEL_MAILDIR_FOLDER_TYPE
+CAMEL_TYPE_MAILDIR_FOLDER
 CAMEL_MAILDIR_FOLDER_CLASS
+CAMEL_IS_MAILDIR_FOLDER_CLASS
+CAMEL_MAILDIR_FOLDER_GET_CLASS
 CamelMaildirFolderClass
 <SUBSECTION Private>
 camel_maildir_folder_get_type
@@ -2859,8 +3200,10 @@ CamelMaildirStore
 <SUBSECTION Standard>
 CAMEL_MAILDIR_STORE
 CAMEL_IS_MAILDIR_STORE
-CAMEL_MAILDIR_STORE_TYPE
+CAMEL_TYPE_MAILDIR_STORE
 CAMEL_MAILDIR_STORE_CLASS
+CAMEL_IS_MAILDIR_STORE_CLASS
+CAMEL_MAILDIR_STORE_GET_CLASS
 CamelMaildirStoreClass
 <SUBSECTION Private>
 camel_maildir_store_get_type
@@ -2880,9 +3223,13 @@ camel_maildir_info_set_filename
 <SUBSECTION Standard>
 CAMEL_MAILDIR_SUMMARY
 CAMEL_IS_MAILDIR_SUMMARY
+CAMEL_TYPE_MAILDIR_SUMMARY
 CAMEL_MAILDIR_SUMMARY_CLASS
+CAMEL_IS_MAILDIR_SUMMARY_CLASS
+CAMEL_MAILDIR_SUMMARY_GET_CLASS
 CamelMaildirSummaryClass
 <SUBSECTION Private>
+CamelMaildirSummaryPrivate
 camel_maildir_summary_get_type
 </SECTION>
 
@@ -2894,8 +3241,10 @@ camel_mbox_folder_new
 <SUBSECTION Standard>
 CAMEL_MBOX_FOLDER
 CAMEL_IS_MBOX_FOLDER
-CAMEL_MBOX_FOLDER_TYPE
+CAMEL_TYPE_MBOX_FOLDER
 CAMEL_MBOX_FOLDER_CLASS
+CAMEL_IS_MBOX_FOLDER_CLASS
+CAMEL_MBOX_FOLDER_GET_CLASS
 CamelMboxFolderClass
 <SUBSECTION Private>
 camel_mbox_folder_get_type
@@ -2908,8 +3257,10 @@ CamelMboxStore
 <SUBSECTION Standard>
 CAMEL_MBOX_STORE
 CAMEL_IS_MBOX_STORE
-CAMEL_MBOX_STORE_TYPE
+CAMEL_TYPE_MBOX_STORE
 CAMEL_MBOX_STORE_CLASS
+CAMEL_IS_MBOX_STORE_CLASS
+CAMEL_MBOX_STORE_GET_CLASS
 CamelMboxStoreClass
 <SUBSECTION Private>
 camel_mbox_store_get_type
@@ -2928,7 +3279,10 @@ camel_mbox_summary_sync_mbox
 <SUBSECTION Standard>
 CAMEL_MBOX_SUMMARY
 CAMEL_IS_MBOX_SUMMARY
+CAMEL_TYPE_MBOX_SUMMARY
 CAMEL_MBOX_SUMMARY_CLASS
+CAMEL_IS_MBOX_SUMMARY_CLASS
+CAMEL_MBOX_SUMMARY_GET_CLASS
 CamelMboxSummaryClass
 <SUBSECTION Private>
 camel_mbox_summary_get_type
@@ -2942,8 +3296,10 @@ camel_mh_folder_new
 <SUBSECTION Standard>
 CAMEL_MH_FOLDER
 CAMEL_IS_MH_FOLDER
-CAMEL_MH_FOLDER_TYPE
+CAMEL_TYPE_MH_FOLDER
 CAMEL_MH_FOLDER_CLASS
+CAMEL_IS_MH_FOLDER_CLASS
+CAMEL_MH_FOLDER_GET_CLASS
 CamelMhFolderClass
 <SUBSECTION Private>
 camel_mh_folder_get_type
@@ -2956,8 +3312,10 @@ CamelMhStore
 <SUBSECTION Standard>
 CAMEL_MH_STORE
 CAMEL_IS_MH_STORE
-CAMEL_MH_STORE_TYPE
+CAMEL_TYPE_MH_STORE
 CAMEL_MH_STORE_CLASS
+CAMEL_IS_MH_STORE_CLASS
+CAMEL_MH_STORE_GET_CLASS
 CamelMhStoreClass
 <SUBSECTION Private>
 camel_mh_store_get_type
@@ -2971,9 +3329,13 @@ camel_mh_summary_new
 <SUBSECTION Standard>
 CAMEL_MH_SUMMARY
 CAMEL_IS_MH_SUMMARY
+CAMEL_TYPE_MH_SUMMARY
 CAMEL_MH_SUMMARY_CLASS
+CAMEL_IS_MH_SUMMARY_CLASS
+CAMEL_MH_SUMMARY_GET_CLASS
 CamelMhSummaryClass
 <SUBSECTION Private>
+CamelMhSummaryPrivate
 camel_mh_summary_get_type
 </SECTION>
 
@@ -2985,10 +3347,13 @@ camel_spool_folder_new
 <SUBSECTION Standard>
 CAMEL_SPOOL_FOLDER
 CAMEL_IS_SPOOL_FOLDER
-CAMEL_SPOOL_FOLDER_TYPE
+CAMEL_TYPE_SPOOL_FOLDER
 CAMEL_SPOOL_FOLDER_CLASS
+CAMEL_IS_SPOOL_FOLDER_CLASS
+CAMEL_SPOOL_FOLDER_GET_CLASS
 CamelSpoolFolderClass
 <SUBSECTION Private>
+CamelSpoolFolderPrivate
 camel_spool_folder_get_type
 </SECTION>
 
@@ -3000,8 +3365,10 @@ camel_spool_store_t
 <SUBSECTION Standard>
 CAMEL_SPOOL_STORE
 CAMEL_IS_SPOOL_STORE
-CAMEL_SPOOL_STORE_TYPE
+CAMEL_TYPE_SPOOL_STORE
 CAMEL_SPOOL_STORE_CLASS
+CAMEL_IS_SPOOL_STORE_CLASS
+CAMEL_SPOOL_STORE_GET_CLASS
 CamelSpoolStoreClass
 <SUBSECTION Private>
 camel_spool_store_get_type
@@ -3023,7 +3390,10 @@ camel_spool_summary_write_headers
 <SUBSECTION Standard>
 CAMEL_SPOOL_SUMMARY
 CAMEL_IS_SPOOL_SUMMARY
+CAMEL_TYPE_SPOOL_SUMMARY
 CAMEL_SPOOL_SUMMARY_CLASS
+CAMEL_IS_SPOOL_SUMMARY_CLASS
+CAMEL_SPOOL_SUMMARY_GET_CLASS
 CamelSpoolSummaryClass
 <SUBSECTION Private>
 camel_spool_summary_get_type
@@ -3038,8 +3408,10 @@ camel_nntp_folder_selected
 <SUBSECTION Standard>
 CAMEL_NNTP_FOLDER
 CAMEL_IS_NNTP_FOLDER
-CAMEL_NNTP_FOLDER_TYPE
+CAMEL_TYPE_NNTP_FOLDER
 CAMEL_NNTP_FOLDER_CLASS
+CAMEL_IS_NNTP_FOLDER_CLASS
+CAMEL_NNTP_FOLDER_GET_CLASS
 CamelNNTPFolderClass
 <SUBSECTION Private>
 CamelNNTPFolderPrivate
@@ -3063,9 +3435,13 @@ camel_nntp_store_summary_full_from_path
 <SUBSECTION Standard>
 CAMEL_NNTP_STORE_SUMMARY
 CAMEL_IS_NNTP_STORE_SUMMARY
+CAMEL_TYPE_NNTP_STORE_SUMMARY
 CAMEL_NNTP_STORE_SUMMARY_CLASS
+CAMEL_IS_NNTP_STORE_SUMMARY_CLASS
+CAMEL_NNTP_STORE_SUMMARY_GET_CLASS
 CamelNNTPStoreSummaryClass
 <SUBSECTION Private>
+CamelNNTPStoreSummaryPrivate
 camel_nntp_store_summary_get_type
 </SECTION>
 
@@ -3090,8 +3466,10 @@ camel_nntp_command
 <SUBSECTION Standard>
 CAMEL_NNTP_STORE
 CAMEL_IS_NNTP_STORE
-CAMEL_NNTP_STORE_TYPE
+CAMEL_TYPE_NNTP_STORE
 CAMEL_NNTP_STORE_CLASS
+CAMEL_IS_NNTP_STORE_CLASS
+CAMEL_NNTP_STORE_GET_CLASS
 CamelNNTPStoreClass
 <SUBSECTION Private>
 CamelNNTPStorePrivate
@@ -3111,7 +3489,10 @@ camel_nntp_stream_getd
 <SUBSECTION Standard>
 CAMEL_NNTP_STREAM
 CAMEL_IS_NNTP_STREAM
+CAMEL_TYPE_NNTP_STREAM
 CAMEL_NNTP_STREAM_CLASS
+CAMEL_IS_NNTP_STREAM_CLASS
+CAMEL_NNTP_STREAM_GET_CLASS
 CamelNNTPStreamClass
 <SUBSECTION Private>
 camel_nntp_stream_get_type
@@ -3125,10 +3506,14 @@ camel_nntp_summary_new
 camel_nntp_summary_check
 <SUBSECTION Standard>
 CAMEL_NNTP_SUMMARY
-CAMEL_IS_LOCAL_SUMMARY
+CAMEL_IS_NNTP_SUMMARY
+CAMEL_TYPE_NNTP_SUMMARY
 CAMEL_NNTP_SUMMARY_CLASS
+CAMEL_IS_NNTP_SUMMARY_CLASS
+CAMEL_NNTP_SUMMARY_GET_CLASS
 CamelNNTPSummaryClass
 <SUBSECTION Private>
+CamelNNTPSummaryPrivate
 camel_nntp_summary_get_type
 </SECTION>
 
@@ -3148,7 +3533,10 @@ camel_pop3_engine_command_new
 <SUBSECTION Standard>
 CAMEL_POP3_ENGINE
 CAMEL_IS_POP3_ENGINE
+CAMEL_TYPE_POP3_ENGINE
 CAMEL_POP3_ENGINE_CLASS
+CAMEL_IS_POP3_ENGINE_CLASS
+CAMEL_POP3_ENGINE_GET_CLASS
 CamelPOP3EngineClass
 <SUBSECTION Private>
 camel_pop3_engine_get_type
@@ -3164,8 +3552,10 @@ camel_pop3_delete_old
 <SUBSECTION Standard>
 CAMEL_POP3_FOLDER
 CAMEL_IS_POP3_FOLDER
-CAMEL_POP3_FOLDER_TYPE
+CAMEL_TYPE_POP3_FOLDER
 CAMEL_POP3_FOLDER_CLASS
+CAMEL_IS_POP3_FOLDER_CLASS
+CAMEL_POP3_FOLDER_GET_CLASS
 CamelPOP3FolderClass
 <SUBSECTION Private>
 camel_pop3_folder_get_type
@@ -3181,8 +3571,10 @@ camel_pop3_command_get_additional_data
 <SUBSECTION Standard>
 CAMEL_POP3_STORE
 CAMEL_IS_POP3_STORE
-CAMEL_POP3_STORE_TYPE
+CAMEL_TYPE_POP3_STORE
 CAMEL_POP3_STORE_CLASS
+CAMEL_IS_POP3_STORE_CLASS
+CAMEL_POP3_STORE_GET_CLASS
 CamelPOP3StoreClass
 <SUBSECTION Private>
 camel_pop3_store_get_type
@@ -3201,7 +3593,10 @@ camel_pop3_stream_getd
 <SUBSECTION Standard>
 CAMEL_POP3_STREAM
 CAMEL_IS_POP3_STREAM
+CAMEL_TYPE_POP3_STREAM
 CAMEL_POP3_STREAM_CLASS
+CAMEL_IS_POP3_STREAM_CLASS
+CAMEL_POP3_STREAM_GET_CLASS
 CamelPOP3StreamClass
 <SUBSECTION Private>
 camel_pop3_stream_get_type
@@ -3214,8 +3609,10 @@ CamelSendmailTransport
 <SUBSECTION Standard>
 CAMEL_SENDMAIL_TRANSPORT
 CAMEL_IS_SENDMAIL_TRANSPORT
-CAMEL_SENDMAIL_TRANSPORT_TYPE
+CAMEL_TYPE_SENDMAIL_TRANSPORT
 CAMEL_SENDMAIL_TRANSPORT_CLASS
+CAMEL_IS_SENDMAIL_TRANSPORT_CLASS
+CAMEL_SENDMAIL_TRANSPORT_GET_CLASS
 CamelSendmailTransportClass
 <SUBSECTION Private>
 camel_sendmail_transport_get_type
@@ -3233,8 +3630,10 @@ CAMEL_SMTP_TRANSPORT_AUTH_EQUAL
 <SUBSECTION Standard>
 CAMEL_SMTP_TRANSPORT
 CAMEL_IS_SMTP_TRANSPORT
-CAMEL_SMTP_TRANSPORT_TYPE
+CAMEL_TYPE_SMTP_TRANSPORT
 CAMEL_SMTP_TRANSPORT_CLASS
+CAMEL_IS_SMTP_TRANSPORT_CLASS
+CAMEL_SMTP_TRANSPORT_GET_CLASS
 CamelSmtpTransportClass
 <SUBSECTION Private>
 camel_smtp_transport_get_type
@@ -3247,9 +3646,11 @@ CamelTestSession
 camel_test_session_new
 <SUBSECTION Standard>
 CAMEL_TEST_SESSION
-CAMEL_TEST_IS_SESSION
-CAMEL_TEST_SESSION_TYPE
+CAMEL_IS_TEST_SESSION
+CAMEL_TYPE_TEST_SESSION
 CAMEL_TEST_SESSION_CLASS
+CAMEL_IS_TEST_SESSION_CLASS
+CAMEL_TEST_SESSION_GET_CLASS
 CamelTestSessionClass
 <SUBSECTION Private>
 camel_test_session_get_type
@@ -3595,41 +3996,6 @@ camel_operation_end
 </SECTION>
 
 <SECTION>
-<FILE>camel-partition-table</FILE>
-<TITLE>CamelPartitionTable</TITLE>
-<TITLE>CamelKeyTable</TITLE>
-camel_hash_t
-CamelPartitionKey
-CamelPartitionKeyBlock
-CamelPartitionMap
-CamelPartitionMapBlock
-CamelPartitionTable
-camel_partition_table_new
-camel_partition_table_sync
-camel_partition_table_add
-camel_partition_table_lookup
-camel_partition_table_remove
-CamelKeyBlock
-CamelKeyRootBlock
-CamelKeyKey
-CAMEL_KEY_TABLE_MAX_KEY
-CamelKeyTable
-camel_key_table_new
-camel_key_table_sync
-camel_key_table_add
-camel_key_table_set_data
-camel_key_table_set_flags
-camel_key_table_lookup
-camel_key_table_next
-<SUBSECTION Standard>
-CamelPartitionTableClass
-CamelKeyTableClass
-<SUBSECTION Private>
-camel_partition_table_get_type
-camel_key_table_get_type
-</SECTION>
-
-<SECTION>
 <FILE>camel-process</FILE>
 camel_process_fork
 camel_process_wait
diff --git a/docs/reference/camel/camel.types b/docs/reference/camel/camel.types
index e69de29..8d8b533 100644
--- a/docs/reference/camel/camel.types
+++ b/docs/reference/camel/camel.types
@@ -0,0 +1,92 @@
+camel_address_get_type
+camel_block_file_get_type
+camel_key_file_get_type
+camel_certdb_get_type
+camel_cipher_context_get_type
+camel_data_cache_get_type
+camel_data_wrapper_get_type
+camel_digest_folder_get_type
+camel_digest_store_get_type
+camel_digest_summary_get_type
+camel_disco_diary_get_type
+camel_disco_folder_get_type
+camel_disco_store_get_type
+camel_filter_driver_get_type
+camel_folder_get_type
+camel_folder_search_get_type
+camel_folder_summary_get_type
+camel_gpg_context_get_type
+camel_html_parser_get_type
+camel_http_stream_get_type
+camel_index_cursor_get_type
+camel_index_name_get_type
+camel_index_get_type
+camel_internet_address_get_type
+camel_medium_get_type
+camel_mime_filter_basic_get_type
+camel_mime_filter_bestenc_get_type
+camel_mime_filter_canon_get_type
+camel_mime_filter_charset_get_type
+camel_mime_filter_crlf_get_type
+camel_mime_filter_enriched_get_type
+camel_mime_filter_from_get_type
+camel_mime_filter_gzip_get_type
+camel_mime_filter_get_type
+camel_mime_filter_html_get_type
+camel_mime_filter_index_get_type
+camel_mime_filter_linewrap_get_type
+camel_mime_filter_pgp_get_type
+camel_mime_filter_progress_get_type
+camel_mime_filter_save_get_type
+camel_mime_filter_tohtml_get_type
+camel_mime_filter_windows_get_type
+camel_mime_filter_yenc_get_type
+camel_mime_message_get_type
+camel_mime_parser_get_type
+camel_mime_part_get_type
+camel_multipart_encrypted_get_type
+camel_multipart_get_type
+camel_multipart_signed_get_type
+camel_nntp_address_get_type
+camel_object_get_type
+camel_offline_folder_get_type
+camel_offline_journal_get_type
+camel_offline_store_get_type
+camel_partition_table_get_type
+camel_key_table_get_type
+camel_sasl_anonymous_get_type
+camel_sasl_cram_md5_get_type
+camel_sasl_digest_md5_get_type
+camel_sasl_gssapi_get_type
+camel_sasl_get_type
+camel_sasl_login_get_type
+camel_sasl_ntlm_get_type
+camel_sasl_plain_get_type
+camel_sasl_popb4smtp_get_type
+camel_seekable_stream_get_type
+camel_seekable_substream_get_type
+camel_service_get_type
+camel_session_get_type
+camel_smime_context_get_type
+camel_store_get_type
+camel_store_summary_get_type
+camel_stream_buffer_get_type
+camel_stream_filter_get_type
+camel_stream_fs_get_type
+camel_stream_get_type
+camel_stream_mem_get_type
+camel_stream_null_get_type
+camel_stream_process_get_type
+camel_stream_vfs_get_type
+camel_tcp_stream_get_type
+camel_tcp_stream_raw_get_type
+camel_tcp_stream_ssl_get_type
+camel_text_index_cursor_get_type
+camel_text_index_key_cursor_get_type
+camel_text_index_name_get_type
+camel_text_index_get_type
+camel_transport_get_type
+camel_vee_folder_get_type
+camel_vee_store_get_type
+camel_vee_summary_get_type
+camel_vtrash_folder_get_type
diff --git a/docs/reference/camel/tmpl/camel-address.sgml b/docs/reference/camel/tmpl/camel-address.sgml
index be2f32a..677b3cd 100644
--- a/docs/reference/camel/tmpl/camel-address.sgml
+++ b/docs/reference/camel/tmpl/camel-address.sgml
@@ -22,9 +22,6 @@ CamelAddress
 
 </para>
 
- parent: 
- addresses: 
- priv: 
 
 <!-- ##### FUNCTION camel_address_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-block-file.sgml b/docs/reference/camel/tmpl/camel-block-file.sgml
index 454f9d4..cf08d27 100644
--- a/docs/reference/camel/tmpl/camel-block-file.sgml
+++ b/docs/reference/camel/tmpl/camel-block-file.sgml
@@ -58,19 +58,6 @@ CamelKeyFile
 
 </para>
 
- parent: 
- priv: 
- version: 
- path: 
- flags: 
- fd: 
- block_size: 
- root: 
- root_block: 
- block_cache_limit: 
- block_cache_count: 
- block_cache: 
- blocks: 
 
 <!-- ##### MACRO CAMEL_BLOCK_FILE_SYNC ##### -->
 <para>
@@ -227,12 +214,6 @@ CamelKeyFile
 
 </para>
 
- parent: 
- priv: 
- fp: 
- path: 
- flags: 
- last: 
 
 <!-- ##### FUNCTION camel_key_file_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-certdb.sgml b/docs/reference/camel/tmpl/camel-certdb.sgml
index d2d3e71..810718e 100644
--- a/docs/reference/camel/tmpl/camel-certdb.sgml
+++ b/docs/reference/camel/tmpl/camel-certdb.sgml
@@ -22,16 +22,6 @@ CamelCertDB
 
 </para>
 
- parent_object: 
- priv: 
- filename: 
- version: 
- saved_certs: 
- flags: 
- cert_size: 
- cert_chunks: 
- certs: 
- cert_hash: 
 
 <!-- ##### ENUM CamelCertTrust ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-cipher-context.sgml b/docs/reference/camel/tmpl/camel-cipher-context.sgml
index 318fedb..eb3f1d1 100644
--- a/docs/reference/camel/tmpl/camel-cipher-context.sgml
+++ b/docs/reference/camel/tmpl/camel-cipher-context.sgml
@@ -22,12 +22,11 @@ CamelCipherContext
 
 </para>
 
- parent_object: 
- priv: 
- session: 
- sign_protocol: 
- encrypt_protocol: 
- key_protocol: 
+
+<!-- ##### ARG CamelCipherContext:session ##### -->
+<para>
+
+</para>
 
 <!-- ##### STRUCT CamelCipherValidity ##### -->
 <para>
@@ -102,13 +101,13 @@ CamelCipherContext
 @Returns: 
 
 
-<!-- ##### FUNCTION camel_cipher_context_construct ##### -->
+<!-- ##### FUNCTION camel_cipher_context_get_session ##### -->
 <para>
 
 </para>
 
 @context: 
- session: 
+ Returns: 
 
 
 <!-- ##### FUNCTION camel_cipher_id_to_hash ##### -->
diff --git a/docs/reference/camel/tmpl/camel-data-cache.sgml b/docs/reference/camel/tmpl/camel-data-cache.sgml
index 5de75f3..d2c094f 100644
--- a/docs/reference/camel/tmpl/camel-data-cache.sgml
+++ b/docs/reference/camel/tmpl/camel-data-cache.sgml
@@ -22,12 +22,11 @@ CamelDataCache
 
 </para>
 
- parent_object: 
- priv: 
- path: 
- flags: 
- expire_age: 
- expire_access: 
+
+<!-- ##### ARG CamelDataCache:path ##### -->
+<para>
+
+</para>
 
 <!-- ##### FUNCTION camel_data_cache_new ##### -->
 <para>
@@ -35,11 +34,28 @@ CamelDataCache
 </para>
 
 @path: 
- flags: 
 @ex: 
 @Returns: 
 
 
+<!-- ##### FUNCTION camel_data_cache_get_path ##### -->
+<para>
+
+</para>
+
+ cdc: 
+ Returns: 
+
+
+<!-- ##### FUNCTION camel_data_cache_set_path ##### -->
+<para>
+
+</para>
+
+ cdc: 
+ path: 
+
+
 <!-- ##### FUNCTION camel_data_cache_set_expire_age ##### -->
 <para>
 
diff --git a/docs/reference/camel/tmpl/camel-data-wrapper.sgml b/docs/reference/camel/tmpl/camel-data-wrapper.sgml
index 6a941a7..11144cc 100644
--- a/docs/reference/camel/tmpl/camel-data-wrapper.sgml
+++ b/docs/reference/camel/tmpl/camel-data-wrapper.sgml
@@ -22,12 +22,6 @@ CamelDataWrapper
 
 </para>
 
- parent_object: 
- priv: 
- encoding: 
- mime_type: 
- stream: 
- offline: 
 
 <!-- ##### FUNCTION camel_data_wrapper_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-digest-folder.sgml b/docs/reference/camel/tmpl/camel-digest-folder.sgml
index f57d24b..41e9e60 100644
--- a/docs/reference/camel/tmpl/camel-digest-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-digest-folder.sgml
@@ -22,8 +22,6 @@ CamelDigestFolder
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### FUNCTION camel_digest_folder_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-digest-store.sgml b/docs/reference/camel/tmpl/camel-digest-store.sgml
index 31b235b..ebc25dc 100644
--- a/docs/reference/camel/tmpl/camel-digest-store.sgml
+++ b/docs/reference/camel/tmpl/camel-digest-store.sgml
@@ -22,7 +22,6 @@ CamelDigestStore
 
 </para>
 
- parent: 
 
 <!-- ##### FUNCTION camel_digest_store_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-digest-summary.sgml b/docs/reference/camel/tmpl/camel-digest-summary.sgml
index 3bbd09e..1cb4079 100644
--- a/docs/reference/camel/tmpl/camel-digest-summary.sgml
+++ b/docs/reference/camel/tmpl/camel-digest-summary.sgml
@@ -22,7 +22,6 @@ CamelDigestSummary
 
 </para>
 
- parent_object: 
 
 <!-- ##### FUNCTION camel_digest_summary_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-disco-diary.sgml b/docs/reference/camel/tmpl/camel-disco-diary.sgml
index 3e32b0d..2114195 100644
--- a/docs/reference/camel/tmpl/camel-disco-diary.sgml
+++ b/docs/reference/camel/tmpl/camel-disco-diary.sgml
@@ -22,11 +22,6 @@ CamelDiscoDiary
 
 </para>
 
- parent_object: 
- store: 
- file: 
- folders: 
- uidmap: 
 
 <!-- ##### ENUM CamelDiscoDiaryAction ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-disco-folder.sgml b/docs/reference/camel/tmpl/camel-disco-folder.sgml
index c0cff22..1635928 100644
--- a/docs/reference/camel/tmpl/camel-disco-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-disco-folder.sgml
@@ -22,8 +22,6 @@ CamelDiscoFolder
 
 </para>
 
- parent_object: 
- offline_sync: 
 
 <!-- ##### FUNCTION camel_disco_folder_expunge_uids ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-disco-store.sgml b/docs/reference/camel/tmpl/camel-disco-store.sgml
index 3b96627..ea7c191 100644
--- a/docs/reference/camel/tmpl/camel-disco-store.sgml
+++ b/docs/reference/camel/tmpl/camel-disco-store.sgml
@@ -22,9 +22,6 @@ CamelDiscoStore
 
 </para>
 
- parent_object: 
- status: 
- diary: 
 
 <!-- ##### ENUM CamelDiscoStoreStatus ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-filter-driver.sgml b/docs/reference/camel/tmpl/camel-filter-driver.sgml
index cfbaf47..2c4ca18 100644
--- a/docs/reference/camel/tmpl/camel-filter-driver.sgml
+++ b/docs/reference/camel/tmpl/camel-filter-driver.sgml
@@ -22,8 +22,6 @@ CamelFilterDriver
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### USER_FUNCTION CamelFilterGetFolderFunc ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-folder-search.sgml b/docs/reference/camel/tmpl/camel-folder-search.sgml
index b3ea24a..8ba597c 100644
--- a/docs/reference/camel/tmpl/camel-folder-search.sgml
+++ b/docs/reference/camel/tmpl/camel-folder-search.sgml
@@ -22,16 +22,6 @@ CamelFolderSearch
 
 </para>
 
- parent: 
- priv: 
- sexp: 
- last_search: 
- folder: 
- summary: 
- summary_set: 
- current: 
- current_message: 
- body_index: 
 
 <!-- ##### FUNCTION camel_folder_search_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-folder-summary.sgml b/docs/reference/camel/tmpl/camel-folder-summary.sgml
index 2f3af73..f95e261 100644
--- a/docs/reference/camel/tmpl/camel-folder-summary.sgml
+++ b/docs/reference/camel/tmpl/camel-folder-summary.sgml
@@ -22,35 +22,6 @@ CamelFolderSummary
 
 </para>
 
- parent: 
- priv: 
- version: 
- flags: 
- nextuid: 
- time: 
- saved_count: 
- unread_count: 
- deleted_count: 
- junk_count: 
- junk_not_deleted_count: 
- visible_count: 
- message_info_size: 
- content_info_size: 
- message_info_chunks: 
- content_info_chunks: 
- summary_path: 
- build_content: 
- messages: 
- messages_uid: 
- uids: 
- loaded_infos: 
- folder: 
- meta_summary: 
- cache_load_time: 
- timeout_handle: 
- collate: 
- sort_by: 
- later: 
 
 <!-- ##### STRUCT CamelMessageInfo ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-folder.sgml b/docs/reference/camel/tmpl/camel-folder.sgml
index 0ee9f4e..ae679b6 100644
--- a/docs/reference/camel/tmpl/camel-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-folder.sgml
@@ -22,16 +22,6 @@ CamelFolder
 
 </para>
 
- parent_object: 
- priv: 
- name: 
- full_name: 
- description: 
- parent_store: 
- summary: 
- folder_flags: 
- permanent_flags: 
- later: 
 
 <!-- ##### STRUCT CamelFolderChangeInfo ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-gpg-context.sgml b/docs/reference/camel/tmpl/camel-gpg-context.sgml
index 29e1745..2f4ae4c 100644
--- a/docs/reference/camel/tmpl/camel-gpg-context.sgml
+++ b/docs/reference/camel/tmpl/camel-gpg-context.sgml
@@ -22,8 +22,11 @@ CamelGpgContext
 
 </para>
 
- parent_object: 
- always_trust: 
+
+<!-- ##### ARG CamelGpgContext:always-trust ##### -->
+<para>
+
+</para>
 
 <!-- ##### FUNCTION camel_gpg_context_new ##### -->
 <para>
@@ -34,12 +37,21 @@ CamelGpgContext
 @Returns: 
 
 
+<!-- ##### FUNCTION camel_gpg_context_get_always_trust ##### -->
+<para>
+
+</para>
+
+ context: 
+ Returns: 
+
+
 <!-- ##### FUNCTION camel_gpg_context_set_always_trust ##### -->
 <para>
 
 </para>
 
- ctx: 
- trust: 
+ context: 
+ always_trust: 
 
 
diff --git a/docs/reference/camel/tmpl/camel-groupwise-folder.sgml b/docs/reference/camel/tmpl/camel-groupwise-folder.sgml
index 7297e4b..2b966c0 100644
--- a/docs/reference/camel/tmpl/camel-groupwise-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-groupwise-folder.sgml
@@ -22,7 +22,7 @@ CamelGroupwiseFolder
 
 </para>
 
- parent_object: 
+ parent: 
 @priv: 
 @search: 
 @journal: 
diff --git a/docs/reference/camel/tmpl/camel-groupwise-journal.sgml b/docs/reference/camel/tmpl/camel-groupwise-journal.sgml
index 60e7c1a..c84cd7e 100644
--- a/docs/reference/camel/tmpl/camel-groupwise-journal.sgml
+++ b/docs/reference/camel/tmpl/camel-groupwise-journal.sgml
@@ -22,7 +22,7 @@ CamelGroupwiseJournal
 
 </para>
 
- parent_object: 
+ parent: 
 
 <!-- ##### STRUCT CamelGroupwiseJournalEntry ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-groupwise-store.sgml b/docs/reference/camel/tmpl/camel-groupwise-store.sgml
index d34c10f..d9a2db1 100644
--- a/docs/reference/camel/tmpl/camel-groupwise-store.sgml
+++ b/docs/reference/camel/tmpl/camel-groupwise-store.sgml
@@ -29,7 +29,7 @@ CamelGroupwiseStore
 
 </para>
 
- parent_object: 
+ parent: 
 @summary: 
 @root_container: 
 @priv: 
diff --git a/docs/reference/camel/tmpl/camel-groupwise-transport.sgml b/docs/reference/camel/tmpl/camel-groupwise-transport.sgml
index b3c0827..186b656 100644
--- a/docs/reference/camel/tmpl/camel-groupwise-transport.sgml
+++ b/docs/reference/camel/tmpl/camel-groupwise-transport.sgml
@@ -22,6 +22,6 @@ CamelGroupwiseTransport
 
 </para>
 
- parent_object: 
+ parent: 
 @connected: 
 
diff --git a/docs/reference/camel/tmpl/camel-html-parser.sgml b/docs/reference/camel/tmpl/camel-html-parser.sgml
index 8cc957f..191b15b 100644
--- a/docs/reference/camel/tmpl/camel-html-parser.sgml
+++ b/docs/reference/camel/tmpl/camel-html-parser.sgml
@@ -22,8 +22,6 @@ CamelHTMLParser
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### ENUM camel_html_parser_t ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-http-stream.sgml b/docs/reference/camel/tmpl/camel-http-stream.sgml
index 1ef6d79..2885970 100644
--- a/docs/reference/camel/tmpl/camel-http-stream.sgml
+++ b/docs/reference/camel/tmpl/camel-http-stream.sgml
@@ -22,20 +22,6 @@ CamelHttpStream
 
 </para>
 
- parent_object: 
- parser: 
- content_type: 
- headers: 
- method: 
- session: 
- url: 
- user_agent: 
- proxy: 
- authrealm: 
- authpass: 
- statuscode: 
- raw: 
- read: 
 
 <!-- ##### ENUM CamelHttpMethod ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-imap-folder.sgml b/docs/reference/camel/tmpl/camel-imap-folder.sgml
index a9df8e0..9d4d279 100644
--- a/docs/reference/camel/tmpl/camel-imap-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-imap-folder.sgml
@@ -22,7 +22,7 @@ CamelImapFolder
 
 </para>
 
- parent_object: 
+ parent: 
 @priv: 
 @search: 
 @cache: 
diff --git a/docs/reference/camel/tmpl/camel-imap-journal.sgml b/docs/reference/camel/tmpl/camel-imap-journal.sgml
index 25157af..73197f1 100644
--- a/docs/reference/camel/tmpl/camel-imap-journal.sgml
+++ b/docs/reference/camel/tmpl/camel-imap-journal.sgml
@@ -43,7 +43,7 @@ CamelImapJournal
 
 </para>
 
- parent_object: 
+ parent: 
 @folders: 
 @uidmap: 
 @rp_in_progress: 
diff --git a/docs/reference/camel/tmpl/camel-imap-message-cache.sgml b/docs/reference/camel/tmpl/camel-imap-message-cache.sgml
index e9231a8..191ea19 100644
--- a/docs/reference/camel/tmpl/camel-imap-message-cache.sgml
+++ b/docs/reference/camel/tmpl/camel-imap-message-cache.sgml
@@ -22,7 +22,7 @@ CamelImapMessageCache
 
 </para>
 
- parent_object: 
+ parent: 
 @path: 
 @parts: 
 @cached: 
diff --git a/docs/reference/camel/tmpl/camel-imap-store.sgml b/docs/reference/camel/tmpl/camel-imap-store.sgml
index 5caeb0f..25a717a 100644
--- a/docs/reference/camel/tmpl/camel-imap-store.sgml
+++ b/docs/reference/camel/tmpl/camel-imap-store.sgml
@@ -31,7 +31,7 @@ CamelImapStore
 
 </para>
 
- parent_object: 
+ parent: 
 @istream: 
 @ostream: 
 @summary: 
diff --git a/docs/reference/camel/tmpl/camel-imap-wrapper.sgml b/docs/reference/camel/tmpl/camel-imap-wrapper.sgml
index ddf3a15..b3cfc74 100644
--- a/docs/reference/camel/tmpl/camel-imap-wrapper.sgml
+++ b/docs/reference/camel/tmpl/camel-imap-wrapper.sgml
@@ -22,7 +22,7 @@ CamelImapWrapper
 
 </para>
 
- parent_object: 
+ parent: 
 @priv: 
 @folder: 
 @uid: 
diff --git a/docs/reference/camel/tmpl/camel-imap4-engine.sgml b/docs/reference/camel/tmpl/camel-imap4-engine.sgml
index 9f859fc..e773c5c 100644
--- a/docs/reference/camel/tmpl/camel-imap4-engine.sgml
+++ b/docs/reference/camel/tmpl/camel-imap4-engine.sgml
@@ -22,7 +22,7 @@ CamelIMAP4Engine
 
 </para>
 
- parent_object: 
+ parent: 
 @reconnect: 
 @reconnecting: 
 @session: 
diff --git a/docs/reference/camel/tmpl/camel-imap4-folder.sgml b/docs/reference/camel/tmpl/camel-imap4-folder.sgml
index f9ba14d..42448be 100644
--- a/docs/reference/camel/tmpl/camel-imap4-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-imap4-folder.sgml
@@ -22,7 +22,7 @@ CamelIMAP4Folder
 
 </para>
 
- parent_object: 
+ parent: 
 @search: 
 @journal: 
 @cache: 
diff --git a/docs/reference/camel/tmpl/camel-imap4-journal.sgml b/docs/reference/camel/tmpl/camel-imap4-journal.sgml
index e4f3662..2095412 100644
--- a/docs/reference/camel/tmpl/camel-imap4-journal.sgml
+++ b/docs/reference/camel/tmpl/camel-imap4-journal.sgml
@@ -22,7 +22,7 @@ CamelIMAP4Journal
 
 </para>
 
- parent_object: 
+ parent: 
 @failed: 
 
 <!-- ##### STRUCT CamelIMAP4JournalEntry ##### -->
diff --git a/docs/reference/camel/tmpl/camel-imap4-search.sgml b/docs/reference/camel/tmpl/camel-imap4-search.sgml
index c2399ae..678b010 100644
--- a/docs/reference/camel/tmpl/camel-imap4-search.sgml
+++ b/docs/reference/camel/tmpl/camel-imap4-search.sgml
@@ -22,7 +22,7 @@ CamelIMAP4Search
 
 </para>
 
- parent_object: 
+ parent: 
 @engine: 
 @lastuid: 
 @validity: 
diff --git a/docs/reference/camel/tmpl/camel-imap4-store.sgml b/docs/reference/camel/tmpl/camel-imap4-store.sgml
index c6b2b3f..b2b6ea3 100644
--- a/docs/reference/camel/tmpl/camel-imap4-store.sgml
+++ b/docs/reference/camel/tmpl/camel-imap4-store.sgml
@@ -22,7 +22,7 @@ CamelIMAP4Store
 
 </para>
 
- parent_object: 
+ parent: 
 @summary: 
 @engine: 
 @storage_path: 
diff --git a/docs/reference/camel/tmpl/camel-imap4-stream.sgml b/docs/reference/camel/tmpl/camel-imap4-stream.sgml
index 118fb0c..1c9627a 100644
--- a/docs/reference/camel/tmpl/camel-imap4-stream.sgml
+++ b/docs/reference/camel/tmpl/camel-imap4-stream.sgml
@@ -43,7 +43,7 @@ CamelIMAP4Stream
 
 </para>
 
- parent_object: 
+ parent: 
 @stream: 
 @disconnected: 
 @have_unget: 
diff --git a/docs/reference/camel/tmpl/camel-imap4-summary.sgml b/docs/reference/camel/tmpl/camel-imap4-summary.sgml
index 74870aa..e2c78bc 100644
--- a/docs/reference/camel/tmpl/camel-imap4-summary.sgml
+++ b/docs/reference/camel/tmpl/camel-imap4-summary.sgml
@@ -22,7 +22,7 @@ CamelIMAP4Summary
 
 </para>
 
- parent_object: 
+ parent: 
 @version: 
 @exists: 
 @recent: 
diff --git a/docs/reference/camel/tmpl/camel-index.sgml b/docs/reference/camel/tmpl/camel-index.sgml
index a3488fe..16292e3 100644
--- a/docs/reference/camel/tmpl/camel-index.sgml
+++ b/docs/reference/camel/tmpl/camel-index.sgml
@@ -22,14 +22,6 @@ CamelIndex
 
 </para>
 
- parent: 
- priv: 
- path: 
- version: 
- flags: 
- state: 
- normalise: 
- normalise_data: 
 
 <!-- ##### USER_FUNCTION CamelIndexNorm ##### -->
 <para>
@@ -47,9 +39,6 @@ CamelIndex
 
 </para>
 
- parent: 
- priv: 
- index: 
 
 <!-- ##### FUNCTION camel_index_cursor_new ##### -->
 <para>
@@ -83,12 +72,6 @@ CamelIndex
 
 </para>
 
- parent: 
- priv: 
- index: 
- name: 
- buffer: 
- words: 
 
 <!-- ##### FUNCTION camel_index_name_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-internet-address.sgml b/docs/reference/camel/tmpl/camel-internet-address.sgml
index b1d03e4..a8fade6 100644
--- a/docs/reference/camel/tmpl/camel-internet-address.sgml
+++ b/docs/reference/camel/tmpl/camel-internet-address.sgml
@@ -22,8 +22,6 @@ CamelInternetAddress
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### FUNCTION camel_internet_address_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-local-folder.sgml b/docs/reference/camel/tmpl/camel-local-folder.sgml
index 4a3660c..a0f2f11 100644
--- a/docs/reference/camel/tmpl/camel-local-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-local-folder.sgml
@@ -22,7 +22,7 @@ CamelLocalFolder
 
 </para>
 
- parent_object: 
+ parent: 
 @priv: 
 @flags: 
 @locked: 
diff --git a/docs/reference/camel/tmpl/camel-local-store.sgml b/docs/reference/camel/tmpl/camel-local-store.sgml
index 0d4704e..0193411 100644
--- a/docs/reference/camel/tmpl/camel-local-store.sgml
+++ b/docs/reference/camel/tmpl/camel-local-store.sgml
@@ -22,7 +22,7 @@ CamelLocalStore
 
 </para>
 
- parent_object: 
+ parent: 
 @toplevel_dir: 
 
 <!-- ##### FUNCTION camel_local_store_get_toplevel_dir ##### -->
diff --git a/docs/reference/camel/tmpl/camel-maildir-folder.sgml b/docs/reference/camel/tmpl/camel-maildir-folder.sgml
index 80331d3..95b400d 100644
--- a/docs/reference/camel/tmpl/camel-maildir-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-maildir-folder.sgml
@@ -22,7 +22,7 @@ CamelMaildirFolder
 
 </para>
 
- parent_object: 
+ parent: 
 
 <!-- ##### FUNCTION camel_maildir_folder_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-maildir-store.sgml b/docs/reference/camel/tmpl/camel-maildir-store.sgml
index 352b56c..d93f582 100644
--- a/docs/reference/camel/tmpl/camel-maildir-store.sgml
+++ b/docs/reference/camel/tmpl/camel-maildir-store.sgml
@@ -22,5 +22,5 @@ CamelMaildirStore
 
 </para>
 
- parent_object: 
+ parent: 
 
diff --git a/docs/reference/camel/tmpl/camel-mbox-folder.sgml b/docs/reference/camel/tmpl/camel-mbox-folder.sgml
index 286ee8f..4db83e0 100644
--- a/docs/reference/camel/tmpl/camel-mbox-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-mbox-folder.sgml
@@ -22,7 +22,7 @@ CamelMboxFolder
 
 </para>
 
- parent_object: 
+ parent: 
 @lockfd: 
 
 <!-- ##### FUNCTION camel_mbox_folder_new ##### -->
diff --git a/docs/reference/camel/tmpl/camel-mbox-store.sgml b/docs/reference/camel/tmpl/camel-mbox-store.sgml
index 6ab4c16..1c3ddc6 100644
--- a/docs/reference/camel/tmpl/camel-mbox-store.sgml
+++ b/docs/reference/camel/tmpl/camel-mbox-store.sgml
@@ -22,5 +22,5 @@ CamelMboxStore
 
 </para>
 
- parent_object: 
+ parent: 
 
diff --git a/docs/reference/camel/tmpl/camel-medium.sgml b/docs/reference/camel/tmpl/camel-medium.sgml
index d6cfd68..e4dbd9d 100644
--- a/docs/reference/camel/tmpl/camel-medium.sgml
+++ b/docs/reference/camel/tmpl/camel-medium.sgml
@@ -22,8 +22,11 @@ CamelMedium
 
 </para>
 
- parent_object: 
- content: 
+
+<!-- ##### ARG CamelMedium:content ##### -->
+<para>
+
+</para>
 
 <!-- ##### STRUCT CamelMediumHeader ##### -->
 <para>
@@ -90,7 +93,7 @@ CamelMedium
 @headers: 
 
 
-<!-- ##### FUNCTION camel_medium_get_content_object ##### -->
+<!-- ##### FUNCTION camel_medium_get_content ##### -->
 <para>
 
 </para>
@@ -99,7 +102,7 @@ CamelMedium
 @Returns: 
 
 
-<!-- ##### FUNCTION camel_medium_set_content_object ##### -->
+<!-- ##### FUNCTION camel_medium_set_content ##### -->
 <para>
 
 </para>
diff --git a/docs/reference/camel/tmpl/camel-mh-folder.sgml b/docs/reference/camel/tmpl/camel-mh-folder.sgml
index 81c9811..4c1daf4 100644
--- a/docs/reference/camel/tmpl/camel-mh-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-mh-folder.sgml
@@ -22,7 +22,7 @@ CamelMhFolder
 
 </para>
 
- parent_object: 
+ parent: 
 
 <!-- ##### FUNCTION camel_mh_folder_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mh-store.sgml b/docs/reference/camel/tmpl/camel-mh-store.sgml
index 02254ac..a32b257 100644
--- a/docs/reference/camel/tmpl/camel-mh-store.sgml
+++ b/docs/reference/camel/tmpl/camel-mh-store.sgml
@@ -22,6 +22,6 @@ CamelMhStore
 
 </para>
 
- parent_object: 
+ parent: 
 @flags: 
 
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml b/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml
index afd570e..22e855b 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml
@@ -22,12 +22,6 @@ CamelMimeFilterBasic
 
 </para>
 
- parent: 
- priv: 
- type: 
- uubuf: 
- state: 
- save: 
 
 <!-- ##### ENUM CamelMimeFilterBasicType ##### -->
 <para>
@@ -46,14 +40,6 @@ CamelMimeFilterBasic
 
 </para>
 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_mime_filter_basic_new_type ##### -->
-<para>
-
-</para>
-
 @type: 
 @Returns: 
 
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml b/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml
index b697a26..505dfda 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml
@@ -42,20 +42,6 @@ CamelMimeFilterBestenc
 
 </para>
 
- parent: 
- flags: 
- count0: 
- count8: 
- total: 
- lastc: 
- crlfnoorder: 
- startofline: 
- fromcount: 
- fromsave: 
- hadfrom: 
- countline: 
- maxline: 
- charset: 
 
 <!-- ##### 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..336eee0 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-canon.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-canon.sgml
@@ -22,8 +22,6 @@ CamelMimeFilterCanon
 
 </para>
 
- parent: 
- flags: 
 
 <!-- ##### 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 a549d1b..9806a55 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-charset.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-charset.sgml
@@ -22,25 +22,12 @@ CamelMimeFilterCharset
 
 </para>
 
- parent: 
- priv: 
- ic: 
- from: 
- to: 
 
 <!-- ##### FUNCTION camel_mime_filter_charset_new ##### -->
 <para>
 
 </para>
 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_mime_filter_charset_new_convert ##### -->
-<para>
-
-</para>
-
 @from_charset: 
 @to_charset: 
 @Returns: 
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml b/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml
index 41fe585..936b52c 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml
@@ -22,12 +22,6 @@ CamelMimeFilterCRLF
 
 </para>
 
- parent: 
- direction: 
- mode: 
- saw_cr: 
- saw_lf: 
- saw_dot: 
 
 <!-- ##### 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 466e06b..a69b360 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-enriched.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-enriched.sgml
@@ -22,9 +22,6 @@ CamelMimeFilterEnriched
 
 </para>
 
- parent_object: 
- flags: 
- nofill: 
 
 <!-- ##### 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..cb78e93 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-from.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-from.sgml
@@ -22,8 +22,6 @@ CamelMimeFilterFrom
 
 </para>
 
- parent: 
- midline: 
 
 <!-- ##### 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 b78a657..b0f2fbf 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-gzip.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-gzip.sgml
@@ -22,10 +22,6 @@ CamelMimeFilterGZip
 
 </para>
 
- parent_object: 
- priv: 
- mode: 
- level: 
 
 <!-- ##### ENUM CamelMimeFilterGZipMode ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-html.sgml b/docs/reference/camel/tmpl/camel-mime-filter-html.sgml
index f4ce6d9..3b13488 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-html.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-html.sgml
@@ -22,8 +22,6 @@ CamelMimeFilterHTML
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_html_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-index.sgml b/docs/reference/camel/tmpl/camel-mime-filter-index.sgml
index b02b07e..8e0d706 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-index.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-index.sgml
@@ -22,24 +22,12 @@ CamelMimeFilterIndex
 
 </para>
 
- parent: 
- priv: 
- index: 
- name: 
 
 <!-- ##### FUNCTION camel_mime_filter_index_new ##### -->
 <para>
 
 </para>
 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_mime_filter_index_new_index ##### -->
-<para>
-
-</para>
-
 @index: 
 @Returns: 
 
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml b/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml
index 86a7b45..b59e3cc 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml
@@ -22,12 +22,6 @@ CamelMimeFilterLinewrap
 
 </para>
 
- parent: 
- wrap_len: 
- max_len: 
- indent: 
- nchars: 
- flags: 
 
 <!-- ##### 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..ecba711 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-pgp.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-pgp.sgml
@@ -22,8 +22,6 @@ CamelMimeFilterPgp
 
 </para>
 
- filter: 
- state: 
 
 <!-- ##### 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..ba16e3f 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-progress.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-progress.sgml
@@ -22,10 +22,6 @@ CamelMimeFilterProgress
 
 </para>
 
- parent: 
- operation: 
- total: 
- count: 
 
 <!-- ##### 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 328f89c..3ae7be0 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-save.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-save.sgml
@@ -22,22 +22,12 @@ CamelMimeFilterSave
 
 </para>
 
- parent: 
- stream: 
 
 <!-- ##### FUNCTION camel_mime_filter_save_new ##### -->
 <para>
 
 </para>
 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_mime_filter_save_new_with_stream ##### -->
-<para>
-
-</para>
-
 @stream: 
 @Returns: 
 
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml b/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml
index 3b18e1a..045a916 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml
@@ -22,12 +22,6 @@ CamelMimeFilterToHTML
 
 </para>
 
- parent: 
- scanner: 
- flags: 
- colour: 
- column: 
- pre_open: 
 
 <!-- ##### MACRO CAMEL_MIME_FILTER_TOHTML_PRE ##### -->
 <para>
@@ -105,7 +99,7 @@ CamelMimeFilterToHTML
 </para>
 
 @flags: 
- colour: 
+ color: 
 @Returns: 
 
 
@@ -116,7 +110,7 @@ CamelMimeFilterToHTML
 
 @in: 
 @flags: 
- colour: 
+ color: 
 @Returns: 
 
 
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml b/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml
index 8472ac1..a82467f 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml
@@ -22,9 +22,6 @@ CamelMimeFilterWindows
 
 </para>
 
- parent: 
- is_windows: 
- claimed_charset: 
 
 <!-- ##### 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 03a0abc..b532a44 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-yenc.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-yenc.sgml
@@ -22,12 +22,6 @@ CamelMimeFilterYenc
 
 </para>
 
- parent_object: 
- direction: 
- part: 
- state: 
- pcrc: 
- crc: 
 
 <!-- ##### ENUM CamelMimeFilterYencDirection ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter.sgml b/docs/reference/camel/tmpl/camel-mime-filter.sgml
index 13572c9..f96d7d6 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter.sgml
@@ -22,16 +22,6 @@ CamelMimeFilter
 
 </para>
 
- parent: 
- priv: 
- outreal: 
- outbuf: 
- outptr: 
- outsize: 
- outpre: 
- backbuf: 
- backsize: 
- backlen: 
 
 <!-- ##### FUNCTION camel_mime_filter_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-message.sgml b/docs/reference/camel/tmpl/camel-mime-message.sgml
index a94a8a9..f7b6ed6 100644
--- a/docs/reference/camel/tmpl/camel-mime-message.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-message.sgml
@@ -22,16 +22,6 @@ CamelMimeMessage
 
 </para>
 
- parent_object: 
- date: 
- date_offset: 
- date_received: 
- date_received_offset: 
- subject: 
- message_id: 
- reply_to: 
- from: 
- recipients: 
 
 <!-- ##### MACRO CAMEL_RECIPIENT_TYPE_TO ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-parser.sgml b/docs/reference/camel/tmpl/camel-mime-parser.sgml
index 18a207c..d31c7bf 100644
--- a/docs/reference/camel/tmpl/camel-mime-parser.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-parser.sgml
@@ -22,8 +22,6 @@ CamelMimeParser
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### ENUM camel_mime_parser_state_t ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-part.sgml b/docs/reference/camel/tmpl/camel-mime-part.sgml
index d916d64..570c2b2 100644
--- a/docs/reference/camel/tmpl/camel-mime-part.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-part.sgml
@@ -22,15 +22,26 @@ CamelMimePart
 
 </para>
 
- parent_object: 
- headers: 
- description: 
- disposition: 
- content_id: 
- content_MD5: 
- content_location: 
- content_languages: 
- encoding: 
+
+<!-- ##### ARG CamelMimePart:content-id ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG CamelMimePart:content-md5 ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG CamelMimePart:description ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG CamelMimePart:disposition ##### -->
+<para>
+
+</para>
 
 <!-- ##### FUNCTION camel_mime_part_new ##### -->
 <para>
@@ -112,7 +123,7 @@ CamelMimePart
 @Returns: 
 
 
-<!-- ##### FUNCTION camel_mime_part_set_content_MD5 ##### -->
+<!-- ##### FUNCTION camel_mime_part_set_content_md5 ##### -->
 <para>
 
 </para>
@@ -121,7 +132,7 @@ CamelMimePart
 @md5sum: 
 
 
-<!-- ##### FUNCTION camel_mime_part_get_content_MD5 ##### -->
+<!-- ##### FUNCTION camel_mime_part_get_content_md5 ##### -->
 <para>
 
 </para>
@@ -202,6 +213,15 @@ CamelMimePart
 @Returns: 
 
 
+<!-- ##### FUNCTION camel_mime_part_get_raw_headers ##### -->
+<para>
+
+</para>
+
+ mime_part: 
+ Returns: 
+
+
 <!-- ##### FUNCTION camel_mime_part_construct_from_parser ##### -->
 <para>
 
diff --git a/docs/reference/camel/tmpl/camel-multipart-encrypted.sgml b/docs/reference/camel/tmpl/camel-multipart-encrypted.sgml
index 7dc230a..08650ed 100644
--- a/docs/reference/camel/tmpl/camel-multipart-encrypted.sgml
+++ b/docs/reference/camel/tmpl/camel-multipart-encrypted.sgml
@@ -22,11 +22,6 @@ CamelMultipartEncrypted
 
 </para>
 
- parent_object: 
- version: 
- content: 
- decrypted: 
- protocol: 
 
 <!-- ##### FUNCTION camel_multipart_encrypted_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-multipart-signed.sgml b/docs/reference/camel/tmpl/camel-multipart-signed.sgml
index 242f9b3..5b52b15 100644
--- a/docs/reference/camel/tmpl/camel-multipart-signed.sgml
+++ b/docs/reference/camel/tmpl/camel-multipart-signed.sgml
@@ -22,16 +22,6 @@ CamelMultipartSigned
 
 </para>
 
- parent_object: 
- content: 
- signature: 
- contentraw: 
- protocol: 
- micalg: 
- start1: 
- end1: 
- start2: 
- end2: 
 
 <!-- ##### FUNCTION camel_multipart_signed_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-multipart.sgml b/docs/reference/camel/tmpl/camel-multipart.sgml
index 90a1010..dbda444 100644
--- a/docs/reference/camel/tmpl/camel-multipart.sgml
+++ b/docs/reference/camel/tmpl/camel-multipart.sgml
@@ -22,10 +22,6 @@ CamelMultipart
 
 </para>
 
- parent_object: 
- parts: 
- preface: 
- postface: 
 
 <!-- ##### FUNCTION camel_multipart_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-nntp-address.sgml b/docs/reference/camel/tmpl/camel-nntp-address.sgml
index 7d49d8a..21b710f 100644
--- a/docs/reference/camel/tmpl/camel-nntp-address.sgml
+++ b/docs/reference/camel/tmpl/camel-nntp-address.sgml
@@ -22,8 +22,6 @@ CamelNNTPAddress
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### FUNCTION camel_nntp_address_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-nntp-store.sgml b/docs/reference/camel/tmpl/camel-nntp-store.sgml
index 54ee864..4eb41de 100644
--- a/docs/reference/camel/tmpl/camel-nntp-store.sgml
+++ b/docs/reference/camel/tmpl/camel-nntp-store.sgml
@@ -22,7 +22,7 @@ CamelNNTPStore
 
 </para>
 
- parent_object: 
+ parent: 
 @priv: 
 @extensions: 
 @posting_allowed: 
diff --git a/docs/reference/camel/tmpl/camel-object.sgml b/docs/reference/camel/tmpl/camel-object.sgml
index 34a8441..223de70 100644
--- a/docs/reference/camel/tmpl/camel-object.sgml
+++ b/docs/reference/camel/tmpl/camel-object.sgml
@@ -17,90 +17,11 @@ CamelObject
 <!-- ##### SECTION Stability_Level ##### -->
 
 
-<!-- ##### MACRO CAMEL_OBJECT_TRACK_INSTANCES ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### TYPEDEF CamelType ##### -->
-<para>
-
-</para>
-
-
 <!-- ##### STRUCT CamelObject ##### -->
 <para>
 
 </para>
 
- klass: 
- magic: 
- hooks: 
- ref_count: 
- flags: 
- next: 
- prev: 
-
-<!-- ##### MACRO CAMEL_CHECK_CAST ##### -->
-<para>
-
-</para>
-
- obj: 
- ctype: 
- ptype: 
-
-
-<!-- ##### MACRO CAMEL_CHECK_CLASS_CAST ##### -->
-<para>
-
-</para>
-
- klass: 
- ctype: 
- ptype: 
-
-
-<!-- ##### MACRO CAMEL_CHECK_TYPE ##### -->
-<para>
-
-</para>
-
- obj: 
- ctype: 
-
-
-<!-- ##### MACRO CAMEL_CHECK_CLASS_TYPE ##### -->
-<para>
-
-</para>
-
- klass: 
- ctype: 
-
-
-<!-- ##### VARIABLE camel_object_type ##### -->
-<para>
-
-</para>
-
-
-<!-- ##### MACRO CAMEL_OBJECT_TYPE ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### MACRO CAMEL_OBJECT_GET_TYPE ##### -->
-<para>
-
-</para>
-
- o: 
-
 
 <!-- ##### TYPEDEF CamelObjectHookID ##### -->
 <para>
@@ -117,59 +38,6 @@ CamelObject
 @value: 
 @name: 
 
-<!-- ##### VARIABLE camel_interface_type ##### -->
-<para>
-
-</para>
-
-
-<!-- ##### MACRO CAMEL_INTERFACE_TYPE ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### STRUCT CamelInterface ##### -->
-<para>
-
-</para>
-
- type: 
-
-<!-- ##### USER_FUNCTION CamelObjectClassInitFunc ##### -->
-<para>
-
-</para>
-
- Param1: 
-
-
-<!-- ##### USER_FUNCTION CamelObjectClassFinalizeFunc ##### -->
-<para>
-
-</para>
-
- Param1: 
-
-
-<!-- ##### USER_FUNCTION CamelObjectInitFunc ##### -->
-<para>
-
-</para>
-
- Param1: 
- Param2: 
-
-
-<!-- ##### USER_FUNCTION CamelObjectFinalizeFunc ##### -->
-<para>
-
-</para>
-
- Param1: 
-
-
 <!-- ##### USER_FUNCTION CamelObjectEventPrepFunc ##### -->
 <para>
 
@@ -190,82 +58,6 @@ CamelObject
 @Param3: 
 
 
-<!-- ##### MACRO CAMEL_INVALID_TYPE ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### ENUM CamelObjectFlags ##### -->
-<para>
-
-</para>
-
- CAMEL_OBJECT_DESTROY: 
-
-<!-- ##### FUNCTION camel_type_init ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### FUNCTION camel_type_register ##### -->
-<para>
-
-</para>
-
- parent: 
- name: 
- instance_size: 
- classfuncs_size: 
- class_init: 
- class_finalize: 
- instance_init: 
- instance_finalize: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_interface_register ##### -->
-<para>
-
-</para>
-
- parent: 
- name: 
- classfuncs_size: 
- class_init: 
- class_finalize: 
- Returns: 
-
-
-<!-- ##### MACRO camel_type_get_global_classfuncs ##### -->
-<para>
-
-</para>
-
- x: 
-
-
-<!-- ##### FUNCTION camel_type_to_name ##### -->
-<para>
-
-</para>
-
- type: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_name_to_type ##### -->
-<para>
-
-</para>
-
- name: 
- Returns: 
-
-
 <!-- ##### FUNCTION camel_object_class_add_event ##### -->
 <para>
 
@@ -276,108 +68,6 @@ CamelObject
 @prep: 
 
 
-<!-- ##### FUNCTION camel_object_class_add_interface ##### -->
-<para>
-
-</para>
-
- klass: 
- itype: 
-
-
-<!-- ##### FUNCTION camel_object_class_dump_tree ##### -->
-<para>
-
-</para>
-
- root: 
-
-
-<!-- ##### FUNCTION camel_object_cast ##### -->
-<para>
-
-</para>
-
- obj: 
- ctype: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_object_is ##### -->
-<para>
-
-</para>
-
- obj: 
- ctype: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_object_class_cast ##### -->
-<para>
-
-</para>
-
- klass: 
- ctype: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_object_class_is ##### -->
-<para>
-
-</para>
-
- klass: 
- ctype: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_interface_cast ##### -->
-<para>
-
-</para>
-
- klass: 
- ctype: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_interface_is ##### -->
-<para>
-
-</para>
-
- k: 
- ctype: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_object_new ##### -->
-<para>
-
-</para>
-
- type: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_object_ref ##### -->
-<para>
-
-</para>
-
- Param1: 
-
-
-<!-- ##### FUNCTION camel_object_unref ##### -->
-<para>
-
-</para>
-
- Param1: 
-
-
 <!-- ##### FUNCTION camel_object_hook_event ##### -->
 <para>
 
@@ -420,16 +110,6 @@ CamelObject
 @event_data: 
 
 
-<!-- ##### FUNCTION camel_object_get_interface ##### -->
-<para>
-
-</para>
-
- vo: 
- itype: 
- Returns: 
-
-
 <!-- ##### FUNCTION camel_object_set ##### -->
 <para>
 
@@ -556,7 +236,7 @@ CamelObject
 
 </para>
 
- vo: 
+ object: 
 @Returns: 
 
 
@@ -565,10 +245,10 @@ CamelObject
 
 </para>
 
- hash: 
- equal: 
- keycopy: 
- keyfree: 
+ key_hash_func: 
+ key_equal_func: 
+ key_copy_func: 
+ key_free_func: 
 @Returns: 
 
 
@@ -609,7 +289,7 @@ CamelObject
 
 @bag: 
 @key: 
- vo: 
+ object: 
 
 
 <!-- ##### FUNCTION camel_object_bag_abort ##### -->
@@ -627,8 +307,8 @@ CamelObject
 </para>
 
 @bag: 
- o: 
- newkey: 
+ object: 
+ new_key: 
 
 
 <!-- ##### FUNCTION camel_object_bag_list ##### -->
@@ -646,7 +326,7 @@ CamelObject
 </para>
 
 @bag: 
- o: 
+ object: 
 
 
 <!-- ##### FUNCTION camel_object_bag_destroy ##### -->
@@ -657,76 +337,3 @@ CamelObject
 @bag: 
 
 
-<!-- ##### MACRO CAMEL_MAKE_CLASS ##### -->
-<para>
-
-</para>
-
- type: 
- tname: 
- parent: 
- pname: 
-
-
-<!-- ##### STRUCT CamelIteratorVTable ##### -->
-<para>
-
-</para>
-
- free: 
- next: 
- reset: 
- length: 
-
-<!-- ##### STRUCT CamelIterator ##### -->
-<para>
-
-</para>
-
- klass: 
-
-<!-- ##### FUNCTION camel_iterator_new ##### -->
-<para>
-
-</para>
-
- klass: 
- size: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_iterator_free ##### -->
-<para>
-
-</para>
-
- it: 
-
-
-<!-- ##### FUNCTION camel_iterator_next ##### -->
-<para>
-
-</para>
-
- it: 
- ex: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_iterator_reset ##### -->
-<para>
-
-</para>
-
- it: 
-
-
-<!-- ##### FUNCTION camel_iterator_length ##### -->
-<para>
-
-</para>
-
- it: 
- Returns: 
-
-
diff --git a/docs/reference/camel/tmpl/camel-offline-folder.sgml b/docs/reference/camel/tmpl/camel-offline-folder.sgml
index c7a05ba..250e5f2 100644
--- a/docs/reference/camel/tmpl/camel-offline-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-offline-folder.sgml
@@ -22,8 +22,6 @@ CamelOfflineFolder
 
 </para>
 
- parent_object: 
- sync_offline: 
 
 <!-- ##### FUNCTION camel_offline_folder_downsync ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-offline-journal.sgml b/docs/reference/camel/tmpl/camel-offline-journal.sgml
index 19d2e61..9d732d7 100644
--- a/docs/reference/camel/tmpl/camel-offline-journal.sgml
+++ b/docs/reference/camel/tmpl/camel-offline-journal.sgml
@@ -22,10 +22,6 @@ CamelOfflineJournal
 
 </para>
 
- parent_object: 
- folder: 
- filename: 
- queue: 
 
 <!-- ##### STRUCT CamelOfflineJournalEntry ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-offline-store.sgml b/docs/reference/camel/tmpl/camel-offline-store.sgml
index 820ad34..728e593 100644
--- a/docs/reference/camel/tmpl/camel-offline-store.sgml
+++ b/docs/reference/camel/tmpl/camel-offline-store.sgml
@@ -22,8 +22,6 @@ CamelOfflineStore
 
 </para>
 
- parent_object: 
- state: 
 
 <!-- ##### FUNCTION camel_offline_store_set_network_state ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-partition-table.sgml b/docs/reference/camel/tmpl/camel-partition-table.sgml
index b9eaafc..8f600d7 100644
--- a/docs/reference/camel/tmpl/camel-partition-table.sgml
+++ b/docs/reference/camel/tmpl/camel-partition-table.sgml
@@ -56,13 +56,6 @@ CamelKeyTable
 
 </para>
 
- parent: 
- priv: 
- blocks: 
- rootid: 
- is_key: 
- is_key_data: 
- partition: 
 
 <!-- ##### FUNCTION camel_partition_table_new ##### -->
 <para>
@@ -149,12 +142,6 @@ CamelKeyTable
 
 </para>
 
- parent: 
- priv: 
- blocks: 
- rootid: 
- root: 
- root_block: 
 
 <!-- ##### FUNCTION camel_key_table_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-pop3-folder.sgml b/docs/reference/camel/tmpl/camel-pop3-folder.sgml
index df381a8..2ceb77d 100644
--- a/docs/reference/camel/tmpl/camel-pop3-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-pop3-folder.sgml
@@ -22,7 +22,7 @@ CamelPOP3Folder
 
 </para>
 
- parent_object: 
+ parent: 
 @uids: 
 @uids_uid: 
 @uids_id: 
diff --git a/docs/reference/camel/tmpl/camel-pop3-store.sgml b/docs/reference/camel/tmpl/camel-pop3-store.sgml
index be61008..89cf08b 100644
--- a/docs/reference/camel/tmpl/camel-pop3-store.sgml
+++ b/docs/reference/camel/tmpl/camel-pop3-store.sgml
@@ -22,7 +22,7 @@ CamelPOP3Store
 
 </para>
 
- parent_object: 
+ parent: 
 @engine: 
 @cache: 
 @delete_after: 
diff --git a/docs/reference/camel/tmpl/camel-sasl-anonymous.sgml b/docs/reference/camel/tmpl/camel-sasl-anonymous.sgml
index edee1ba..9653859 100644
--- a/docs/reference/camel/tmpl/camel-sasl-anonymous.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-anonymous.sgml
@@ -22,9 +22,6 @@ CamelSaslAnonymous
 
 </para>
 
- parent_object: 
- trace_info: 
- type: 
 
 <!-- ##### ENUM CamelSaslAnonTraceType ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml b/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml
index 31c338d..b4e39dc 100644
--- a/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml
@@ -22,7 +22,6 @@ CamelSaslCramMd5
 
 </para>
 
- parent_object: 
 
 <!-- ##### VARIABLE camel_sasl_cram_md5_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-digest-md5.sgml b/docs/reference/camel/tmpl/camel-sasl-digest-md5.sgml
index 7506ebb..d1d54f7 100644
--- a/docs/reference/camel/tmpl/camel-sasl-digest-md5.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-digest-md5.sgml
@@ -22,8 +22,6 @@ CamelSaslDigestMd5
 
 </para>
 
- parent_object: 
- priv: 
 
 <!-- ##### VARIABLE camel_sasl_digest_md5_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-gssapi.sgml b/docs/reference/camel/tmpl/camel-sasl-gssapi.sgml
index 0dafc3e..bf2d7b4 100644
--- a/docs/reference/camel/tmpl/camel-sasl-gssapi.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-gssapi.sgml
@@ -22,8 +22,6 @@ CamelSaslGssapi
 
 </para>
 
- parent_object: 
- priv: 
 
 <!-- ##### VARIABLE camel_sasl_gssapi_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-login.sgml b/docs/reference/camel/tmpl/camel-sasl-login.sgml
index a111667..55f4dc8 100644
--- a/docs/reference/camel/tmpl/camel-sasl-login.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-login.sgml
@@ -22,8 +22,6 @@ CamelSaslLogin
 
 </para>
 
- parent_object: 
- priv: 
 
 <!-- ##### VARIABLE camel_sasl_login_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml b/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml
index 848a31d..e475b80 100644
--- a/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml
@@ -22,7 +22,6 @@ CamelSaslNTLM
 
 </para>
 
- parent_object: 
 
 <!-- ##### 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 b498726..3e1feb5 100644
--- a/docs/reference/camel/tmpl/camel-sasl-plain.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-plain.sgml
@@ -22,7 +22,6 @@ CamelSaslPlain
 
 </para>
 
- parent_object: 
 
 <!-- ##### 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 d2e8d14..ac9ae62 100644
--- a/docs/reference/camel/tmpl/camel-sasl-popb4smtp.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-popb4smtp.sgml
@@ -22,7 +22,6 @@ CamelSaslPOPB4SMTP
 
 </para>
 
- parent_object: 
 
 <!-- ##### 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 4b88f41..13fff82 100644
--- a/docs/reference/camel/tmpl/camel-sasl.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl.sgml
@@ -22,11 +22,26 @@ CamelSasl
 
 </para>
 
- parent_object: 
- service_name: 
- mech: 
- service: 
- authenticated: 
+
+<!-- ##### ARG CamelSasl:authenticated ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG CamelSasl:mechanism ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG CamelSasl:service ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG CamelSasl:service-name ##### -->
+<para>
+
+</para>
 
 <!-- ##### FUNCTION camel_sasl_challenge ##### -->
 <para>
@@ -50,7 +65,18 @@ CamelSasl
 @Returns: 
 
 
-<!-- ##### FUNCTION camel_sasl_authenticated ##### -->
+<!-- ##### FUNCTION camel_sasl_new ##### -->
+<para>
+
+</para>
+
+ service_name: 
+ mechanism: 
+ service: 
+ Returns: 
+
+
+<!-- ##### FUNCTION camel_sasl_get_authenticated ##### -->
 <para>
 
 </para>
@@ -59,14 +85,39 @@ CamelSasl
 @Returns: 
 
 
-<!-- ##### FUNCTION camel_sasl_new ##### -->
+<!-- ##### FUNCTION camel_sasl_set_authenticated ##### -->
 <para>
 
 </para>
 
- service_name: 
- mechanism: 
- service: 
+ sasl: 
+ authenticated: 
+
+
+<!-- ##### FUNCTION camel_sasl_get_mechanism ##### -->
+<para>
+
+</para>
+
+ sasl: 
+ Returns: 
+
+
+<!-- ##### FUNCTION camel_sasl_get_service ##### -->
+<para>
+
+</para>
+
+ sasl: 
+ Returns: 
+
+
+<!-- ##### FUNCTION camel_sasl_get_service_name ##### -->
+<para>
+
+</para>
+
+ sasl: 
 @Returns: 
 
 
diff --git a/docs/reference/camel/tmpl/camel-seekable-stream.sgml b/docs/reference/camel/tmpl/camel-seekable-stream.sgml
index 7cee441..b12cddb 100644
--- a/docs/reference/camel/tmpl/camel-seekable-stream.sgml
+++ b/docs/reference/camel/tmpl/camel-seekable-stream.sgml
@@ -22,10 +22,6 @@ CamelSeekableStream
 
 </para>
 
- parent_object: 
- position: 
- bound_start: 
- bound_end: 
 
 <!-- ##### ENUM CamelStreamSeekPolicy ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-seekable-substream.sgml b/docs/reference/camel/tmpl/camel-seekable-substream.sgml
index 5fb25a1..d2b9ef3 100644
--- a/docs/reference/camel/tmpl/camel-seekable-substream.sgml
+++ b/docs/reference/camel/tmpl/camel-seekable-substream.sgml
@@ -22,8 +22,6 @@ CamelSeekableSubstream
 
 </para>
 
- parent_object: 
- parent_stream: 
 
 <!-- ##### FUNCTION camel_seekable_substream_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sendmail-transport.sgml b/docs/reference/camel/tmpl/camel-sendmail-transport.sgml
index 045783e..1fefb78 100644
--- a/docs/reference/camel/tmpl/camel-sendmail-transport.sgml
+++ b/docs/reference/camel/tmpl/camel-sendmail-transport.sgml
@@ -22,5 +22,5 @@ CamelSendmailTransport
 
 </para>
 
- parent_object: 
+ parent: 
 
diff --git a/docs/reference/camel/tmpl/camel-service.sgml b/docs/reference/camel/tmpl/camel-service.sgml
index 9b34608..b384dcb 100644
--- a/docs/reference/camel/tmpl/camel-service.sgml
+++ b/docs/reference/camel/tmpl/camel-service.sgml
@@ -22,13 +22,6 @@ CamelService
 
 </para>
 
- parent_object: 
- priv: 
- session: 
- provider: 
- status: 
- connect_op: 
- url: 
 
 <!-- ##### MACRO CAMEL_SERVICE_USERNAME ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-session.sgml b/docs/reference/camel/tmpl/camel-session.sgml
index 3f97907..e868e6a 100644
--- a/docs/reference/camel/tmpl/camel-session.sgml
+++ b/docs/reference/camel/tmpl/camel-session.sgml
@@ -22,13 +22,6 @@ CamelSession
 
 </para>
 
- parent_object: 
- priv: 
- storage_path: 
- junk_plugin: 
- online: 
- check_junk: 
- network_state: 
 
 <!-- ##### USER_FUNCTION CamelTimeoutCallback ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-smime-context.sgml b/docs/reference/camel/tmpl/camel-smime-context.sgml
index d5996c5..78c3220 100644
--- a/docs/reference/camel/tmpl/camel-smime-context.sgml
+++ b/docs/reference/camel/tmpl/camel-smime-context.sgml
@@ -22,8 +22,6 @@ CamelSMIMEContext
 
 </para>
 
- cipher: 
- priv: 
 
 <!-- ##### ENUM camel_smime_sign_t ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-smtp-transport.sgml b/docs/reference/camel/tmpl/camel-smtp-transport.sgml
index 1494d85..925b323 100644
--- a/docs/reference/camel/tmpl/camel-smtp-transport.sgml
+++ b/docs/reference/camel/tmpl/camel-smtp-transport.sgml
@@ -22,7 +22,7 @@ CamelSmtpTransport
 
 </para>
 
- parent_object: 
+ parent: 
 @istream: 
 @ostream: 
 @flags: 
diff --git a/docs/reference/camel/tmpl/camel-spool-store.sgml b/docs/reference/camel/tmpl/camel-spool-store.sgml
index 2cd5cb7..34183a7 100644
--- a/docs/reference/camel/tmpl/camel-spool-store.sgml
+++ b/docs/reference/camel/tmpl/camel-spool-store.sgml
@@ -22,7 +22,7 @@ CamelSpoolStore
 
 </para>
 
- parent_object: 
+ parent: 
 @type: 
 
 <!-- ##### ENUM camel_spool_store_t ##### -->
diff --git a/docs/reference/camel/tmpl/camel-store-summary.sgml b/docs/reference/camel/tmpl/camel-store-summary.sgml
index e98a3d2..4886fa4 100644
--- a/docs/reference/camel/tmpl/camel-store-summary.sgml
+++ b/docs/reference/camel/tmpl/camel-store-summary.sgml
@@ -53,18 +53,6 @@ CamelStoreSummary
 
 </para>
 
- parent: 
- priv: 
- version: 
- flags: 
- count: 
- time: 
- uri_base: 
- store_info_size: 
- store_info_chunks: 
- summary_path: 
- folders: 
- folders_path: 
 
 <!-- ##### MACRO CAMEL_STORE_INFO_FOLDER_UNKNOWN ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-store.sgml b/docs/reference/camel/tmpl/camel-store.sgml
index 7846821..f531d09 100644
--- a/docs/reference/camel/tmpl/camel-store.sgml
+++ b/docs/reference/camel/tmpl/camel-store.sgml
@@ -22,14 +22,6 @@ CamelStore
 
 </para>
 
- parent_object: 
- priv: 
- folders: 
- cdb_r: 
- cdb_w: 
- flags: 
- mode: 
- later: 
 
 <!-- ##### STRUCT CamelFolderInfo ##### -->
 <para>
@@ -537,43 +529,3 @@ CamelStore
 @Returns: 
 
 
-<!-- ##### STRUCT CamelISubscribe ##### -->
-<para>
-
-</para>
-
- iface: 
- subscribed: 
- subscribe: 
- unsubscribe: 
-
-<!-- ##### FUNCTION camel_isubscribe_subscribed ##### -->
-<para>
-
-</para>
-
- store: 
- name: 
- Returns: 
-
-
-<!-- ##### FUNCTION camel_isubscribe_subscribe ##### -->
-<para>
-
-</para>
-
- store: 
- folder_name: 
- ex: 
-
-
-<!-- ##### FUNCTION camel_isubscribe_unsubscribe ##### -->
-<para>
-
-</para>
-
- store: 
- folder_name: 
- ex: 
-
-
diff --git a/docs/reference/camel/tmpl/camel-stream-buffer.sgml b/docs/reference/camel/tmpl/camel-stream-buffer.sgml
index b4b17c0..35348b7 100644
--- a/docs/reference/camel/tmpl/camel-stream-buffer.sgml
+++ b/docs/reference/camel/tmpl/camel-stream-buffer.sgml
@@ -22,16 +22,6 @@ CamelStreamBuffer
 
 </para>
 
- parent_object: 
- stream: 
- buf: 
- ptr: 
- end: 
- size: 
- linebuf: 
- linesize: 
- mode: 
- flags: 
 
 <!-- ##### ENUM CamelStreamBufferMode ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-stream-filter.sgml b/docs/reference/camel/tmpl/camel-stream-filter.sgml
index 1b804c6..3f6e8e3 100644
--- a/docs/reference/camel/tmpl/camel-stream-filter.sgml
+++ b/docs/reference/camel/tmpl/camel-stream-filter.sgml
@@ -22,16 +22,13 @@ CamelStreamFilter
 
 </para>
 
- parent: 
- source: 
- priv: 
 
-<!-- ##### FUNCTION camel_stream_filter_new_with_stream ##### -->
+<!-- ##### FUNCTION camel_stream_filter_new ##### -->
 <para>
 
 </para>
 
- stream: 
+ source: 
 @Returns: 
 
 
@@ -54,3 +51,12 @@ CamelStreamFilter
 @id: 
 
 
+<!-- ##### FUNCTION camel_stream_filter_get_source ##### -->
+<para>
+
+</para>
+
+ stream: 
+ Returns: 
+
+
diff --git a/docs/reference/camel/tmpl/camel-stream-fs.sgml b/docs/reference/camel/tmpl/camel-stream-fs.sgml
index 50b07a0..8947ca6 100644
--- a/docs/reference/camel/tmpl/camel-stream-fs.sgml
+++ b/docs/reference/camel/tmpl/camel-stream-fs.sgml
@@ -22,8 +22,6 @@ CamelStreamFs
 
 </para>
 
- parent_object: 
- fd: 
 
 <!-- ##### FUNCTION camel_stream_fs_new_with_name ##### -->
 <para>
@@ -69,3 +67,12 @@ CamelStreamFs
 @Returns: 
 
 
+<!-- ##### FUNCTION camel_stream_fs_get_fd ##### -->
+<para>
+
+</para>
+
+ stream: 
+ Returns: 
+
+
diff --git a/docs/reference/camel/tmpl/camel-stream-mem.sgml b/docs/reference/camel/tmpl/camel-stream-mem.sgml
index a919438..42a46c2 100644
--- a/docs/reference/camel/tmpl/camel-stream-mem.sgml
+++ b/docs/reference/camel/tmpl/camel-stream-mem.sgml
@@ -22,10 +22,6 @@ CamelStreamMem
 
 </para>
 
- parent_object: 
- owner: 
- secure: 
- buffer: 
 
 <!-- ##### FUNCTION camel_stream_mem_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-stream-null.sgml b/docs/reference/camel/tmpl/camel-stream-null.sgml
index 2c5a847..43c9a29 100644
--- a/docs/reference/camel/tmpl/camel-stream-null.sgml
+++ b/docs/reference/camel/tmpl/camel-stream-null.sgml
@@ -22,8 +22,6 @@ CamelStreamNull
 
 </para>
 
- parent: 
- written: 
 
 <!-- ##### FUNCTION camel_stream_null_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-stream-process.sgml b/docs/reference/camel/tmpl/camel-stream-process.sgml
index f8b5172..b5c6d1d 100644
--- a/docs/reference/camel/tmpl/camel-stream-process.sgml
+++ b/docs/reference/camel/tmpl/camel-stream-process.sgml
@@ -22,9 +22,6 @@ CamelStreamProcess
 
 </para>
 
- parent: 
- sockfd: 
- childpid: 
 
 <!-- ##### FUNCTION camel_stream_process_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-stream-vfs.sgml b/docs/reference/camel/tmpl/camel-stream-vfs.sgml
index 834e3ec..f984d8a 100644
--- a/docs/reference/camel/tmpl/camel-stream-vfs.sgml
+++ b/docs/reference/camel/tmpl/camel-stream-vfs.sgml
@@ -22,8 +22,6 @@ CamelStreamVFS
 
 </para>
 
- parent_object: 
- stream: 
 
 <!-- ##### ENUM CamelStreamVFSOpenMethod ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-stream.sgml b/docs/reference/camel/tmpl/camel-stream.sgml
index 62b03ee..109f381 100644
--- a/docs/reference/camel/tmpl/camel-stream.sgml
+++ b/docs/reference/camel/tmpl/camel-stream.sgml
@@ -22,8 +22,6 @@ CamelStream
 
 </para>
 
- parent_object: 
- eos: 
 
 <!-- ##### FUNCTION camel_stream_read ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-tcp-stream-raw.sgml b/docs/reference/camel/tmpl/camel-tcp-stream-raw.sgml
index aaa7090..e78b311 100644
--- a/docs/reference/camel/tmpl/camel-tcp-stream-raw.sgml
+++ b/docs/reference/camel/tmpl/camel-tcp-stream-raw.sgml
@@ -22,9 +22,6 @@ CamelTcpStreamRaw
 
 </para>
 
- parent_object: 
- sockfd: 
- is_nonblocking: 
 
 <!-- ##### FUNCTION camel_tcp_stream_raw_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-tcp-stream-ssl.sgml b/docs/reference/camel/tmpl/camel-tcp-stream-ssl.sgml
index 28e00ef..fe52536 100644
--- a/docs/reference/camel/tmpl/camel-tcp-stream-ssl.sgml
+++ b/docs/reference/camel/tmpl/camel-tcp-stream-ssl.sgml
@@ -22,8 +22,6 @@ CamelTcpStreamSSL
 
 </para>
 
- parent_object: 
- priv: 
 
 <!-- ##### MACRO CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-tcp-stream.sgml b/docs/reference/camel/tmpl/camel-tcp-stream.sgml
index 3ef788c..4ddafee 100644
--- a/docs/reference/camel/tmpl/camel-tcp-stream.sgml
+++ b/docs/reference/camel/tmpl/camel-tcp-stream.sgml
@@ -22,7 +22,6 @@ CamelTcpStream
 
 </para>
 
- parent_object: 
 
 <!-- ##### ENUM CamelSockOpt ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-text-index.sgml b/docs/reference/camel/tmpl/camel-text-index.sgml
index faa0037..ab4bb90 100644
--- a/docs/reference/camel/tmpl/camel-text-index.sgml
+++ b/docs/reference/camel/tmpl/camel-text-index.sgml
@@ -32,32 +32,24 @@ CamelTextIndex
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### STRUCT CamelTextIndexCursor ##### -->
 <para>
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### STRUCT CamelTextIndexKeyCursor ##### -->
 <para>
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### STRUCT CamelTextIndexName ##### -->
 <para>
 
 </para>
 
- parent: 
- priv: 
 
 <!-- ##### FUNCTION camel_text_index_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-transport.sgml b/docs/reference/camel/tmpl/camel-transport.sgml
index 7e2370d..4f43ce0 100644
--- a/docs/reference/camel/tmpl/camel-transport.sgml
+++ b/docs/reference/camel/tmpl/camel-transport.sgml
@@ -22,8 +22,6 @@ CamelTransport
 
 </para>
 
- parent_object: 
- priv: 
 
 <!-- ##### FUNCTION camel_transport_send_to ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-unused.sgml b/docs/reference/camel/tmpl/camel-unused.sgml
index f578a14..dd988ae 100644
--- a/docs/reference/camel/tmpl/camel-unused.sgml
+++ b/docs/reference/camel/tmpl/camel-unused.sgml
@@ -230,6 +230,40 @@ camel-search-sql-sexp.h
 camel-types
 
 
+<!-- ##### MACRO CAMEL_CHECK_CAST ##### -->
+<para>
+
+</para>
+
+ instance: 
+ g_type: 
+ c_type: 
+
+<!-- ##### MACRO CAMEL_CHECK_CLASS_CAST ##### -->
+<para>
+
+</para>
+
+ g_class: 
+ g_type: 
+ c_type: 
+
+<!-- ##### MACRO CAMEL_CHECK_CLASS_TYPE ##### -->
+<para>
+
+</para>
+
+ g_class: 
+ g_type: 
+
+<!-- ##### MACRO CAMEL_CHECK_TYPE ##### -->
+<para>
+
+</para>
+
+ instance: 
+ g_type: 
+
 <!-- ##### MACRO CAMEL_GROUPWISE_FOLDER_LOCK ##### -->
 <para>
 
@@ -284,6 +318,18 @@ camel-types
 @f: 
 @l: 
 
+<!-- ##### MACRO CAMEL_INTERFACE_TYPE ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### MACRO CAMEL_INVALID_TYPE ##### -->
+<para>
+
+</para>
+
+
 <!-- ##### MACRO CAMEL_LOCAL_FOLDER_LOCK ##### -->
 <para>
 
@@ -300,6 +346,16 @@ camel-types
 @f: 
 @l: 
 
+<!-- ##### MACRO CAMEL_MAKE_CLASS ##### -->
+<para>
+
+</para>
+
+ type: 
+ tname: 
+ parent: 
+ pname: 
+
 <!-- ##### MACRO CAMEL_NNTP_FOLDER_LOCK ##### -->
 <para>
 
@@ -332,6 +388,59 @@ camel-types
 @f: 
 @l: 
 
+<!-- ##### MACRO CAMEL_OBJECT_GET_TYPE ##### -->
+<para>
+
+</para>
+
+ object: 
+
+<!-- ##### MACRO CAMEL_OBJECT_TRACK_INSTANCES ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### MACRO CAMEL_OBJECT_TYPE ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SIGNAL CamelFolder::deleted ##### -->
+<para>
+
+</para>
+
+ camelfolder: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelFolder::folder-changed ##### -->
+<para>
+
+</para>
+
+ camelfolder: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelFolder::renamed ##### -->
+<para>
+
+</para>
+
+ camelfolder: the object which received the signal.
+ arg1: 
+
+<!-- ##### STRUCT CamelISubscribe ##### -->
+<para>
+
+</para>
+
+ iface: 
+ subscribed: 
+ subscribe: 
+ unsubscribe: 
+
 <!-- ##### STRUCT CamelImapFolderPrivate ##### -->
 <para>
 
@@ -345,6 +454,29 @@ camel-types
 </para>
 
 
+<!-- ##### STRUCT CamelInterface ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### STRUCT CamelIterator ##### -->
+<para>
+
+</para>
+
+ klass: 
+
+<!-- ##### STRUCT CamelIteratorVTable ##### -->
+<para>
+
+</para>
+
+ free: 
+ next: 
+ reset: 
+ length: 
+
 <!-- ##### STRUCT CamelLocalFolderPrivate ##### -->
 <para>
 
@@ -411,18 +543,127 @@ camel-types
 
 @dummy: 
 
+<!-- ##### SIGNAL CamelObject::finalize ##### -->
+<para>
+
+</para>
+
+ camelobject: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelObject::meta-changed ##### -->
+<para>
+
+</para>
+
+ camelobject: the object which received the signal.
+ arg1: 
+
+<!-- ##### TYPEDEF CamelObjectClassFinalizeFunc ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### TYPEDEF CamelObjectClassInitFunc ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### TYPEDEF CamelObjectFinalizeFunc ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### ENUM CamelObjectFlags ##### -->
+<para>
+
+</para>
+
+ CAMEL_OBJECT_DESTROY: 
+
+<!-- ##### TYPEDEF CamelObjectInitFunc ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SIGNAL CamelSession::online ##### -->
+<para>
+
+</para>
+
+ camelsession: the object which received the signal.
+ arg1: 
+
 <!-- ##### STRUCT CamelSimpleDataWrapper ##### -->
 <para>
 
 </para>
 
 
+<!-- ##### SIGNAL CamelStore::folder-created ##### -->
+<para>
+
+</para>
+
+ camelstore: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelStore::folder-deleted ##### -->
+<para>
+
+</para>
+
+ camelstore: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelStore::folder-opened ##### -->
+<para>
+
+</para>
+
+ camelstore: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelStore::folder-renamed ##### -->
+<para>
+
+</para>
+
+ camelstore: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelStore::folder-subscribed ##### -->
+<para>
+
+</para>
+
+ camelstore: the object which received the signal.
+ arg1: 
+
+<!-- ##### SIGNAL CamelStore::folder-unsubscribed ##### -->
+<para>
+
+</para>
+
+ camelstore: the object which received the signal.
+ arg1: 
+
 <!-- ##### STRUCT CamelStreamDataWrapper ##### -->
 <para>
 
 </para>
 
 
+<!-- ##### TYPEDEF CamelType ##### -->
+<para>
+
+</para>
+
+
 <!-- ##### MACRO NI_MAXHOST ##### -->
 <para>
 
@@ -466,6 +707,14 @@ camel-types
 
 @Returns: 
 
+<!-- ##### FUNCTION camel_cipher_context_construct ##### -->
+<para>
+
+</para>
+
+ context: 
+ session: 
+
 <!-- ##### FUNCTION camel_file_util_decode_size_t ##### -->
 <para>
 
@@ -517,6 +766,42 @@ camel-types
 
 @Returns: 
 
+<!-- ##### MACRO camel_interface_cast ##### -->
+<para>
+
+</para>
+
+ g_class: 
+ g_type: 
+ Returns: 
+
+<!-- ##### MACRO camel_interface_is ##### -->
+<para>
+
+</para>
+
+ g_class: 
+ g_type: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_interface_register ##### -->
+<para>
+
+</para>
+
+ parent: 
+ name: 
+ classfuncs_size: 
+ class_init: 
+ class_finalize: 
+ Returns: 
+
+<!-- ##### VARIABLE camel_interface_type ##### -->
+<para>
+
+</para>
+
+
 <!-- ##### FUNCTION camel_isubscribe_get_type ##### -->
 <para>
 
@@ -524,6 +809,73 @@ camel-types
 
 @Returns: 
 
+<!-- ##### FUNCTION camel_isubscribe_subscribe ##### -->
+<para>
+
+</para>
+
+ store: 
+ folder_name: 
+ ex: 
+
+<!-- ##### FUNCTION camel_isubscribe_subscribed ##### -->
+<para>
+
+</para>
+
+ store: 
+ name: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_isubscribe_unsubscribe ##### -->
+<para>
+
+</para>
+
+ store: 
+ folder_name: 
+ ex: 
+
+<!-- ##### FUNCTION camel_iterator_free ##### -->
+<para>
+
+</para>
+
+ it: 
+
+<!-- ##### FUNCTION camel_iterator_length ##### -->
+<para>
+
+</para>
+
+ it: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_iterator_new ##### -->
+<para>
+
+</para>
+
+ klass: 
+ size: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_iterator_next ##### -->
+<para>
+
+</para>
+
+ it: 
+ ex: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_iterator_reset ##### -->
+<para>
+
+</para>
+
+ it: 
+
 <!-- ##### FUNCTION camel_key_file_get_type ##### -->
 <para>
 
@@ -579,6 +931,147 @@ camel-types
 @buf: 
 @len: 
 
+<!-- ##### FUNCTION camel_medium_get_content_object ##### -->
+<para>
+
+</para>
+
+ medium: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_medium_set_content_object ##### -->
+<para>
+
+</para>
+
+ medium: 
+ content: 
+
+<!-- ##### FUNCTION camel_mime_filter_basic_new_type ##### -->
+<para>
+
+</para>
+
+ type: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_mime_filter_charset_new_convert ##### -->
+<para>
+
+</para>
+
+ from_charset: 
+ to_charset: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_mime_filter_index_new_index ##### -->
+<para>
+
+</para>
+
+ index: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_mime_filter_save_new_with_stream ##### -->
+<para>
+
+</para>
+
+ stream: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_mime_part_get_content_MD5 ##### -->
+<para>
+
+</para>
+
+ mime_part: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_mime_part_set_content_MD5 ##### -->
+<para>
+
+</para>
+
+ mime_part: 
+ md5sum: 
+
+<!-- ##### MACRO camel_name_to_type ##### -->
+<para>
+
+</para>
+
+ name: 
+ Returns: 
+
+<!-- ##### MACRO camel_object_cast ##### -->
+<para>
+
+</para>
+
+ instance: 
+ g_type: 
+ Returns: 
+
+<!-- ##### FUNCTION camel_object_class_add_interface ##### -->
+<para>
+
+</para>
+
+ klass: 
+ itype: 
+
+<!-- ##### MACRO camel_object_class_cast ##### -->
+<para>
+
+</para>
+
+ g_class: 
+ g_type: 
+ Returns: 
+
+<!-- ##### MACRO camel_object_class_dump_tree ##### -->
+<para>
+
+</para>
+
+ g_type: 
+
+<!-- ##### MACRO camel_object_class_is ##### -->
+<para>
+
+</para>
+
+ g_class: 
+ g_type: 
+ Returns: 
+
+<!-- ##### MACRO camel_object_get_interface ##### -->
+<para>
+
+</para>
+
+ instance: 
+ g_type: 
+ Returns: 
+
+<!-- ##### MACRO camel_object_is ##### -->
+<para>
+
+</para>
+
+ instance: 
+ g_type: 
+ Returns: 
+
+<!-- ##### MACRO camel_object_new ##### -->
+<para>
+
+</para>
+
+ type: 
+ Returns: 
+
 <!-- ##### FUNCTION camel_object_new_name ##### -->
 <para>
 
@@ -587,6 +1080,24 @@ camel-types
 @name: 
 @Returns: 
 
+<!-- ##### MACRO camel_object_ref ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### VARIABLE camel_object_type ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### MACRO camel_object_unref ##### -->
+<para>
+
+</para>
+
+
 <!-- ##### FUNCTION camel_partition_table_get_type ##### -->
 <para>
 
@@ -594,6 +1105,14 @@ camel-types
 
 @Returns: 
 
+<!-- ##### FUNCTION camel_sasl_authenticated ##### -->
+<para>
+
+</para>
+
+ sasl: 
+ Returns: 
+
 <!-- ##### FUNCTION camel_search_build_match_regex ##### -->
 <para>
 
@@ -695,6 +1214,14 @@ camel-types
 @type: 
 @words: 
 
+<!-- ##### FUNCTION camel_stream_filter_new_with_stream ##### -->
+<para>
+
+</para>
+
+ stream: 
+ Returns: 
+
 <!-- ##### FUNCTION camel_stream_vfs_new_with_handle ##### -->
 <para>
 
@@ -724,6 +1251,42 @@ camel-types
 
 @Returns: 
 
+<!-- ##### MACRO camel_type_get_global_classfuncs ##### -->
+<para>
+
+</para>
+
+ type: 
+
+<!-- ##### MACRO camel_type_init ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### FUNCTION camel_type_register ##### -->
+<para>
+
+</para>
+
+ parent: 
+ name: 
+ instance_size: 
+ classfuncs_size: 
+ class_init: 
+ class_finalize: 
+ instance_init: 
+ instance_finalize: 
+ Returns: 
+
+<!-- ##### MACRO camel_type_to_name ##### -->
+<para>
+
+</para>
+
+ g_class: 
+ Returns: 
+
 <!-- ##### FUNCTION camel_ustrstrcase ##### -->
 <para>
 
diff --git a/docs/reference/camel/tmpl/camel-vee-folder.sgml b/docs/reference/camel/tmpl/camel-vee-folder.sgml
index 8675cb2..2d24836 100644
--- a/docs/reference/camel/tmpl/camel-vee-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-vee-folder.sgml
@@ -22,16 +22,6 @@ CamelVeeFolder
 
 </para>
 
- parent: 
- priv: 
- expression: 
- flags: 
- changes: 
- search: 
- parent_vee_store: 
- hashes: 
- loaded: 
- deleted: 
 
 <!-- ##### MACRO CAMEL_UNMATCHED_NAME ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-vee-store.sgml b/docs/reference/camel/tmpl/camel-vee-store.sgml
index 723b730..61ae391 100644
--- a/docs/reference/camel/tmpl/camel-vee-store.sgml
+++ b/docs/reference/camel/tmpl/camel-vee-store.sgml
@@ -22,9 +22,6 @@ CamelVeeStore
 
 </para>
 
- parent: 
- folder_unmatched: 
- unmatched_uids: 
 
 <!-- ##### MACRO CAMEL_STORE_VEE_FOLDER_AUTO ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-vee-summary.sgml b/docs/reference/camel/tmpl/camel-vee-summary.sgml
index 969d25f..137b636 100644
--- a/docs/reference/camel/tmpl/camel-vee-summary.sgml
+++ b/docs/reference/camel/tmpl/camel-vee-summary.sgml
@@ -22,9 +22,6 @@ CamelVeeSummary
 
 </para>
 
- summary: 
- force_counts: 
- fake_visible_count: 
 
 <!-- ##### STRUCT CamelVeeMessageInfo ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-vtrash-folder.sgml b/docs/reference/camel/tmpl/camel-vtrash-folder.sgml
index b08bedd..d9783c6 100644
--- a/docs/reference/camel/tmpl/camel-vtrash-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-vtrash-folder.sgml
@@ -36,9 +36,6 @@ CamelVTrashFolder
 
 </para>
 
- parent: 
- type: 
- bit: 
 
 <!-- ##### ENUM camel_vtrash_folder_t ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/session.sgml b/docs/reference/camel/tmpl/session.sgml
index 01737fa..d0b01b6 100644
--- a/docs/reference/camel/tmpl/session.sgml
+++ b/docs/reference/camel/tmpl/session.sgml
@@ -22,7 +22,7 @@ CamelTestSession
 
 </para>
 
- parent_object: 
+ parent: 
 
 <!-- ##### FUNCTION camel_test_session_new ##### -->
 <para>



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