diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index 247c18f..f7ed376 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -27,7 +27,6 @@
 #endif
 
 #include <unistd.h>
-#include <pthread.h>
 #include <string.h>
 #include <glib/gi18n-lib.h>
 
diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c
index 673ff80..248d614 100644
--- a/camel/camel-block-file.c
+++ b/camel/camel-block-file.c
@@ -25,7 +25,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -51,21 +50,21 @@ struct _CamelBlockFilePrivate {
 
 	struct _CamelBlockFile *base;
 
-	pthread_mutex_t root_lock; /* for modifying the root block */
-	pthread_mutex_t cache_lock; /* for refcounting, flag manip, cache manip */
-	pthread_mutex_t io_lock; /* for all io ops */
+	GStaticMutex root_lock; /* for modifying the root block */
+	GStaticMutex cache_lock; /* for refcounting, flag manip, cache manip */
+	GStaticMutex io_lock; /* for all io ops */
 
 	guint deleted:1;
 };
 
-#define CAMEL_BLOCK_FILE_LOCK(kf, lock) (pthread_mutex_lock(&(kf)->priv->lock))
-#define CAMEL_BLOCK_FILE_TRYLOCK(kf, lock) (pthread_mutex_trylock(&(kf)->priv->lock))
-#define CAMEL_BLOCK_FILE_UNLOCK(kf, lock) (pthread_mutex_unlock(&(kf)->priv->lock))
+#define CAMEL_BLOCK_FILE_LOCK(kf, lock) (g_static_mutex_lock(&(kf)->priv->lock))
+#define CAMEL_BLOCK_FILE_TRYLOCK(kf, lock) (g_static_mutex_trylock(&(kf)->priv->lock))
+#define CAMEL_BLOCK_FILE_UNLOCK(kf, lock) (g_static_mutex_unlock(&(kf)->priv->lock))
 
-#define LOCK(x) pthread_mutex_lock(&x)
-#define UNLOCK(x) pthread_mutex_unlock(&x)
+#define LOCK(x) g_static_mutex_lock(&x)
+#define UNLOCK(x) g_static_mutex_unlock(&x)
 
-static pthread_mutex_t block_file_lock = PTHREAD_MUTEX_INITIALIZER;
+static GStaticMutex block_file_lock = G_STATIC_MUTEX_INIT;
 
 /* lru cache of block files */
 static CamelDList block_file_list = CAMEL_DLIST_INITIALISER(block_file_list);
@@ -172,9 +171,9 @@ camel_block_file_init(CamelBlockFile *bs)
 	p = bs->priv = g_malloc0(sizeof(*bs->priv));
 	p->base = bs;
 
-	pthread_mutex_init(&p->root_lock, NULL);
-	pthread_mutex_init(&p->cache_lock, NULL);
-	pthread_mutex_init(&p->io_lock, NULL);
+	g_static_mutex_init (&p->root_lock);
+	g_static_mutex_init (&p->cache_lock);
+	g_static_mutex_init (&p->io_lock);
 
 	/* link into lru list */
 	LOCK(block_file_lock);
@@ -231,9 +230,9 @@ camel_block_file_finalise(CamelBlockFile *bs)
 	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_static_mutex_free (&p->io_lock);
+	g_static_mutex_free (&p->cache_lock);
+	g_static_mutex_free (&p->root_lock);
 
 	g_free(p);
 }
@@ -306,9 +305,9 @@ block_file_use(CamelBlockFile *bs)
 		if (bf->fd != -1) {
 			/* Need to trylock, as any of these lock levels might be trying
 			   to lock the block_file_lock, so we need to check and abort if so */
-			if (CAMEL_BLOCK_FILE_TRYLOCK(bf, root_lock) == 0) {
-				if (CAMEL_BLOCK_FILE_TRYLOCK(bf, cache_lock) == 0) {
-					if (CAMEL_BLOCK_FILE_TRYLOCK(bf, io_lock) == 0) {
+			if (CAMEL_BLOCK_FILE_TRYLOCK (bf, root_lock)) {
+				if (CAMEL_BLOCK_FILE_TRYLOCK (bf, cache_lock)) {
+					if (CAMEL_BLOCK_FILE_TRYLOCK (bf, io_lock)) {
 						d(printf("[%d] Turning block file offline: %s\n", block_file_count-1, bf->path));
 						sync_nolock(bf);
 						close(bf->fd);
@@ -800,15 +799,15 @@ struct _CamelKeyFilePrivate {
 	struct _CamelKeyFilePrivate *prev;
 
 	struct _CamelKeyFile *base;
-	pthread_mutex_t lock;
+	GStaticMutex lock;
 	guint deleted:1;
 };
 
-#define CAMEL_KEY_FILE_LOCK(kf, lock) (pthread_mutex_lock(&(kf)->priv->lock))
-#define CAMEL_KEY_FILE_TRYLOCK(kf, lock) (pthread_mutex_trylock(&(kf)->priv->lock))
-#define CAMEL_KEY_FILE_UNLOCK(kf, lock) (pthread_mutex_unlock(&(kf)->priv->lock))
+#define CAMEL_KEY_FILE_LOCK(kf, lock) (g_static_mutex_lock(&(kf)->priv->lock))
+#define CAMEL_KEY_FILE_TRYLOCK(kf, lock) (g_static_mutex_trylock(&(kf)->priv->lock))
+#define CAMEL_KEY_FILE_UNLOCK(kf, lock) (g_static_mutex_unlock(&(kf)->priv->lock))
 
-static pthread_mutex_t key_file_lock = PTHREAD_MUTEX_INITIALIZER;
+static GStaticMutex key_file_lock = G_STATIC_MUTEX_INIT;
 
 /* lru cache of block files */
 static CamelDList key_file_list = CAMEL_DLIST_INITIALISER(key_file_list);
@@ -829,7 +828,7 @@ camel_key_file_init(CamelKeyFile *bs)
 	p = bs->priv = g_malloc0(sizeof(*bs->priv));
 	p->base = bs;
 
-	pthread_mutex_init(&p->lock, NULL);
+	g_static_mutex_init (&p->lock);
 
 	LOCK(key_file_lock);
 	camel_dlist_addhead(&key_file_list, (CamelDListNode *)p);
@@ -853,7 +852,7 @@ camel_key_file_finalise(CamelKeyFile *bs)
 
 	g_free(bs->path);
 
-	pthread_mutex_destroy(&p->lock);
+	g_static_mutex_free (&p->lock);
 
 	g_free(p);
 }
@@ -937,7 +936,7 @@ key_file_use(CamelKeyFile *bs)
 		if (bf->fp != NULL) {
 			/* Need to trylock, as any of these lock levels might be trying
 			   to lock the key_file_lock, so we need to check and abort if so */
-			if (CAMEL_BLOCK_FILE_TRYLOCK(bf, lock) == 0) {
+			if (CAMEL_BLOCK_FILE_TRYLOCK (bf, lock)) {
 				d(printf("Turning key file offline: %s\n", bf->path));
 				fclose(bf->fp);
 				bf->fp = NULL;
diff --git a/camel/camel-certdb.c b/camel/camel-certdb.c
index cce0fd6..5972b57 100644
--- a/camel/camel-certdb.c
+++ b/camel/camel-certdb.c
@@ -26,7 +26,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <pthread.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -154,12 +153,12 @@ camel_certdb_new (void)
 }
 
 static CamelCertDB *default_certdb = NULL;
-static pthread_mutex_t default_certdb_lock = PTHREAD_MUTEX_INITIALIZER;
+static GStaticMutex default_certdb_lock = G_STATIC_MUTEX_INIT;
 
 void
 camel_certdb_set_default (CamelCertDB *certdb)
 {
-	pthread_mutex_lock (&default_certdb_lock);
+	g_static_mutex_lock (&default_certdb_lock);
 
 	if (default_certdb)
 		camel_object_unref (default_certdb);
@@ -169,7 +168,7 @@ camel_certdb_set_default (CamelCertDB *certdb)
 
 	default_certdb = certdb;
 
-	pthread_mutex_unlock (&default_certdb_lock);
+	g_static_mutex_unlock (&default_certdb_lock);
 }
 
 CamelCertDB *
@@ -177,14 +176,14 @@ camel_certdb_get_default (void)
 {
 	CamelCertDB *certdb;
 
-	pthread_mutex_lock (&default_certdb_lock);
+	g_static_mutex_lock (&default_certdb_lock);
 
 	if (default_certdb)
 		camel_object_ref (default_certdb);
 
 	certdb = default_certdb;
 
-	pthread_mutex_unlock (&default_certdb_lock);
+	g_static_mutex_unlock (&default_certdb_lock);
 
 	return certdb;
 }
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c
index 252dc14..a860b7a 100644
--- a/camel/camel-data-wrapper.c
+++ b/camel/camel-data-wrapper.c
@@ -72,7 +72,7 @@ camel_data_wrapper_init (gpointer object, gpointer klass)
 	CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
 
 	camel_data_wrapper->priv = g_malloc (sizeof (struct _CamelDataWrapperPrivate));
-	pthread_mutex_init (&camel_data_wrapper->priv->stream_lock, NULL);
+	g_static_mutex_init (&camel_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;
@@ -84,7 +84,7 @@ camel_data_wrapper_finalize (CamelObject *object)
 {
 	CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
 
-	pthread_mutex_destroy (&camel_data_wrapper->priv->stream_lock);
+	g_static_mutex_free (&camel_data_wrapper->priv->stream_lock);
 
 	g_free (camel_data_wrapper->priv);
 
diff --git a/camel/camel-debug.c b/camel/camel-debug.c
index 91cf5cf..01f0028 100644
--- a/camel/camel-debug.c
+++ b/camel/camel-debug.c
@@ -19,13 +19,10 @@
  * USA
  */
 
-#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <libedataserver/e-data-server-util.h>
-
 #include "camel-debug.h"
 
 gint camel_verbose_debug;
@@ -118,7 +115,7 @@ gboolean camel_debug(const gchar *mode)
 	return FALSE;
 }
 
-static pthread_mutex_t debug_lock = PTHREAD_MUTEX_INITIALIZER;
+static GStaticMutex debug_lock = G_STATIC_MUTEX_INIT;
 /**
  * camel_debug_start:
  * @mode:
@@ -133,8 +130,8 @@ gboolean
 camel_debug_start(const gchar *mode)
 {
 	if (camel_debug(mode)) {
-		pthread_mutex_lock(&debug_lock);
-		printf("Thread %" G_GINT64_MODIFIER "x >\n", e_util_pthread_id(pthread_self()));
+		g_static_mutex_lock (&debug_lock);
+		printf ("Thread %p >\n", g_thread_self());
 		return TRUE;
 	}
 
@@ -150,8 +147,8 @@ camel_debug_start(const gchar *mode)
 void
 camel_debug_end(void)
 {
-	printf("< %" G_GINT64_MODIFIER "x >\n", e_util_pthread_id(pthread_self()));
-	pthread_mutex_unlock(&debug_lock);
+	printf ("< %p >\n", g_thread_self());
+	g_static_mutex_unlock (&debug_lock);
 }
 
 #if 0
diff --git a/camel/camel-exception.c b/camel/camel-exception.c
index d8c2980..22db7f5 100644
--- a/camel/camel-exception.c
+++ b/camel/camel-exception.c
@@ -26,7 +26,6 @@
 #endif
 
 #include <stdio.h>
-#include <pthread.h>
 
 #include <glib.h>
 #include <glib/gi18n-lib.h>
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 90a10e4..d73c702 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -28,7 +28,6 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <pthread.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -69,11 +68,11 @@
 #define SUMMARY_CACHE_DROP 300
 #define dd(x) if (camel_debug("sync")) x
 
-static pthread_mutex_t info_lock = PTHREAD_MUTEX_INITIALIZER;
+static GStaticMutex info_lock = G_STATIC_MUTEX_INIT;
 
 /* this lock is ONLY for the standalone messageinfo stuff */
-#define GLOBAL_INFO_LOCK(i) pthread_mutex_lock(&info_lock)
-#define GLOBAL_INFO_UNLOCK(i) pthread_mutex_unlock(&info_lock)
+#define GLOBAL_INFO_LOCK(i) g_static_mutex_lock(&info_lock)
+#define GLOBAL_INFO_UNLOCK(i) g_static_mutex_unlock(&info_lock)
 
 /* this should probably be conditional on it existing */
 #define USE_BSEARCH
diff --git a/camel/camel-lock-client.c b/camel/camel-lock-client.c
index 33c72ee..1dfe70b 100644
--- a/camel/camel-lock-client.c
+++ b/camel/camel-lock-client.c
@@ -25,7 +25,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -44,9 +43,9 @@
 /* see also camel-lock.c */
 #define _(x) (x)
 
-static pthread_mutex_t lock_lock = PTHREAD_MUTEX_INITIALIZER;
-#define LOCK() pthread_mutex_lock(&lock_lock)
-#define UNLOCK() pthread_mutex_unlock(&lock_lock)
+static GStaticMutex lock_lock = G_STATIC_MUTEX_INIT;
+#define LOCK() g_static_mutex_lock(&lock_lock)
+#define UNLOCK() g_static_mutex_unlock(&lock_lock)
 
 static gint lock_sequence;
 static gint lock_helper_pid = -1;
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index 51cb654..70be854 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -30,7 +30,6 @@
 #include <sys/types.h>
 #include <sys/param.h>  /* for MAXHOSTNAMELEN */
 #include <sys/stat.h>
-#include <pthread.h>
 #include <unistd.h>
 #include <regex.h>
 #include <fcntl.h>
@@ -4420,9 +4419,9 @@ camel_header_raw_clear(struct _camel_header_raw **list)
 gchar *
 camel_header_msgid_generate (void)
 {
-	static pthread_mutex_t count_lock = PTHREAD_MUTEX_INITIALIZER;
-#define COUNT_LOCK() pthread_mutex_lock (&count_lock)
-#define COUNT_UNLOCK() pthread_mutex_unlock (&count_lock)
+	static GStaticMutex count_lock = G_STATIC_MUTEX_INIT;
+#define COUNT_LOCK() g_static_mutex_lock (&count_lock)
+#define COUNT_UNLOCK() g_static_mutex_unlock (&count_lock)
 	gchar host[MAXHOSTNAMELEN];
 	const gchar *name;
 	static gint count = 0;
@@ -4504,10 +4503,8 @@ static struct {
 	{ "List-Unsubscribe", "<mailto:(.+)-unsubscribe@([^ \n\t\r>]*)" },
 };
 
-static pthread_once_t mailing_list_init_once = PTHREAD_ONCE_INIT;
-
-static void
-mailing_list_init(void)
+static gpointer
+mailing_list_init (gpointer param)
 {
 	gint i, errcode, failed=0;
 
@@ -4529,16 +4526,19 @@ mailing_list_init(void)
 	}
 
 	g_assert(failed == 0);
+
+	return NULL;
 }
 
 gchar *
 camel_header_raw_check_mailing_list(struct _camel_header_raw **list)
 {
+	static GOnce once = G_ONCE_INIT;
 	const gchar *v;
 	regmatch_t match[3];
 	gint i, j;
 
-	pthread_once(&mailing_list_init_once, mailing_list_init);
+	g_once (&once, mailing_list_init, NULL);
 
 	for (i = 0; i < G_N_ELEMENTS (mail_list_magic); i++) {
 		v = camel_header_raw_find (list, mail_list_magic[i].name, NULL);
diff --git a/camel/camel-net-utils.c b/camel/camel-net-utils.c
index d447e41..4320f52 100644
--- a/camel/camel-net-utils.c
+++ b/camel/camel-net-utils.c
@@ -26,7 +26,6 @@
 #endif
 
 #include <errno.h>
-#include <pthread.h>
 #include <stdio.h>
 
 #include <glib.h>
@@ -447,8 +446,9 @@ static gint
 cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar *error, CamelException *ex)
 {
 	CamelMsgPort *reply_port;
-	pthread_t id;
-	gint err, cancel_fd, cancel = 0, fd;
+	GThread *thread;
+	GError *err = NULL;
+	gint cancel_fd, cancel = 0, fd;
 
 	cancel_fd = camel_operation_cancel_fd(NULL);
 	if (cancel_fd == -1) {
@@ -458,7 +458,7 @@ cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar
 
 	reply_port = msg->msg.reply_port = camel_msgport_new();
 	fd = camel_msgport_fd(msg->msg.reply_port);
-	if ((err = pthread_create(&id, NULL, worker, msg)) == 0) {
+	if ((thread = g_thread_create (worker, msg, TRUE, &err)) != NULL) {
 		gint status;
 #ifndef G_OS_WIN32
 		GPollFD polls[2];
@@ -506,19 +506,20 @@ cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar
 			   We check the reply port incase we had a reply in the mean time, which we free later */
 			d(printf("Canceling lookup thread and leaving it\n"));
 			msg->cancelled = 1;
-			pthread_cancel(id);
-			pthread_join (id, NULL);
+			g_thread_join (thread);
 			cancel = 1;
 		} else {
 			struct _addrinfo_msg *reply = (struct _addrinfo_msg *)camel_msgport_try_pop(reply_port);
 
 			g_assert(reply == msg);
 			d(printf("waiting for child to exit\n"));
-			pthread_join(id, NULL);
+			g_thread_join (thread);
 			d(printf("child done\n"));
 		}
 	} else {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s: %s", error, _("cannot create thread"), g_strerror(err));
+		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s: %s", error, _("cannot create thread"), err ? err->message : _("Unknown error"));
+		if (err)
+			g_error_free (err);
 	}
 	camel_msgport_destroy(reply_port);
 
@@ -540,13 +541,12 @@ cs_getaddrinfo(gpointer data)
 	/* This is a pretty simplistic emulation of getaddrinfo */
 
 	while ((msg->result = camel_gethostbyname_r(msg->name, &h, msg->hostbufmem, msg->hostbuflen, &herr)) == ERANGE) {
-		pthread_testcancel();
+		if (msg->cancelled)
+			break;
                 msg->hostbuflen *= 2;
                 msg->hostbufmem = g_realloc(msg->hostbufmem, msg->hostbuflen);
 	}
 
-	pthread_testcancel ();
-
 	/* If we got cancelled, dont reply, just free it */
 	if (msg->cancelled)
 		goto cancel;
@@ -599,9 +599,7 @@ cs_getaddrinfo(gpointer data)
 		}
 	}
 
-	pthread_testcancel ();
-
-	for (i=0;h.h_addr_list[i];i++) {
+	for (i = 0; h.h_addr_list[i] && !msg->cancelled; i++) {
 		res = g_malloc0(sizeof(*res));
 		if (msg->hints) {
 			res->ai_flags = msg->hints->ai_flags;
@@ -651,8 +649,6 @@ cs_getaddrinfo(gpointer data)
 			info->result = getaddrinfo(info->name, "443", info->hints, info->res);
 	}
 
-	pthread_testcancel ();
-
 	if (!info->cancelled)
 		camel_msgport_reply((CamelMsg *)info);
 
@@ -747,7 +743,8 @@ cs_getnameinfo(gpointer data)
 
 	while ((msg->result = camel_gethostbyaddr_r((const gchar *)&sin->sin_addr, sizeof(sin->sin_addr), AF_INET, &h,
 						    msg->hostbufmem, msg->hostbuflen, &herr)) == ERANGE) {
-		pthread_testcancel ();
+		if (msg->cancelled)
+			break;
                 msg->hostbuflen *= 2;
                 msg->hostbufmem = g_realloc(msg->hostbufmem, msg->hostbuflen);
 	}
@@ -755,8 +752,6 @@ cs_getnameinfo(gpointer data)
 	if (msg->cancelled)
 		goto cancel;
 
-	pthread_testcancel ();
-
 	if (msg->host) {
 		g_free(msg->host);
 		if (msg->result == 0 && h.h_name && h.h_name[0]) {
@@ -773,7 +768,8 @@ cs_getnameinfo(gpointer data)
 	if (msg->serv)
 		sprintf(msg->serv, "%d", sin->sin_port);
 
-	camel_msgport_reply((CamelMsg *)msg);
+	if (!msg->cancelled)
+		camel_msgport_reply ((CamelMsg *)msg);
 cancel:
 	return NULL;
 }
@@ -786,8 +782,6 @@ cs_getnameinfo(gpointer data)
 	/* there doens't appear to be a return code which says host or serv buffers are too short, lengthen them */
 	msg->result = getnameinfo(msg->addr, msg->addrlen, msg->host, msg->hostlen, msg->serv, msg->servlen, msg->flags);
 
-	pthread_testcancel ();
-
 	if (!msg->cancelled)
 		camel_msgport_reply((CamelMsg *)msg);
 
diff --git a/camel/camel-object.c b/camel/camel-object.c
index c54ae59..918b4d2 100644
--- a/camel/camel-object.c
+++ b/camel/camel-object.c
@@ -25,7 +25,6 @@
 #endif
 
 #include <errno.h>
-#include <pthread.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -90,7 +89,7 @@ struct _CamelObjectBagKey {
 
 	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 */
+	GThread *owner;		/* the thread that has reserved the bag for a new entry */
 	gint have_owner;
 	GCond *cond;
 };
@@ -141,8 +140,6 @@ static GHashTable *type_table;
 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))
@@ -1249,13 +1246,13 @@ camel_object_free_hooks(CamelObject *o)
 static CamelHookList *
 camel_object_get_hooks(CamelObject *o)
 {
-	static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+	static GStaticMutex lock = G_STATIC_MUTEX_INIT;
 	CamelHookList *hooks;
 
 	/* if we have it, we dont have to do any other locking,
 	   otherwise use a global lock to setup the object's hook data */
 	if (o->hooks == NULL) {
-		pthread_mutex_lock(&lock);
+		g_static_mutex_lock(&lock);
 		if (o->hooks == NULL) {
 			hooks = hooks_alloc();
 			g_static_rec_mutex_init(&hooks->lock);
@@ -1265,7 +1262,7 @@ camel_object_get_hooks(CamelObject *o)
 			hooks->list = NULL;
 			o->hooks = hooks;
 		}
-		pthread_mutex_unlock(&lock);
+		g_static_mutex_unlock(&lock);
 	}
 
 	g_static_rec_mutex_lock(&o->hooks->lock);
@@ -2003,7 +2000,7 @@ co_bag_unreserve(CamelObjectBag *bag, gconstpointer key)
 	}
 
 	g_assert(res != NULL);
-	g_assert(res->have_owner && pthread_equal(res->owner, pthread_self()));
+	g_assert(res->have_owner && res->owner == g_thread_self ());
 
 	if (res->waiters > 0) {
 		b(printf("unreserve bag '%s', waking waiters\n", (gchar *)key));
@@ -2107,7 +2104,7 @@ camel_object_bag_get(CamelObjectBag *bag, gconstpointer key)
 			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_assert(!res->have_owner || res->owner != g_thread_self ());
 			g_cond_wait(res->cond, ref_lock);
 			res->waiters--;
 
@@ -2119,7 +2116,7 @@ camel_object_bag_get(CamelObjectBag *bag, gconstpointer key)
 			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->owner = g_thread_self ();
 			res->have_owner = TRUE;
 			co_bag_unreserve(bag, key);
 		}
@@ -2202,7 +2199,7 @@ camel_object_bag_reserve(CamelObjectBag *bag, gconstpointer key)
 
 		if (res) {
 			b(printf("bag reserve %s, already reserved, waiting\n", (gchar *)key));
-			g_assert(!res->have_owner || !pthread_equal(res->owner, pthread_self()));
+			g_assert(!res->have_owner || res->owner != g_thread_self ());
 			res->waiters++;
 			g_cond_wait(res->cond, ref_lock);
 			res->waiters--;
@@ -2212,12 +2209,12 @@ camel_object_bag_reserve(CamelObjectBag *bag, gconstpointer key)
 				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->owner = g_thread_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->owner = g_thread_self ();
 				res->have_owner = TRUE;
 			}
 		} else {
@@ -2226,7 +2223,7 @@ camel_object_bag_reserve(CamelObjectBag *bag, gconstpointer key)
 			res->waiters = 0;
 			res->key = bag->copy_key(key);
 			res->cond = g_cond_new();
-			res->owner = pthread_self();
+			res->owner = g_thread_self ();
 			res->have_owner = TRUE;
 			res->next = bag->reserved;
 			bag->reserved = res;
diff --git a/camel/camel-object.h b/camel/camel-object.h
index 4b2216b..364d7fb 100644
--- a/camel/camel-object.h
+++ b/camel/camel-object.h
@@ -29,7 +29,6 @@
 #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 */
diff --git a/camel/camel-operation.c b/camel/camel-operation.c
index 2d87904..ebf6868 100644
--- a/camel/camel-operation.c
+++ b/camel/camel-operation.c
@@ -24,7 +24,6 @@
 #include <config.h>
 #endif
 
-#include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/time.h>
@@ -54,7 +53,7 @@ struct _CamelOperation {
 	struct _CamelOperation *next;
 	struct _CamelOperation *prev;
 
-	pthread_t id;		/* id of running thread */
+	GThread *thread;	/* running thread */
 	guint32 flags;		/* cancelled ? */
 	gint blocked;		/* cancellation blocked depth */
 	gint refcount;
@@ -80,31 +79,22 @@ struct _CamelOperation {
 /* Delay before a transient operation has any effect on the status */
 #define CAMEL_OPERATION_TRANSIENT_DELAY (5)
 
-static pthread_mutex_t operation_lock = PTHREAD_MUTEX_INITIALIZER;
-#define LOCK() pthread_mutex_lock(&operation_lock)
-#define UNLOCK() pthread_mutex_unlock(&operation_lock)
+static GStaticMutex operation_lock = G_STATIC_MUTEX_INIT;
+#define LOCK() g_static_mutex_lock(&operation_lock)
+#define UNLOCK() g_static_mutex_unlock(&operation_lock)
 
 static guint stamp (void);
 static CamelDList operation_list = CAMEL_DLIST_INITIALISER(operation_list);
-static pthread_key_t operation_key;
-static pthread_once_t operation_once = PTHREAD_ONCE_INIT;
+static GStaticPrivate operation_key = G_STATIC_PRIVATE_INIT;
 
 typedef struct _CamelOperationMsg {
 	CamelMsg msg;
 } CamelOperationMsg;
 
-static void
-co_createspecific(void)
-{
-	pthread_key_create(&operation_key, NULL);
-}
-
 static CamelOperation *
 co_getcc(void)
 {
-	pthread_once(&operation_once, co_createspecific);
-
-	return (CamelOperation *)pthread_getspecific(operation_key);
+	return (CamelOperation *)g_static_private_get (&operation_key);
 }
 
 /**
@@ -356,7 +346,7 @@ camel_operation_register (CamelOperation *cc)
 {
 	CamelOperation *oldcc = co_getcc();
 
-	pthread_setspecific(operation_key, cc);
+	g_static_private_set (&operation_key, cc, NULL);
 
 	return oldcc;
 }
@@ -370,8 +360,7 @@ camel_operation_register (CamelOperation *cc)
 void
 camel_operation_unregister (CamelOperation *cc)
 {
-	pthread_once(&operation_once, co_createspecific);
-	pthread_setspecific(operation_key, NULL);
+	g_static_private_set (&operation_key, NULL, NULL);
 }
 
 /**
@@ -389,7 +378,7 @@ camel_operation_cancel_check (CamelOperation *cc)
 	CamelOperationMsg *msg;
 	gint cancelled;
 
-	d(printf("checking for cancel in thread %d\n", pthread_self()));
+	d(printf("checking for cancel in thread %p\n", g_thread_self()));
 
 	if (cc == NULL)
 		cc = co_getcc();
diff --git a/camel/camel-partition-table.c b/camel/camel-partition-table.c
index bec514b..fde2d33 100644
--- a/camel/camel-partition-table.c
+++ b/camel/camel-partition-table.c
@@ -44,11 +44,11 @@
 #define k(x) /*(printf("%s(%d):%s: ",  __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
 
 struct _CamelPartitionTablePrivate {
-	pthread_mutex_t lock;	/* for locking partition */
+	GStaticMutex 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) (g_static_mutex_lock(&(kf)->priv->lock))
+#define CAMEL_PARTITION_TABLE_UNLOCK(kf, lock) (g_static_mutex_unlock(&(kf)->priv->lock))
 
 static void
 camel_partition_table_class_init(CamelPartitionTableClass *klass)
@@ -63,7 +63,7 @@ camel_partition_table_init(CamelPartitionTable *cpi)
 	camel_dlist_init(&cpi->partition);
 
 	p = cpi->priv = g_malloc0(sizeof(*cpi->priv));
-	pthread_mutex_init(&p->lock, NULL);
+	g_static_mutex_init (&p->lock);
 }
 
 static void
@@ -84,7 +84,7 @@ camel_partition_table_finalise(CamelPartitionTable *cpi)
 		camel_object_unref((CamelObject *)cpi->blocks);
 	}
 
-	pthread_mutex_destroy(&p->lock);
+	g_static_mutex_free (&p->lock);
 
 	g_free(p);
 
@@ -583,11 +583,11 @@ fail:
 /* ********************************************************************** */
 
 struct _CamelKeyTablePrivate {
-	pthread_mutex_t lock;	/* for locking key */
+	GStaticMutex 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) (g_static_mutex_lock(&(kf)->priv->lock))
+#define CAMEL_KEY_TABLE_UNLOCK(kf, lock) (g_static_mutex_unlock(&(kf)->priv->lock))
 
 static void
 camel_key_table_class_init(CamelKeyTableClass *klass)
@@ -600,7 +600,7 @@ camel_key_table_init(CamelKeyTable *ki)
 	struct _CamelKeyTablePrivate *p;
 
 	p = ki->priv = g_malloc0(sizeof(*ki->priv));
-	pthread_mutex_init(&p->lock, NULL);
+	g_static_mutex_init (&p->lock);
 }
 
 static void
@@ -619,7 +619,7 @@ camel_key_table_finalise(CamelKeyTable *ki)
 		camel_object_unref((CamelObject *)ki->blocks);
 	}
 
-	pthread_mutex_destroy(&p->lock);
+	g_static_mutex_free (&p->lock);
 
 	g_free(p);
 
diff --git a/camel/camel-private.h b/camel/camel-private.h
index a556f7e..9914b16 100644
--- a/camel/camel-private.h
+++ b/camel/camel-private.h
@@ -30,8 +30,6 @@
 #include "config.h"
 #endif
 
-#include <pthread.h>
-
 G_BEGIN_DECLS
 
 struct _CamelFolderPrivate {
@@ -164,13 +162,13 @@ struct _CamelVeeFolderPrivate {
 	(g_mutex_unlock(((CamelVeeFolder *) (f))->priv->l))
 
 struct _CamelDataWrapperPrivate {
-	pthread_mutex_t stream_lock;
+	GStaticMutex stream_lock;
 };
 
 #define CAMEL_DATA_WRAPPER_LOCK(dw, l) \
-	(pthread_mutex_lock(&((CamelDataWrapper *) (dw))->priv->l))
+	(g_static_mutex_lock(&((CamelDataWrapper *) (dw))->priv->l))
 #define CAMEL_DATA_WRAPPER_UNLOCK(dw, l) \
-	(pthread_mutex_unlock(&((CamelDataWrapper *) (dw))->priv->l))
+	(g_static_mutex_unlock(&((CamelDataWrapper *) (dw))->priv->l))
 
 /* most of this stuff really is private, but the lock can be used by subordinate classes */
 struct _CamelCertDBPrivate {
diff --git a/camel/camel-provider.c b/camel/camel-provider.c
index c510ff3..959a71f 100644
--- a/camel/camel-provider.c
+++ b/camel/camel-provider.c
@@ -69,10 +69,10 @@ static CamelProvider vee_provider = {
 	/* ... */
 };
 
-static pthread_once_t setup_once = PTHREAD_ONCE_INIT;
+static GOnce setup_once = G_ONCE_INIT;
 
-static void
-provider_setup(void)
+static gpointer
+provider_setup (gpointer param)
 {
 	module_table = g_hash_table_new(camel_strcase_hash, camel_strcase_equal);
 	provider_table = g_hash_table_new(camel_strcase_hash, camel_strcase_equal);
@@ -81,6 +81,8 @@ provider_setup(void)
 	vee_provider.url_hash = camel_url_hash;
 	vee_provider.url_equal = camel_url_equal;
 	camel_provider_register(&vee_provider);
+
+	return NULL;
 }
 
 /**
@@ -106,7 +108,7 @@ camel_provider_init (void)
 	CamelProviderModule *m;
 	static gint loaded = 0;
 
-	pthread_once(&setup_once, provider_setup);
+	g_once (&setup_once, provider_setup, NULL);
 
 	if (loaded)
 		return;
@@ -177,7 +179,7 @@ camel_provider_load(const gchar *path, CamelException *ex)
 	GModule *module;
 	CamelProvider *(*camel_provider_module_init) (void);
 
-	pthread_once(&setup_once, provider_setup);
+	g_once (&setup_once, provider_setup, NULL);
 
 	if (!g_module_supported ()) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
diff --git a/camel/camel-sasl-popb4smtp.c b/camel/camel-sasl-popb4smtp.c
index aca41d5..fd3de89 100644
--- a/camel/camel-sasl-popb4smtp.c
+++ b/camel/camel-sasl-popb4smtp.c
@@ -24,7 +24,6 @@
 #include <config.h>
 #endif
 
-#include <pthread.h>
 #include <string.h>
 #include <time.h>
 
@@ -50,9 +49,9 @@ static GHashTable *poplast;
 /* use 1 hour as our pop timeout */
 #define POPB4SMTP_TIMEOUT (60*60)
 
-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 GStaticMutex lock = G_STATIC_MUTEX_INIT;
+#define POPB4SMTP_LOCK(l) g_static_mutex_lock(&l)
+#define POPB4SMTP_UNLOCK(l) g_static_mutex_unlock(&l)
 
 static CamelSaslClass *parent_class = NULL;
 
diff --git a/camel/camel-service.c b/camel/camel-service.c
index 3dc24f9..4227a7a 100644
--- a/camel/camel-service.c
+++ b/camel/camel-service.c
@@ -29,7 +29,6 @@
 
 #include <ctype.h>
 #include <errno.h>
-#include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/camel/camel-string-utils.c b/camel/camel-string-utils.c
index b2c1b27..5ebea4e 100644
--- a/camel/camel-string-utils.c
+++ b/camel/camel-string-utils.c
@@ -25,7 +25,6 @@
 #endif
 
 #include <string.h>
-#include <pthread.h>
 
 #include "camel-string-utils.h"
 
@@ -139,7 +138,7 @@ gchar camel_toupper(gchar c)
 }
 
 /* working stuff for pstrings */
-static pthread_mutex_t pstring_lock = PTHREAD_MUTEX_INITIALIZER;
+static GStaticMutex pstring_lock = G_STATIC_MUTEX_INIT;
 static GHashTable *pstring_table = NULL;
 
 /**
@@ -170,7 +169,7 @@ camel_pstring_add (gchar *str, gboolean own)
 		return "";
 	}
 
-	pthread_mutex_lock (&pstring_lock);
+	g_static_mutex_lock (&pstring_lock);
 	if (pstring_table == NULL)
 		pstring_table = g_hash_table_new (g_str_hash, g_str_equal);
 
@@ -184,7 +183,7 @@ camel_pstring_add (gchar *str, gboolean own)
 		g_hash_table_insert (pstring_table, pstr, GINT_TO_POINTER (1));
 	}
 
-	pthread_mutex_unlock (&pstring_lock);
+	g_static_mutex_unlock (&pstring_lock);
 
 	return pstr;
 }
@@ -213,7 +212,7 @@ camel_pstring_peek (const gchar *str)
 		return "";
 	}
 
-	pthread_mutex_lock (&pstring_lock);
+	g_static_mutex_lock (&pstring_lock);
 	if (pstring_table == NULL)
 		pstring_table = g_hash_table_new (g_str_hash, g_str_equal);
 
@@ -222,7 +221,7 @@ camel_pstring_peek (const gchar *str)
 		g_hash_table_insert (pstring_table, pstr, GINT_TO_POINTER (1));
 	}
 
-	pthread_mutex_unlock (&pstring_lock);
+	g_static_mutex_unlock (&pstring_lock);
 
 	return pstr;
 }
@@ -266,7 +265,7 @@ camel_pstring_free(const gchar *s)
 	if (s == NULL || s[0] == 0)
 		return;
 
-	pthread_mutex_lock(&pstring_lock);
+	g_static_mutex_lock (&pstring_lock);
 	if (g_hash_table_lookup_extended(pstring_table, s, (gpointer *)&p, &pcount)) {
 		count = GPOINTER_TO_INT(pcount)-1;
 		if (count == 0) {
@@ -286,5 +285,5 @@ camel_pstring_free(const gchar *s)
 			g_assert (0);
 		}
 	}
-	pthread_mutex_unlock(&pstring_lock);
+	g_static_mutex_unlock (&pstring_lock);
 }
diff --git a/camel/providers/imapx/camel-imapx-exception.c b/camel/providers/imapx/camel-imapx-exception.c
index e031baf..b13e8bf 100644
--- a/camel/providers/imapx/camel-imapx-exception.c
+++ b/camel/providers/imapx/camel-imapx-exception.c
@@ -7,13 +7,12 @@
 
 #include "camel-imapx-exception.h"
 
-#include <pthread.h>
-
-static pthread_key_t handler_key = 0;
+static GStaticPrivate handler_key = G_STATIC_PRIVATE_INIT;
 
 void camel_exception_setup(void)
 {
-	pthread_key_create(&handler_key, NULL);
+	/* No need for 'new' with GStaticPrivate */
+	/* g_static_private_new (&handler_key); */
 }
 
 void
@@ -21,12 +20,12 @@ camel_exception_try(struct _CamelExceptionEnv *env)
 {
 	struct _CamelExceptionEnv *handler;
 
-	handler = pthread_getspecific(handler_key);
+	handler = g_static_private_get (&handler_key);
 	env->parent = handler;
 	handler = env;
 	env->ex = NULL;
 
-	pthread_setspecific(handler_key, handler);
+	g_static_private_set (&handler_key, handler, NULL);
 }
 
 void
@@ -36,10 +35,10 @@ camel_exception_throw_ex(CamelException *ex)
 
 	printf("throwing exception '%s'\n", ex->desc);
 
-	env = pthread_getspecific(handler_key);
+	env = g_static_private_get (&handler_key);
 	if (env != NULL) {
 		env->ex = ex;
-		pthread_setspecific(handler_key, env->parent);
+		g_static_private_set (&handler_key, env->parent, NULL);
 		longjmp(env->env, ex->id);
 	} else {
 		fprintf(stderr, "\nUncaught exception: %s\n", ex->desc);
@@ -67,13 +66,13 @@ camel_exception_throw(gint id, gchar *fmt, ...)
 void
 camel_exception_drop(struct _CamelExceptionEnv *env)
 {
-	pthread_setspecific(handler_key, env->parent);
+	g_static_private_set (&handler_key, env->parent, NULL);
 }
 
 void
 camel_exception_done(struct _CamelExceptionEnv *env)
 {
-	pthread_setspecific(handler_key, env->parent);
+	g_static_private_set (&handler_key, env->parent, NULL);
 	if (env->ex != NULL) {
 		camel_exception_free(env->ex);
 	}
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index a56f167..308593c 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -255,7 +255,7 @@ typedef struct _CamelIMAPXIdle CamelIMAPXIdle;
 struct _CamelIMAPXIdle {
 	GMutex *idle_lock;
 	EFlag *idle_start_watch;
-	pthread_t idle_thread_id;
+	GThread *idle_thread;
 
 	gboolean idle_issue_done;
 	gboolean in_idle;
@@ -1748,11 +1748,11 @@ imapx_exit_idle (CamelIMAPXServer *is)
 
 	IDLE_LOCK (idle);
 
-	if (idle->idle_thread_id) {
+	if (idle->idle_thread) {
 		idle->idle_exit = TRUE;
 		e_flag_set (idle->idle_start_watch);
 
-		pthread_join (idle->idle_thread_id, NULL);
+		g_thread_join (idle->idle_thread);
 	}
 
 	IDLE_UNLOCK (idle);
@@ -1775,9 +1775,15 @@ imapx_start_idle (CamelIMAPXServer *is)
 
 	IDLE_LOCK (idle);
 
-	if (!idle->idle_thread_id) {
+	if (!idle->idle_thread) {
+		GError *error = NULL;
+
 		idle->idle_start_watch = e_flag_new ();
-		pthread_create (&idle->idle_thread_id, NULL, idle_thread, is);
+		idle->idle_thread = g_thread_create (idle_thread, is, TRUE, &error);
+		if (error) {
+			fprintf (stderr, "%s: Failed to create a thread: %s\n", G_STRFUNC, error->message);
+			g_error_free (error);
+		}
 	} else
 		e_flag_set (idle->idle_start_watch);
 
@@ -3253,8 +3259,8 @@ camel_imapx_server_connect(CamelIMAPXServer *is, gint state)
 
 	CAMEL_SERVICE_REC_LOCK (is->store, connect_lock);
 	if (state) {
-		pthread_t id;
-		CamelException ex = {0, NULL};
+		GError *error = NULL;
+		CamelException ex = CAMEL_EXCEPTION_INITIALIZE;
 
 		if (is->state == IMAPX_AUTHENTICATED || is->state == IMAPX_SELECTED) {
 			ret = TRUE;
@@ -3267,16 +3273,22 @@ camel_imapx_server_connect(CamelIMAPXServer *is, gint state)
 			goto exit;
 		}
 
-		pthread_create(&id, NULL, imapx_parser_thread, is);
-		is->parser_thread_id = id;
-		ret = TRUE;
+		is->parser_thread = g_thread_create (imapx_parser_thread, is, TRUE, &error);
+		if (!is->parser_thread) {
+			ret = FALSE;
+			if (error) {
+				fprintf (stderr, "%s: Failed to create a thread: %s\n", G_STRFUNC, error->message);
+				g_error_free (error);
+			}
+		} else
+			ret = TRUE;
 	} else {
 		imapx_disconnect (is);
 
 		if (imapx_idle_supported (is))
 			imapx_exit_idle (is);
 
-		pthread_join (is->parser_thread_id, NULL);
+		g_thread_join (is->parser_thread);
 		ret = TRUE;
 	}
 
@@ -3482,7 +3494,7 @@ fail:
 
 #include "camel-imapx-store.h"
 /*
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static GStaticMutex lock = G_StATIC_MUTEX_INIT;
 static CamelIterator *threaditer;
 static CamelFolder *threadfolder;
 
@@ -3497,13 +3509,13 @@ getmsgs(gpointer d)
 
 	printf("Checking thread, downloading messages in the background ...\n");
 
-	pthread_mutex_lock(&lock);
+	g_static_mutex_lock (&lock);
 	while ((info = imapx_iterator_next(threaditer, NULL))) {
 		gchar *cur = imapx_get_path_uid(is, threadfolder, NULL, camel_message_info_uid(info));
 		gchar *uid = g_strdup(camel_message_info_uid(info));
 		struct stat st;
 
-		pthread_mutex_unlock(&lock);
+		g_static_mutex_unlock (&lock);
 
 		if (stat(cur, &st) == -1 && errno == ENOENT) {
 			CamelStream *stream;
@@ -3518,9 +3530,9 @@ getmsgs(gpointer d)
 
 		g_free(uid);
 		g_free(cur);
-		pthread_mutex_lock(&lock);
+		g_static_mutex_lock (&lock);
 	}
-	pthread_mutex_unlock(&lock);
+	g_static_mutex_unlock (&lock);
 
 	return NULL;
 } */
diff --git a/camel/providers/imapx/camel-imapx-server.h b/camel/providers/imapx/camel-imapx-server.h
index 856238d..6bf1e0f 100644
--- a/camel/providers/imapx/camel-imapx-server.h
+++ b/camel/providers/imapx/camel-imapx-server.h
@@ -88,7 +88,7 @@ struct _CamelIMAPXServer {
 	   processed after the command completes. */
 	GSList *expunged;
 
-	pthread_t parser_thread_id;
+	GThread *parser_thread;
 
 	/* Idle */
 	struct _CamelIMAPXIdle *idle;
diff --git a/camel/providers/local/camel-local-private.h b/camel/providers/local/camel-local-private.h
index 68f2503..0de4fc6 100644
--- a/camel/providers/local/camel-local-private.h
+++ b/camel/providers/local/camel-local-private.h
@@ -31,7 +31,6 @@
 #endif
 
 #include <glib.h>
-#include <pthread.h>
 
 G_BEGIN_DECLS
 
diff --git a/camel/providers/nntp/camel-nntp-newsrc.c b/camel/providers/nntp/camel-nntp-newsrc.c
index 05281a8..0d937ba 100644
--- a/camel/providers/nntp/camel-nntp-newsrc.c
+++ b/camel/providers/nntp/camel-nntp-newsrc.c
@@ -26,7 +26,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/camel/tests/folder/test10.c b/camel/tests/folder/test10.c
index 2c980b5..ab45628 100644
--- a/camel/tests/folder/test10.c
+++ b/camel/tests/folder/test10.c
@@ -1,7 +1,6 @@
 /* threaded folder testing */
 
 #include <string.h>
-#include <pthread.h>
 
 #include "camel-test.h"
 #include "camel-test-provider.h"
@@ -60,7 +59,7 @@ gint main(gint argc, gchar **argv)
 {
 	CamelException *ex;
 	gint i, j;
-	pthread_t threads[MAX_THREADS];
+	GThread *threads[MAX_THREADS];
 
 	camel_test_init(argc, argv);
 	camel_test_provider_init(1, local_drivers);
@@ -83,11 +82,19 @@ gint main(gint argc, gchar **argv)
 			camel_test_push("provider %s", local_providers[j]);
 			path = g_strdup_printf("%s:///tmp/camel-test/%s", local_providers[j], local_providers[j]);
 
-			for (i=0;i<MAX_THREADS;i++)
-				pthread_create(&threads[i], 0, worker, NULL);
+			for (i = 0; i < MAX_THREADS; i++) {
+				GError *error = NULL;
 
-			for (i=0;i<MAX_THREADS;i++)
-				pthread_join(threads[i], NULL);
+				threads[i] = g_thread_create (worker, NULL, TRUE, &error);
+				if (error) {
+					fprintf (stderr, "%s: Failed to create a thread: %s\n", G_STRFUNC, error->message);
+					g_error_free (error);
+				}
+			}
+
+			for (i = 0; i < MAX_THREADS; i++) {
+				if (threads[i])
+					g_thread_join (threads[i]);
 
 			test_free(path);
 
diff --git a/camel/tests/folder/test11.c b/camel/tests/folder/test11.c
index fe20aaf..78a1ec0 100644
--- a/camel/tests/folder/test11.c
+++ b/camel/tests/folder/test11.c
@@ -2,7 +2,6 @@
 /* threaded folder testing */
 
 #include <string.h>
-#include <pthread.h>
 
 #include "camel-test.h"
 #include "camel-test-provider.h"
diff --git a/camel/tests/folder/test8.c b/camel/tests/folder/test8.c
index f2c2e1c..d9cd8fe 100644
--- a/camel/tests/folder/test8.c
+++ b/camel/tests/folder/test8.c
@@ -1,7 +1,6 @@
 /* threaded folder testing */
 
 #include <string.h>
-#include <pthread.h>
 
 #include "camel-test.h"
 #include "camel-test-provider.h"
@@ -72,7 +71,7 @@ worker(gpointer d)
 	/* we add a message, search for it, twiddle some flags, delete it */
 	/* and flat out */
 	for (i=0;i<MAX_MESSAGES;i++) {
-		d(printf("Thread %ld message %i\n", pthread_self(), i));
+		d(printf ("Thread %p message %i\n", g_thread_self (), i));
 		test_add_message(info->folder, id+i);
 
 		sub = g_strdup_printf("(match-all (header-contains \"subject\" \"message %08x subject\"))", id+i);
@@ -130,7 +129,7 @@ gint main(gint argc, gchar **argv)
 	gint i, j, index;
 	gchar *path;
 	CamelStore *store;
-	pthread_t threads[MAX_THREADS];
+	GThread *threads[MAX_THREADS];
 	struct _threadinfo *info;
 	CamelFolder *folder;
 	GPtrArray *uids;
@@ -164,16 +163,25 @@ gint main(gint argc, gchar **argv)
 								CAMEL_STORE_FOLDER_CREATE|CAMEL_STORE_FOLDER_BODY_INDEX, ex);
 			check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
 
-			for (i=0;i<MAX_THREADS;i++) {
+			for (i = 0; i < MAX_THREADS; i++) {
+				GError *error = NULL;
+
 				info = g_malloc(sizeof(*info));
 				info->id = i*MAX_MESSAGES;
 				info->folder = folder;
-				pthread_create(&threads[i], 0, worker, info);
+
+				threads[i] = g_thread_create (worker, info, TRUE, &error);
+				if (error) {
+					fprintf (stderr, "%s: Failed to create a thread: %s\n", G_STRFUNC, error->message);
+					g_error_free (error);
+				}
 			}
 
-			for (i=0;i<MAX_THREADS;i++) {
-				pthread_join(threads[i], (gpointer *)&info);
-				g_free(info);
+			for (i = 0; i < MAX_THREADS; i++) {
+				if (threads[i]) {
+					info = g_thread_join (threads[i]);
+					g_free (info);
+				}
 			}
 			pull();
 
diff --git a/camel/tests/lib/camel-test.c b/camel/tests/lib/camel-test.c
index 9cf38a6..d10cdaf 100644
--- a/camel/tests/lib/camel-test.c
+++ b/camel/tests/lib/camel-test.c
@@ -5,24 +5,16 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <pthread.h>
 #include <unistd.h>
 #include <signal.h>
 #include <errno.h>
 
 #include <camel/camel.h>
 
-/* well i dunno, doesn't seem to be in the headers but hte manpage mentions it */
-/* a nonportable checking mutex for glibc, not really needed, just validates
-   the test harness really */
-# ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
-static pthread_mutex_t lock = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
-# else
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
-# endif
-#define CAMEL_TEST_LOCK pthread_mutex_lock(&lock)
-#define CAMEL_TEST_UNLOCK pthread_mutex_unlock(&lock)
-#define CAMEL_TEST_ID (pthread_self())
+static GStaticMutex lock = G_STATIC_MUTEX_INIT;
+#define CAMEL_TEST_LOCK g_static_mutex_lock(&lock)
+#define CAMEL_TEST_UNLOCK g_static_mutex_unlock(&lock)
+#define CAMEL_TEST_ID (g_thread_self())
 
 static gint setup;
 static gint ok;
@@ -45,11 +37,11 @@ static GHashTable *info_table;
 gint camel_test_verbose;
 
 static void
-dump_action(gint id, struct _state *s, gpointer d)
+dump_action (GThread *thread, struct _state *s, gpointer d)
 {
 	struct _stack *node;
 
-	printf("\nThread %d:\n", id);
+	printf("\nThread %p:\n", thread);
 
 	node = s->state;
 	if (node) {
@@ -88,10 +80,10 @@ current_state(void)
 	if (info_table == NULL)
 		info_table = g_hash_table_new(0, 0);
 
-	info = g_hash_table_lookup(info_table, (gpointer)CAMEL_TEST_ID);
+	info = g_hash_table_lookup(info_table, CAMEL_TEST_ID);
 	if (info == NULL) {
 		info = g_malloc0(sizeof(*info));
-		g_hash_table_insert(info_table, (gpointer)CAMEL_TEST_ID, info);
+		g_hash_table_insert(info_table, CAMEL_TEST_ID, info);
 	}
 	return info;
 }
diff --git a/configure.ac b/configure.ac
index 6e137d0..2ea3b10 100644
--- a/configure.ac
+++ b/configure.ac
@@ -587,7 +587,7 @@ dnl check if pkg-config files exist (which are only shipped by distributions, no
 			CFLAGS_save="$CFLAGS"
 			LDFLAGS_save="$LDFLAGS"
 			LIBS_save="$LIBS"
-			nsprlibs="$DL_LIB -lplc4 -lplds4 -lnspr4 $PTHREAD_LIB"
+			nsprlibs="$DL_LIB -lplc4 -lplds4 -lnspr4"
 
 			CFLAGS="$CFLAGS $MANUAL_NSPR_CFLAGS"
 			LIBS="$nsprlibs"
@@ -1161,23 +1161,6 @@ dnl ******************************
 dnl Posix thread support
 dnl ******************************
 
-dnl GLIB_CONFIG=${GLIB_CONFIG-glib-config}
-dnl GNOME_PTHREAD_CHECK
-
-dnl if test "x$PTHREAD_LIB" = "x" ; then
-dnl 	AC_MSG_ERROR([POSIX threads are currently required for Evolution])
-dnl fi
-
-dnl Notice that this is a hack, and we wont be able to use this forever, but
-dnl at least for some time
-
-EVO_PTHREAD_CHECK
-
-THREADS_LIBS="$PTHREAD_LIB"
-THREADS_CFLAGS="$PTHREAD_CFLAGS"
-
-AC_SUBST(THREADS_LIBS)
-AC_SUBST(THREADS_CFLAGS)
 AC_DEFINE(ENABLE_THREADS,1,[Required])
 
 dnl ******************************
@@ -1220,7 +1203,7 @@ dnl libedataserver flags
 dnl ******************************
 E_DATA_SERVER_DEPS="libxml-2.0 gthread-2.0 libsoup-2.4 gconf-2.0 $mozilla_nspr"
 
-EVO_SET_COMPILE_FLAGS(E_DATA_SERVER, $E_DATA_SERVER_DEPS, $THREADS_CFLAGS $MANUAL_NSPR_CFLAGS, $THREADS_LIBS $MANUAL_NSPR_LIBS)
+EVO_SET_COMPILE_FLAGS(E_DATA_SERVER, $E_DATA_SERVER_DEPS, $MANUAL_NSPR_CFLAGS, $MANUAL_NSPR_LIBS)
 AC_SUBST(E_DATA_SERVER_CFLAGS)
 AC_SUBST(E_DATA_SERVER_LIBS)
 
@@ -1229,7 +1212,7 @@ dnl libedataserverui
 dnl ******************************
 E_DATA_SERVER_UI_DEPS="gtk+-2.0 libxml-2.0 gobject-2.0 gthread-2.0 gconf-2.0 $GNOME_KEYRING_REQUIREMENT"
 
-EVO_SET_COMPILE_FLAGS(E_DATA_SERVER_UI, $E_DATA_SERVER_UI_DEPS, $THREADS_CFLAGS, $THREADS_LIBS)
+EVO_SET_COMPILE_FLAGS(E_DATA_SERVER_UI, $E_DATA_SERVER_UI_DEPS, , )
 AC_SUBST(E_DATA_SERVER_UI_CFLAGS)
 AC_SUBST(E_DATA_SERVER_UI_LIBS)
 
@@ -1359,7 +1342,7 @@ fi
 
 AM_CONDITIONAL(ENABLE_LARGEFILE, [test "x$enable_largefile" = "xyes"])
 
-EVO_SET_COMPILE_FLAGS(CAMEL, $mozilla_nss gio-2.0 sqlite3 >= sqlite_minimum_version gthread-2.0, $THREADS_CFLAGS $KRB5_CFLAGS $MANUAL_NSS_CFLAGS $LARGEFILE_CFLAGS, -lz $THREADS_LIBS $KRB5_LIBS $MANUAL_NSS_LIBS)
+EVO_SET_COMPILE_FLAGS(CAMEL, $mozilla_nss gio-2.0 sqlite3 >= sqlite_minimum_version gthread-2.0, $KRB5_CFLAGS $MANUAL_NSS_CFLAGS $LARGEFILE_CFLAGS, -lz $KRB5_LIBS $MANUAL_NSS_LIBS)
 AC_SUBST(CAMEL_CFLAGS)
 AC_SUBST(CAMEL_LIBS)
 AC_SUBST(CAMEL_GROUPWISE_CFLAGS)
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 651b5a3..dae226b 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -414,23 +414,17 @@ e_utf8_strftime(gchar *s, gsize max, const gchar *fmt, const struct tm *tm)
 }
 
 /**
- * e_util_pthread_id:
- * @t: A pthread_t value
+ * e_util_gthread_id:
+ * @thread: A #GThread pointer
  *
  * Returns a 64-bit integer hopefully uniquely identifying the
- * thread. To be used in debugging output and logging only. To test
- * whether two pthread_t values refer to the same thread, use
- * pthread_equal().
+ * thread. To be used in debugging output and logging only.
+ * The returned value is just a cast of a pointer to the 64-bit integer.
  *
- * There is no guarantee that calling e_util_pthread_id() on one
+ * There is no guarantee that calling e_util_gthread_id() on one
  * thread first and later after that thread has dies on another won't
  * return the same integer.
  *
- * On some platforms it might even be that when called two times on
- * the same thread's pthread_t (with some pthread API calls inbetween)
- * we will return different values (this of course makes this function
- * rather useless on such platforms).
- *
  * On Linux and Win32, known to really return a unique id for each
  * thread existing at a certain time. No guarantee that ids won't be
  * reused after a thread has terminated, though.
@@ -438,35 +432,13 @@ e_utf8_strftime(gchar *s, gsize max, const gchar *fmt, const struct tm *tm)
  * Returns: A 64-bit integer.
  */
 guint64
-e_util_pthread_id (pthread_t t)
+e_util_gthread_id (GThread *thread)
 {
-#ifdef HAVE_GUINT64_CASTABLE_PTHREAD_T
-	/* We know that pthread_t is an integral type, or at least
-	 * castable to such without loss of precision.
-	 */
-	return (guint64) t;
-#elif defined (PTW32_VERSION)
-	/* pthreads-win32 implementation on Windows: Return the
-	 * pointer to the "actual object" (see pthread.h)
-	 */
 #if GLIB_SIZEOF_VOID_P == 8
 	/* 64-bit Windows */
-	return (guint64) t.p;
-#else
-	return (gint) t.p;
-#endif
+	return (guint64) thread;
 #else
-	/* Just return a checksum of the contents of the pthread_t */
-	{
-		guint64 retval = 0;
-		guchar *const tend = (guchar *) ((&t)+1);
-		guchar *tp = (guchar *) &t;
-
-		while (tp < tend)
-			retval = (retval << 5) - retval * *tp++;
-
-		return retval;
-	}
+	return (gint) thread;
 #endif
 }
 
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index 57e2581..7280ac0 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -22,7 +22,6 @@
 #ifndef __E_DATA_SERVER_UTIL_H__
 #define __E_DATA_SERVER_UTIL_H__
 
-#include <pthread.h>
 #include <sys/types.h>
 #include <glib.h>
 
@@ -41,7 +40,7 @@ const gchar *e_util_utf8_strstrcase (const gchar *haystack, const gchar *needle)
 const gchar *e_util_utf8_strstrcasedecomp (const gchar *haystack, const gchar *needle);
 gint	     e_util_utf8_strcasecmp (const gchar *s1, const gchar *s2);
 gchar       *e_util_utf8_remove_accents (const gchar *str);
-guint64      e_util_pthread_id (pthread_t t);
+guint64      e_util_gthread_id (GThread *thread);
 void         e_filename_make_safe (gchar *string);
 
 gsize e_utf8_strftime(gchar *s, gsize max, const gchar *fmt, const struct tm *tm);
diff --git a/libedataserver/e-msgport.c b/libedataserver/e-msgport.c
index 868143e..6532ff7 100644
--- a/libedataserver/e-msgport.c
+++ b/libedataserver/e-msgport.c
@@ -31,8 +31,6 @@
 #include <string.h>
 #include <stdio.h>
 
-#include <pthread.h>
-
 #include <glib.h>
 
 #ifdef HAVE_NSS
@@ -66,136 +64,6 @@
 #define E_IS_STATUS_INTR() (errno == EINTR)
 #endif
 
-static gint
-e_pipe (gint *fds)
-{
-#ifndef G_OS_WIN32
-	if (pipe (fds) != -1)
-		return 0;
-
-	fds[0] = -1;
-	fds[1] = -1;
-
-	return -1;
-#else
-	SOCKET temp, socket1 = -1, socket2 = -1;
-	struct sockaddr_in saddr;
-	gint len;
-	u_long arg;
-	fd_set read_set, write_set;
-	struct timeval tv;
-
-	temp = socket (AF_INET, SOCK_STREAM, 0);
-
-	if (temp == INVALID_SOCKET) {
-		goto out0;
-	}
-
-	arg = 1;
-	if (ioctlsocket (temp, FIONBIO, &arg) == SOCKET_ERROR) {
-		goto out0;
-	}
-
-	memset (&saddr, 0, sizeof (saddr));
-	saddr.sin_family = AF_INET;
-	saddr.sin_port = 0;
-	saddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-
-	if (bind (temp, (struct sockaddr *)&saddr, sizeof (saddr))) {
-		goto out0;
-	}
-
-	if (listen (temp, 1) == SOCKET_ERROR) {
-		goto out0;
-	}
-
-	len = sizeof (saddr);
-	if (getsockname (temp, (struct sockaddr *)&saddr, &len)) {
-		goto out0;
-	}
-
-	socket1 = socket (AF_INET, SOCK_STREAM, 0);
-
-	if (socket1 == INVALID_SOCKET) {
-		goto out0;
-	}
-
-	arg = 1;
-	if (ioctlsocket (socket1, FIONBIO, &arg) == SOCKET_ERROR) {
-		goto out1;
-	}
-
-	if (connect (socket1, (struct sockaddr  *)&saddr, len) != SOCKET_ERROR ||
-	    WSAGetLastError () != WSAEWOULDBLOCK) {
-		goto out1;
-	}
-
-	FD_ZERO (&read_set);
-	FD_SET (temp, &read_set);
-
-	tv.tv_sec = 0;
-	tv.tv_usec = 0;
-
-	if (select (0, &read_set, NULL, NULL, NULL) == SOCKET_ERROR) {
-		goto out1;
-	}
-
-	if (!FD_ISSET (temp, &read_set)) {
-		goto out1;
-	}
-
-	socket2 = accept (temp, (struct sockaddr *) &saddr, &len);
-	if (socket2 == INVALID_SOCKET) {
-		goto out1;
-	}
-
-	FD_ZERO (&write_set);
-	FD_SET (socket1, &write_set);
-
-	tv.tv_sec = 0;
-	tv.tv_usec = 0;
-
-	if (select (0, NULL, &write_set, NULL, NULL) == SOCKET_ERROR) {
-		goto out2;
-	}
-
-	if (!FD_ISSET (socket1, &write_set)) {
-		goto out2;
-	}
-
-	arg = 0;
-	if (ioctlsocket (socket1, FIONBIO, &arg) == SOCKET_ERROR) {
-		goto out2;
-	}
-
-	arg = 0;
-	if (ioctlsocket (socket2, FIONBIO, &arg) == SOCKET_ERROR) {
-		goto out2;
-	}
-
-	fds[0] = socket1;
-	fds[1] = socket2;
-
-	closesocket (temp);
-
-	return 0;
-
-out2:
-	closesocket (socket2);
-out1:
-	closesocket (socket1);
-out0:
-	closesocket (temp);
-	errno = EMFILE;		/* FIXME: use the real syscall errno? */
-
-	fds[0] = -1;
-	fds[1] = -1;
-
-	return -1;
-
-#endif
-}
-
 void e_dlist_init(EDList *v)
 {
         v->head = (EDListNode *)&v->tail;
@@ -484,943 +352,3 @@ em_cache_clear(EMCache *emc)
 		g_free(node);
 	}
 }
-
-struct _EMsgPort {
-	GAsyncQueue *queue;
-	gint pipe[2];  /* on Win32, actually a pair of SOCKETs */
-#ifdef HAVE_NSS
-	PRFileDesc *prpipe[2];
-#endif
-};
-
-/* message flags */
-enum {
-	MSG_FLAG_SYNC_WITH_PIPE    = 1 << 0,
-	MSG_FLAG_SYNC_WITH_PR_PIPE = 1 << 1
-};
-
-#ifdef HAVE_NSS
-static gint
-e_prpipe (PRFileDesc **fds)
-{
-#ifdef G_OS_WIN32
-	if (PR_NewTCPSocketPair (fds) != PR_FAILURE)
-		return 0;
-#else
-	if (PR_CreatePipe (&fds[0], &fds[1]) != PR_FAILURE)
-		return 0;
-#endif
-
-	fds[0] = NULL;
-	fds[1] = NULL;
-
-	return -1;
-}
-#endif
-
-static void
-msgport_sync_with_pipe (gint fd)
-{
-	gchar buffer[1];
-
-	while (fd >= 0) {
-		if (E_READ (fd, buffer, 1) > 0)
-			break;
-		else if (!E_IS_STATUS_INTR ()) {
-			g_warning ("%s: Failed to read from pipe: %s",
-				G_STRFUNC, g_strerror (errno));
-			break;
-		}
-	}
-}
-
-#ifdef HAVE_NSS
-static void
-msgport_sync_with_prpipe (PRFileDesc *prfd)
-{
-	gchar buffer[1];
-
-	while (prfd != NULL) {
-		if (PR_Read (prfd, buffer, 1) > 0)
-			break;
-		else if (PR_GetError () != PR_PENDING_INTERRUPT_ERROR) {
-			gchar *text = g_alloca (PR_GetErrorTextLength ());
-			PR_GetErrorText (text);
-			g_warning ("%s: Failed to read from NSPR pipe: %s",
-				G_STRFUNC, text);
-			break;
-		}
-	}
-}
-#endif
-
-EMsgPort *
-e_msgport_new (void)
-{
-	EMsgPort *msgport;
-
-	msgport = g_slice_new (EMsgPort);
-	msgport->queue = g_async_queue_new ();
-	msgport->pipe[0] = -1;
-	msgport->pipe[1] = -1;
-#ifdef HAVE_NSS
-	msgport->prpipe[0] = NULL;
-	msgport->prpipe[1] = NULL;
-#endif
-
-	return msgport;
-}
-
-void
-e_msgport_destroy (EMsgPort *msgport)
-{
-	g_return_if_fail (msgport != NULL);
-
-	if (msgport->pipe[0] >= 0) {
-		E_CLOSE (msgport->pipe[0]);
-		E_CLOSE (msgport->pipe[1]);
-	}
-#ifdef HAVE_NSS
-	if (msgport->prpipe[0] != NULL) {
-		PR_Close (msgport->prpipe[0]);
-		PR_Close (msgport->prpipe[1]);
-	}
-#endif
-
-	g_async_queue_unref (msgport->queue);
-	g_slice_free (EMsgPort, msgport);
-}
-
-gint
-e_msgport_fd (EMsgPort *msgport)
-{
-	gint fd;
-
-	g_return_val_if_fail (msgport != NULL, -1);
-
-	g_async_queue_lock (msgport->queue);
-	fd = msgport->pipe[0];
-	if (fd < 0 && e_pipe (msgport->pipe) == 0)
-		fd = msgport->pipe[0];
-	g_async_queue_unlock (msgport->queue);
-
-	return fd;
-}
-
-#ifdef HAVE_NSS
-PRFileDesc *
-e_msgport_prfd (EMsgPort *msgport)
-{
-	PRFileDesc *prfd;
-
-	g_return_val_if_fail (msgport != NULL, NULL);
-
-	g_async_queue_lock (msgport->queue);
-	prfd = msgport->prpipe[0];
-	if (prfd == NULL && e_prpipe (msgport->prpipe) == 0)
-		prfd = msgport->prpipe[0];
-	g_async_queue_unlock (msgport->queue);
-
-	return prfd;
-}
-#endif
-
-void
-e_msgport_put (EMsgPort *msgport, EMsg *msg)
-{
-	gint fd;
-#ifdef HAVE_NSS
-	PRFileDesc *prfd;
-#endif
-
-	g_return_if_fail (msgport != NULL);
-	g_return_if_fail (msg != NULL);
-
-	g_async_queue_lock (msgport->queue);
-
-	msg->flags = 0;
-
-	fd = msgport->pipe[1];
-	while (fd >= 0) {
-		if (E_WRITE (fd, "E", 1) > 0) {
-			msg->flags |= MSG_FLAG_SYNC_WITH_PIPE;
-			break;
-		} else if (!E_IS_STATUS_INTR ()) {
-			g_warning ("%s: Failed to write to pipe: %s",
-				G_STRFUNC, g_strerror (errno));
-			break;
-		}
-	}
-
-#ifdef HAVE_NSS
-	prfd = msgport->prpipe[1];
-	while (prfd != NULL) {
-		if (PR_Write (prfd, "E", 1) > 0) {
-			msg->flags |= MSG_FLAG_SYNC_WITH_PR_PIPE;
-			break;
-		} else if (PR_GetError () != PR_PENDING_INTERRUPT_ERROR) {
-			gchar *text = g_alloca (PR_GetErrorTextLength ());
-			PR_GetErrorText (text);
-			g_warning ("%s: Failed to write to NSPR pipe: %s",
-				G_STRFUNC, text);
-			break;
-		}
-	}
-#endif
-
-	g_async_queue_push_unlocked (msgport->queue, msg);
-	g_async_queue_unlock (msgport->queue);
-}
-
-EMsg *
-e_msgport_wait (EMsgPort *msgport)
-{
-	EMsg *msg;
-
-	g_return_val_if_fail (msgport != NULL, NULL);
-
-	g_async_queue_lock (msgport->queue);
-
-	msg = g_async_queue_pop_unlocked (msgport->queue);
-
-	g_assert (msg != NULL);
-
-	if (msg->flags & MSG_FLAG_SYNC_WITH_PIPE)
-		msgport_sync_with_pipe (msgport->pipe[0]);
-#ifdef HAVE_NSS
-	if (msg->flags & MSG_FLAG_SYNC_WITH_PR_PIPE)
-		msgport_sync_with_prpipe (msgport->prpipe[0]);
-#endif
-
-	g_async_queue_unlock (msgport->queue);
-
-	return msg;
-}
-
-EMsg *
-e_msgport_get (EMsgPort *msgport)
-{
-	EMsg *msg;
-
-	g_return_val_if_fail (msgport != NULL, NULL);
-
-	g_async_queue_lock (msgport->queue);
-
-	msg = g_async_queue_try_pop_unlocked (msgport->queue);
-
-	if (msg != NULL && msg->flags & MSG_FLAG_SYNC_WITH_PIPE)
-		msgport_sync_with_pipe (msgport->pipe[0]);
-#ifdef HAVE_NSS
-	if (msg != NULL && msg->flags & MSG_FLAG_SYNC_WITH_PR_PIPE)
-		msgport_sync_with_prpipe (msgport->prpipe[0]);
-#endif
-
-	g_async_queue_unlock (msgport->queue);
-
-	return msg;
-}
-
-void
-e_msgport_reply (EMsg *msg)
-{
-	g_return_if_fail (msg != NULL);
-
-	if (msg->reply_port)
-		e_msgport_put (msg->reply_port, msg);
-
-	/* else lost? */
-}
-
-#ifndef EDS_DISABLE_DEPRECATED
-
-struct _thread_info {
-	pthread_t id;
-	gint busy;
-};
-
-struct _EThread {
-	struct _EThread *next;
-	struct _EThread *prev;
-
-	EMsgPort *server_port;
-	EMsgPort *reply_port;
-	pthread_mutex_t mutex;
-	e_thread_t type;
-	gint queue_limit;
-
-	gint waiting;		/* if we are waiting for a new message, count of waiting processes */
-	pthread_t id;		/* our running child thread */
-	gint have_thread;
-	GList *id_list;		/* if THREAD_NEW, then a list of our child threads in thread_info structs */
-
-	EThreadFunc destroy;
-	gpointer destroy_data;
-
-	EThreadFunc received;
-	gpointer received_data;
-
-	EThreadFunc lost;
-	gpointer lost_data;
-};
-
-/* All active threads */
-static EDList ethread_list = E_DLIST_INITIALISER(ethread_list);
-static pthread_mutex_t ethread_lock = PTHREAD_MUTEX_INITIALIZER;
-
-#define E_THREAD_QUIT_REPLYPORT ((struct _EMsgPort *)~0)
-
-static void thread_destroy_msg(EThread *e, EMsg *m);
-
-static struct _thread_info *thread_find(EThread *e, pthread_t id)
-{
-	GList *node;
-	struct _thread_info *info;
-
-	node = e->id_list;
-	while (node) {
-		info = node->data;
-		if (pthread_equal (info->id, id))
-			return info;
-		node = node->next;
-	}
-	return NULL;
-}
-
-#if 0
-static void thread_remove(EThread *e, pthread_t id)
-{
-	GList *node;
-	struct _thread_info *info;
-
-	node = e->id_list;
-	while (node) {
-		info = node->data;
-		if (pthread_equal (info->id, id)) {
-			e->id_list = g_list_remove(e->id_list, info);
-			g_free(info);
-		}
-		node = node->next;
-	}
-}
-#endif
-
-EThread *e_thread_new(e_thread_t type)
-{
-	EThread *e;
-
-	e = g_malloc0(sizeof(*e));
-	pthread_mutex_init(&e->mutex, NULL);
-	e->type = type;
-	e->server_port = e_msgport_new();
-	e->have_thread = FALSE;
-	e->queue_limit = INT_MAX;
-
-	pthread_mutex_lock(&ethread_lock);
-	e_dlist_addtail(&ethread_list, (EDListNode *)e);
-	pthread_mutex_unlock(&ethread_lock);
-
-	return e;
-}
-
-/* close down the threads & resources etc */
-void e_thread_destroy(EThread *e)
-{
-	gint busy = FALSE;
-	EMsg *msg;
-	struct _thread_info *info;
-	GList *l;
-
-	/* make sure we soak up all the messages first */
-	while ((msg = e_msgport_get(e->server_port))) {
-		thread_destroy_msg(e, msg);
-	}
-
-	pthread_mutex_lock(&e->mutex);
-
-	switch (e->type) {
-	case E_THREAD_QUEUE:
-	case E_THREAD_DROP:
-		/* if we have a thread, 'kill' it */
-		if (e->have_thread) {
-			pthread_t id = e->id;
-			t(printf("Sending thread '%" G_GUINT64_FORMAT "' quit message\n", e_util_pthread_id(id)));
-
-			e->have_thread = FALSE;
-
-			msg = g_malloc0(sizeof(*msg));
-			msg->reply_port = E_THREAD_QUIT_REPLYPORT;
-			e_msgport_put(e->server_port, msg);
-
-			pthread_mutex_unlock(&e->mutex);
-			t(printf("Joining thread '%" G_GUINT64_FORMAT "'\n", e_util_pthread_id(id)));
-			pthread_join(id, NULL);
-			t(printf("Joined thread '%" G_GUINT64_FORMAT "'!\n", e_util_pthread_id(id)));
-			pthread_mutex_lock(&e->mutex);
-		}
-		busy = e->have_thread;
-		break;
-	case E_THREAD_NEW:
-		/* first, send everyone a quit message */
-		l = e->id_list;
-		while (l) {
-			info = l->data;
-			t(printf("Sending thread '%" G_GUINT64_FORMAT "' quit message\n", e_util_pthread_id(info->id)));
-			msg = g_malloc0(sizeof(*msg));
-			msg->reply_port = E_THREAD_QUIT_REPLYPORT;
-			e_msgport_put(e->server_port, msg);
-			l = l->next;
-		}
-
-		/* then, wait for everyone to quit */
-		while (e->id_list) {
-			info = e->id_list->data;
-			e->id_list = g_list_remove(e->id_list, info);
-			pthread_mutex_unlock(&e->mutex);
-			t(printf("Joining thread '%" G_GUINT64_FORMAT "'\n", e_util_pthread_id(info->id)));
-			pthread_join(info->id, NULL);
-			t(printf("Joined thread '%" G_GUINT64_FORMAT "'!\n", e_util_pthread_id(info->id)));
-			pthread_mutex_lock(&e->mutex);
-			g_free(info);
-		}
-		busy = g_list_length(e->id_list) != 0;
-		break;
-	}
-
-	pthread_mutex_unlock(&e->mutex);
-
-	/* and clean up, if we can */
-	if (busy) {
-		g_warning("threads were busy, leaked EThread");
-		return;
-	}
-
-	pthread_mutex_lock(&ethread_lock);
-	e_dlist_remove((EDListNode *)e);
-	pthread_mutex_unlock(&ethread_lock);
-
-	pthread_mutex_destroy(&e->mutex);
-	e_msgport_destroy(e->server_port);
-	g_free(e);
-}
-
-/* set the queue maximum depth, what happens when the queue
-   fills up depends on the queue type */
-void e_thread_set_queue_limit(EThread *e, gint limit)
-{
-	e->queue_limit = limit;
-}
-
-/* set a msg destroy callback, this can not call any e_thread functions on @e */
-void e_thread_set_msg_destroy(EThread *e, EThreadFunc destroy, gpointer data)
-{
-	pthread_mutex_lock(&e->mutex);
-	e->destroy = destroy;
-	e->destroy_data = data;
-	pthread_mutex_unlock(&e->mutex);
-}
-
-/* set a message lost callback, called if any message is discarded */
-void e_thread_set_msg_lost(EThread *e, EThreadFunc lost, gpointer data)
-{
-	pthread_mutex_lock(&e->mutex);
-	e->lost = lost;
-	e->lost_data = lost;
-	pthread_mutex_unlock(&e->mutex);
-}
-
-/* set a reply port, if set, then send messages back once finished */
-void e_thread_set_reply_port(EThread *e, EMsgPort *reply_port)
-{
-	e->reply_port = reply_port;
-}
-
-/* set a received data callback */
-void e_thread_set_msg_received(EThread *e, EThreadFunc received, gpointer data)
-{
-	pthread_mutex_lock(&e->mutex);
-	e->received = received;
-	e->received_data = data;
-	pthread_mutex_unlock(&e->mutex);
-}
-
-/* find out if we're busy doing any work, e==NULL, check for all work */
-gint e_thread_busy(EThread *e)
-{
-	gint busy = FALSE;
-
-	if (e == NULL) {
-		pthread_mutex_lock(&ethread_lock);
-		e = (EThread *)ethread_list.head;
-		while (e->next && !busy) {
-			busy = e_thread_busy(e);
-			e = e->next;
-		}
-		pthread_mutex_unlock(&ethread_lock);
-	} else {
-		pthread_mutex_lock(&e->mutex);
-		switch (e->type) {
-		case E_THREAD_QUEUE:
-		case E_THREAD_DROP:
-			busy = e->waiting != 1 && e->have_thread;
-			break;
-		case E_THREAD_NEW:
-			busy = e->waiting != g_list_length(e->id_list);
-			break;
-		}
-		pthread_mutex_unlock(&e->mutex);
-	}
-
-	return busy;
-}
-
-static void
-thread_destroy_msg(EThread *e, EMsg *m)
-{
-	EThreadFunc func;
-	gpointer func_data;
-
-	/* we do this so we never get an incomplete/unmatched callback + data */
-	pthread_mutex_lock(&e->mutex);
-	func = e->destroy;
-	func_data = e->destroy_data;
-	pthread_mutex_unlock(&e->mutex);
-
-	if (func)
-		func(e, m, func_data);
-}
-
-static void
-thread_received_msg(EThread *e, EMsg *m)
-{
-	EThreadFunc func;
-	gpointer func_data;
-
-	/* we do this so we never get an incomplete/unmatched callback + data */
-	pthread_mutex_lock(&e->mutex);
-	func = e->received;
-	func_data = e->received_data;
-	pthread_mutex_unlock(&e->mutex);
-
-	if (func)
-		func(e, m, func_data);
-	else
-		g_warning("No processing callback for EThread, message unprocessed");
-}
-
-static void
-thread_lost_msg(EThread *e, EMsg *m)
-{
-	EThreadFunc func;
-	gpointer func_data;
-
-	/* we do this so we never get an incomplete/unmatched callback + data */
-	pthread_mutex_lock(&e->mutex);
-	func = e->lost;
-	func_data = e->lost_data;
-	pthread_mutex_unlock(&e->mutex);
-
-	if (func)
-		func(e, m, func_data);
-}
-
-/* the actual thread dispatcher */
-static gpointer
-thread_dispatch(gpointer din)
-{
-	EThread *e = din;
-	EMsg *m;
-	struct _thread_info *info;
-	pthread_t self = pthread_self();
-
-	t(printf("dispatch thread started: %" G_GUINT64_FORMAT "\n", e_util_pthread_id(self)));
-
-	while (1) {
-		pthread_mutex_lock(&e->mutex);
-		m = e_msgport_get(e->server_port);
-		if (m == NULL) {
-			/* nothing to do?  If we are a 'new' type thread, just quit.
-			   Otherwise, go into waiting (can be cancelled here) */
-			info = thread_find(e, self);
-			if (info)
-				info->busy = FALSE;
-			e->waiting++;
-			pthread_mutex_unlock(&e->mutex);
-			m = e_msgport_wait(e->server_port);
-			pthread_mutex_lock(&e->mutex);
-			e->waiting--;
-		}
-
-		if (m->reply_port == E_THREAD_QUIT_REPLYPORT) {
-			t(printf("Thread %" G_GUINT64_FORMAT " got quit message\n", e_util_pthread_id(self)));
-			/* Handle a quit message, say we're quitting, free the message, and break out of the loop */
-			info = thread_find(e, self);
-			if (info)
-				info->busy = 2;
-			pthread_mutex_unlock(&e->mutex);
-			g_free(m);
-			break;
-		} else {
-			info = thread_find(e, self);
-			if (info)
-				info->busy = TRUE;
-		}
-		pthread_mutex_unlock(&e->mutex);
-
-		t(printf("got message in dispatch thread\n"));
-
-		/* process it */
-		thread_received_msg(e, m);
-
-		/* if we have a reply port, send it back, otherwise, lose it */
-		if (m->reply_port) {
-			e_msgport_reply(m);
-		} else {
-			thread_destroy_msg(e, m);
-		}
-	}
-
-	return NULL;
-}
-
-/* send a message to the thread, start thread if necessary */
-void e_thread_put(EThread *e, EMsg *msg)
-{
-	pthread_t id;
-	EMsg *dmsg = NULL;
-
-	pthread_mutex_lock(&e->mutex);
-
-	/* the caller forgot to tell us what to do, well, we can't do anything can we */
-	if (e->received == NULL) {
-		pthread_mutex_unlock(&e->mutex);
-		g_warning("EThread called with no receiver function, no work to do!");
-		thread_destroy_msg(e, msg);
-		return;
-	}
-
-	msg->reply_port = e->reply_port;
-
-	switch (e->type) {
-	case E_THREAD_QUEUE:
-		/* if the queue is full, lose this new addition */
-		if (g_async_queue_length(e->server_port->queue) < e->queue_limit) {
-			e_msgport_put(e->server_port, msg);
-		} else {
-			printf("queue limit reached, dropping new message\n");
-			dmsg = msg;
-		}
-		break;
-	case E_THREAD_DROP:
-		/* if the queue is full, lose the oldest (unprocessed) message */
-		if (g_async_queue_length(e->server_port->queue) < e->queue_limit) {
-			e_msgport_put(e->server_port, msg);
-		} else {
-			printf("queue limit reached, dropping old message\n");
-			e_msgport_put(e->server_port, msg);
-			dmsg = e_msgport_get(e->server_port);
-		}
-		break;
-	case E_THREAD_NEW:
-		/* it is possible that an existing thread can catch this message, so
-		   we might create a thread with no work to do.
-		   but that doesn't matter, the other alternative that it be lost is worse */
-		e_msgport_put(e->server_port, msg);
-		if (e->waiting == 0
-		    && g_list_length(e->id_list) < e->queue_limit
-		    && pthread_create(&id, NULL, thread_dispatch, e) == 0) {
-			struct _thread_info *info = g_malloc0(sizeof(*info));
-			t(printf("created NEW thread %" G_GUINT64_FORMAT "\n", e_util_pthread_id(id)));
-			info->id = id;
-			info->busy = TRUE;
-			e->id_list = g_list_append(e->id_list, info);
-		}
-		pthread_mutex_unlock(&e->mutex);
-		return;
-	}
-
-	/* create the thread, if there is none to receive it yet */
-	if (!e->have_thread) {
-		gint err;
-
-		if ((err = pthread_create(&e->id, NULL, thread_dispatch, e)) != 0) {
-			g_warning("Could not create dispatcher thread, message queued?: %s", g_strerror(err));
-		} else {
-			e->have_thread = TRUE;
-		}
-	}
-
-	pthread_mutex_unlock(&e->mutex);
-
-	if (dmsg) {
-		thread_lost_msg(e, dmsg);
-		thread_destroy_msg(e, dmsg);
-	}
-}
-#endif     /* EDS_DISABLE_DEPRECATED */
-
-/* yet-another-mutex interface */
-struct _EMutex {
-	gint type;
-	pthread_t owner;
-	gint have_owner;
-	short waiters;
-	short depth;
-	pthread_mutex_t mutex;
-	pthread_cond_t cond;
-};
-
-/* sigh, this is just painful to have to need, but recursive
-   read/write, etc mutexes just aren't very common in thread
-   implementations */
-/* TODO: Just make it use recursive mutexes if they are available */
-EMutex *e_mutex_new(e_mutex_t type)
-{
-	struct _EMutex *m;
-
-	m = g_malloc(sizeof(*m));
-	m->type = type;
-	m->waiters = 0;
-	m->depth = 0;
-	m->have_owner = FALSE;
-
-	switch (type) {
-	case E_MUTEX_SIMPLE:
-		pthread_mutex_init(&m->mutex, NULL);
-		break;
-	case E_MUTEX_REC:
-		pthread_mutex_init(&m->mutex, NULL);
-		pthread_cond_init(&m->cond, NULL);
-		break;
-		/* read / write ?  flags for same? */
-	}
-
-	return m;
-}
-
-gint e_mutex_destroy(EMutex *m)
-{
-	gint ret = 0;
-
-	switch (m->type) {
-	case E_MUTEX_SIMPLE:
-		ret = pthread_mutex_destroy(&m->mutex);
-		if (ret == -1)
-			g_warning("EMutex destroy failed: %s", g_strerror(errno));
-		g_free(m);
-		break;
-	case E_MUTEX_REC:
-		ret = pthread_mutex_destroy(&m->mutex);
-		if (ret == -1)
-			g_warning("EMutex destroy failed: %s", g_strerror(errno));
-		ret = pthread_cond_destroy(&m->cond);
-		if (ret == -1)
-			g_warning("EMutex destroy failed: %s", g_strerror(errno));
-		g_free(m);
-
-	}
-	return ret;
-}
-
-gint e_mutex_lock(EMutex *m)
-{
-	pthread_t id;
-	gint err;
-
-	switch (m->type) {
-	case E_MUTEX_SIMPLE:
-		return pthread_mutex_lock(&m->mutex);
-	case E_MUTEX_REC:
-		id = pthread_self();
-		if ((err = pthread_mutex_lock(&m->mutex)) != 0)
-			return err;
-		while (1) {
-			if (!m->have_owner) {
-				m->owner = id;
-				m->have_owner = TRUE;
-				m->depth = 1;
-				break;
-			} else if (pthread_equal (id, m->owner)) {
-				m->depth++;
-				break;
-			} else {
-				m->waiters++;
-				if ((err = pthread_cond_wait(&m->cond, &m->mutex)) != 0)
-					return err;
-				m->waiters--;
-			}
-		}
-		return pthread_mutex_unlock(&m->mutex);
-	}
-
-	return EINVAL;
-}
-
-gint e_mutex_unlock(EMutex *m)
-{
-	gint err;
-
-	switch (m->type) {
-	case E_MUTEX_SIMPLE:
-		return pthread_mutex_unlock(&m->mutex);
-	case E_MUTEX_REC:
-		if ((err = pthread_mutex_lock(&m->mutex)) != 0)
-			return err;
-		g_assert(m->have_owner && pthread_equal(m->owner, pthread_self()));
-
-		m->depth--;
-		if (m->depth == 0) {
-			m->have_owner = FALSE;
-			if (m->waiters > 0)
-				pthread_cond_signal(&m->cond);
-		}
-		return pthread_mutex_unlock(&m->mutex);
-	}
-
-	errno = EINVAL;
-	return -1;
-}
-
-void e_mutex_assert_locked(EMutex *m)
-{
-	g_return_if_fail (m->type == E_MUTEX_REC);
-	pthread_mutex_lock(&m->mutex);
-	g_assert(m->have_owner && pthread_equal(m->owner, pthread_self()));
-	pthread_mutex_unlock(&m->mutex);
-}
-
-gint e_mutex_cond_wait(gpointer vcond, EMutex *m)
-{
-	gint ret;
-	pthread_cond_t *cond = vcond;
-
-	switch (m->type) {
-	case E_MUTEX_SIMPLE:
-		return pthread_cond_wait(cond, &m->mutex);
-	case E_MUTEX_REC:
-		if ((ret = pthread_mutex_lock(&m->mutex)) != 0)
-			return ret;
-		g_assert(m->have_owner && pthread_equal(m->owner, pthread_self()));
-		ret = pthread_cond_wait(cond, &m->mutex);
-		g_assert(m->have_owner && pthread_equal(m->owner, pthread_self()));
-		pthread_mutex_unlock(&m->mutex);
-		return ret;
-	default:
-		g_return_val_if_reached(-1);
-	}
-}
-
-#ifdef STANDALONE
-
-static EMsgPort *server_port;
-
-gpointer fdserver(gpointer data)
-{
-	gint fd;
-	EMsg *msg;
-	gint id = (gint)data;
-	fd_set rfds;
-
-	fd = e_msgport_fd(server_port);
-
-	while (1) {
-		gint count = 0;
-
-		printf("server %d: waiting on fd %d\n", id, fd);
-		FD_ZERO(&rfds);
-		FD_SET(fd, &rfds);
-		select(fd+1, &rfds, NULL, NULL, NULL);
-		printf("server %d: Got async notification, checking for messages\n", id);
-		while ((msg = e_msgport_get(server_port))) {
-			printf("server %d: got message\n", id);
-			g_usleep(1000000);
-			printf("server %d: replying\n", id);
-			e_msgport_reply(msg);
-			count++;
-		}
-		printf("server %d: got %d messages\n", id, count);
-	}
-}
-
-gpointer server(gpointer data)
-{
-	EMsg *msg;
-	gint id = (gint)data;
-
-	while (1) {
-		printf("server %d: waiting\n", id);
-		msg = e_msgport_wait(server_port);
-		if (msg) {
-			printf("server %d: got message\n", id);
-			g_usleep(1000000);
-			printf("server %d: replying\n", id);
-			e_msgport_reply(msg);
-		} else {
-			printf("server %d: didn't get message\n", id);
-		}
-	}
-	return NULL;
-}
-
-gpointer client(gpointer data)
-{
-	EMsg *msg;
-	EMsgPort *replyport;
-	gint i;
-
-	replyport = e_msgport_new();
-	msg = g_malloc0(sizeof(*msg));
-	msg->reply_port = replyport;
-	for (i=0;i<10;i++) {
-		/* synchronous operation */
-		printf("client: sending\n");
-		e_msgport_put(server_port, msg);
-		printf("client: waiting for reply\n");
-		e_msgport_wait(replyport);
-		printf("client: got reply\n");
-	}
-
-	printf("client: sleeping ...\n");
-	g_usleep(2000000);
-	printf("client: sending multiple\n");
-
-	for (i=0;i<10;i++) {
-		msg = g_malloc0(sizeof(*msg));
-		msg->reply_port = replyport;
-		e_msgport_put(server_port, msg);
-	}
-
-	printf("client: receiving multiple\n");
-	for (i=0;i<10;i++) {
-		msg = e_msgport_wait(replyport);
-		g_free(msg);
-	}
-
-	printf("client: done\n");
-	return NULL;
-}
-
-gint main(gint argc, gchar **argv)
-{
-	pthread_t serverid, clientid;
-
-	g_thread_init(NULL);
-
-#ifdef G_OS_WIN32
-	{
-		WSADATA wsadata;
-		if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0)
-			g_error ("Windows Sockets could not be initialized");
-	}
-#endif
-
-	server_port = e_msgport_new();
-
-	/*pthread_create(&serverid, NULL, server, (gpointer)1);*/
-	pthread_create(&serverid, NULL, fdserver, (gpointer)1);
-	pthread_create(&clientid, NULL, client, NULL);
-
-	g_usleep(60000000);
-
-	return 0;
-}
-#endif
diff --git a/libedataserver/e-msgport.h b/libedataserver/e-msgport.h
index 59b116c..83c20a0 100644
--- a/libedataserver/e-msgport.h
+++ b/libedataserver/e-msgport.h
@@ -50,71 +50,4 @@ void em_cache_node_unref(EMCache *emc, EMCacheNode *n);
 void em_cache_add(EMCache *emc, EMCacheNode *n);
 void em_cache_clear(EMCache *emc);
 
-#ifndef EDS_DISABLE_DEPRECATED
-/* message ports - a simple inter-thread 'ipc' primitive */
-/* opaque handle */
-typedef struct _EMsgPort EMsgPort;
-
-/* header for any message */
-typedef struct _EMsg {
-	EDListNode ln;
-	EMsgPort *reply_port;
-	gint flags;
-} EMsg;
-
-EMsgPort *e_msgport_new(void);
-void e_msgport_destroy(EMsgPort *mp);
-/* get a fd that can be used to wait on the port asynchronously */
-gint e_msgport_fd(EMsgPort *mp);
-void e_msgport_put(EMsgPort *mp, EMsg *msg);
-EMsg *e_msgport_wait(EMsgPort *mp);
-EMsg *e_msgport_get(EMsgPort *mp);
-void e_msgport_reply(EMsg *msg);
-#ifdef HAVE_NSS
-struct PRFileDesc *e_msgport_prfd(EMsgPort *mp);
-#endif
-#endif /* EDS_DISABLE_DEPRECATED */
-
-#ifndef EDS_DISABLE_DEPRECATED
-/* e threads, a server thread with a message based request-response, and flexible queuing */
-typedef struct _EThread EThread;
-
-typedef enum {
-	E_THREAD_QUEUE = 0,	/* run one by one, until done, if the queue_limit is reached, discard new request */
-	E_THREAD_DROP,		/* run one by one, until done, if the queue_limit is reached, discard oldest requests */
-	E_THREAD_NEW		/* always run in a new thread, if the queue limit is reached, new requests are
-				   stored in the queue until a thread becomes available for it, creating a thread pool */
-} e_thread_t;
-
-typedef void (*EThreadFunc)(EThread *, EMsg *, gpointer data);
-
-EThread *e_thread_new(e_thread_t type);
-void e_thread_destroy(EThread *e);
-void e_thread_set_queue_limit(EThread *e, gint limit);
-void e_thread_set_msg_lost(EThread *e, EThreadFunc destroy, gpointer data);
-void e_thread_set_msg_destroy(EThread *e, EThreadFunc destroy, gpointer data);
-void e_thread_set_reply_port(EThread *e, EMsgPort *reply_port);
-void e_thread_set_msg_received(EThread *e, EThreadFunc received, gpointer data);
-void e_thread_put(EThread *e, EMsg *msg);
-gint e_thread_busy(EThread *e);
-#endif /* EDS_DISABLE_DEPRECATED */
-
-#ifndef EDS_DISABLE_DEPRECATED
-/* sigh, another mutex interface, this one allows different mutex types, portably */
-typedef struct _EMutex EMutex;
-
-typedef enum _e_mutex_t {
-	E_MUTEX_SIMPLE,		/* == pthread_mutex */
-	E_MUTEX_REC		/* recursive mutex */
-} e_mutex_t;
-
-EMutex *e_mutex_new(e_mutex_t type);
-gint e_mutex_destroy(EMutex *m);
-gint e_mutex_lock(EMutex *m);
-gint e_mutex_unlock(EMutex *m);
-void e_mutex_assert_locked(EMutex *m);
-/* this uses pthread cond's */
-gint e_mutex_cond_wait(gpointer cond, EMutex *m);
-#endif /* EDS_DISABLE_DEPRECATED */
-
 #endif
diff --git a/m4/evo_pthread_check.m4 b/m4/evo_pthread_check.m4
deleted file mode 100644
index 5a96fc5..0000000
--- a/m4/evo_pthread_check.m4
+++ /dev/null
@@ -1,16 +0,0 @@
-dnl EVO_PTHREAD_CHECK
-#serial 0.1
-AC_DEFUN([EVO_PTHREAD_CHECK],[
-	PTHREAD_LIB=""
-	AC_CHECK_LIB(pthread, pthread_create, [PTHREAD_LIB="-lpthread"],
-		[AC_CHECK_LIB(pthreads, pthread_create, [PTHREAD_LIB="-lpthreads"],
-			[AC_CHECK_LIB(c_r, pthread_create, [PTHREAD_LIB="-lc_r"],
-			[AC_CHECK_LIB(pthread, __pthread_attr_init_system, [PTHREAD_LIB="-lpthread"],
-				[AC_CHECK_FUNC(pthread_create)]
-			)]
-			)]
-		)]
-	)
-	AC_SUBST(PTHREAD_LIB)
-	AC_PROVIDE([EVO_PTHREAD_CHECK])
-])
