Index: plugins/folder-unsubscribe/folder-unsubscribe.c
===================================================================
--- plugins/folder-unsubscribe/folder-unsubscribe.c	(revision 33416)
+++ plugins/folder-unsubscribe/folder-unsubscribe.c	(working copy)
@@ -108,5 +108,5 @@ org_gnome_mail_folder_unsubscribe (EPlug
 	unsub = mail_msg_new (&unsubscribe_op, NULL, sizeof (struct _folder_unsub_t));
 	unsub->uri = g_strdup (target->uri);
 	
-	e_thread_put (mail_thread_new, (EMsg *) unsub);
+	mail_msg_unordered_push ((mail_msg_t *) unsub);
 }
Index: plugins/groupwise-features/share-folder-common.c
===================================================================
--- plugins/groupwise-features/share-folder-common.c	(revision 33416)
+++ plugins/groupwise-features/share-folder-common.c	(working copy)
@@ -239,7 +239,7 @@ create_folder (CamelStore *store, const 
 	m->done = done;
 	g_free (namebuf);
 	id = m->msg.seq;
-	e_thread_put (mail_thread_new, (EMsg *) m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 		
 	return id;
 }
Index: plugins/exchange-operations/exchange-folder.c
===================================================================
--- plugins/exchange-operations/exchange-folder.c	(revision 33416)
+++ plugins/exchange-operations/exchange-folder.c	(working copy)
@@ -134,7 +134,7 @@ org_gnome_exchange_folder_inbox_unsubscr
 	inbox_physical_uri = e_folder_get_physical_uri (inbox);
 
 	/* To get the CamelStore/Folder */
-        mail_get_folder (inbox_physical_uri, 0, exchange_get_folder, target_uri, mail_thread_new);
+        mail_get_folder (inbox_physical_uri, 0, exchange_get_folder, target_uri, mail_msg_unordered_push);
 
 
 }
Index: plugins/mark-all-read/mark-all-read.c
===================================================================
--- plugins/mark-all-read/mark-all-read.c	(revision 33416)
+++ plugins/mark-all-read/mark-all-read.c	(working copy)
@@ -44,7 +44,7 @@ org_gnome_mark_all_read (EPlugin *ep, EM
 		return;
 	}
 	
-	mail_get_folder(t->uri, 0, mar_got_folder, NULL, mail_thread_new);
+	mail_get_folder(t->uri, 0, mar_got_folder, NULL, mail_msg_unordered_push);
 }
 
 static void
Index: plugins/mailing-list-actions/mailing-list-actions.c
===================================================================
--- plugins/mailing-list-actions/mailing-list-actions.c	(revision 33416)
+++ plugins/mailing-list-actions/mailing-list-actions.c	(working copy)
@@ -89,7 +89,7 @@ void emla_list_action (EPlugin *item, EM
 	data->uri = strdup (sel->uri);
 
 	mail_get_message (sel->folder, (const char*) g_ptr_array_index (sel->uids, 0),
-	                  emla_list_action_do, data, mail_thread_new);
+	                  emla_list_action_do, data, mail_msg_unordered_push);
 }
 	
 void emla_list_action_do (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data)
Index: plugins/save-attachments/save-attachments.c
===================================================================
--- plugins/save-attachments/save-attachments.c	(revision 33416)
+++ plugins/save-attachments/save-attachments.c	(working copy)
@@ -403,5 +403,5 @@ org_gnome_save_attachments_save(EPlugin 
 	camel_object_ref(data->folder);
 	data->uid = g_strdup(target->uids->pdata[0]);
 
-	mail_get_message(data->folder, data->uid, save_got_message, data, mail_thread_new);
+	mail_get_message(data->folder, data->uid, save_got_message, data, mail_msg_unordered_push);
 }
Index: mail/em-folder-properties.c
===================================================================
--- mail/em-folder-properties.c	(revision 33416)
+++ mail/em-folder-properties.c	(working copy)
@@ -386,7 +386,7 @@ em_folder_properties_show(GtkWindow *par
 	}
 
 	if (folder == NULL)
-		mail_get_folder(uri, 0, emfp_dialog_got_folder, NULL, mail_thread_new);
+		mail_get_folder(uri, 0, emfp_dialog_got_folder, NULL, mail_msg_unordered_push);
 	else
 		emfp_dialog_got_folder((char *)uri, folder, NULL);
 }
Index: mail/em-folder-utils.c
===================================================================
--- mail/em-folder-utils.c	(revision 33416)
+++ mail/em-folder-utils.c	(working copy)
@@ -260,7 +260,7 @@ em_folder_utils_copy_folders(CamelStore 
 	m->delete = delete;
 	seq = m->msg.seq;
 
-	e_thread_put (mail_thread_new, (EMsg *) m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 
 	return seq;
 }
@@ -652,7 +652,7 @@ emfu_create_folder_real (CamelStore *sto
 	g_free (namebuf);
 	
 	id = m->msg.seq;
-	e_thread_put (mail_thread_new, (EMsg *) m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 	
 	return id;
 }
Index: mail/mail-vfolder.c
===================================================================
--- mail/mail-vfolder.c	(revision 33416)
+++ mail/mail-vfolder.c	(working copy)
@@ -188,7 +188,7 @@ vfolder_setup(CamelFolder *folder, const
 	m->sources_folder = sources_folder;
 	
 	id = m->msg.seq;
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
@@ -323,7 +323,7 @@ vfolder_adduri(const char *uri, GList *f
 	m->remove = remove;
 	
 	id = m->msg.seq;
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
@@ -447,7 +447,7 @@ mail_vfolder_add_uri(CamelStore *store, 
 		return;
 	}
 
-	g_assert(pthread_equal(pthread_self(), mail_gui_thread));
+	g_assert(mail_in_main_thread());
 
 	is_ignore = uri_is_ignore(store, curi);
 
@@ -540,7 +540,7 @@ mail_vfolder_delete_uri(CamelStore *stor
 
 	d(printf ("Deleting uri to check: %s\n", uri));
 	
-	g_assert (pthread_equal(pthread_self(), mail_gui_thread));
+	g_assert (mail_in_main_thread());
 	
 	changed = g_string_new ("");
 	
@@ -615,7 +615,7 @@ mail_vfolder_rename_uri(CamelStore *stor
 	if (context == NULL || uri_is_spethal(store, cfrom) || uri_is_spethal(store, cto))
 		return;
 
-	g_assert(pthread_equal(pthread_self(), mail_gui_thread));
+	g_assert(mail_in_main_thread());
 
 	from = em_uri_from_camel(cfrom);
 	to = em_uri_from_camel(cto);
Index: mail/em-format-html-print.c
===================================================================
--- mail/em-format-html-print.c	(revision 33416)
+++ mail/em-format-html-print.c	(working copy)
@@ -262,7 +262,7 @@ int em_format_html_print_message(EMForma
 		g_object_ref(source);
 	g_object_ref(efhp);
 
-	mail_get_message(folder, uid, emfhp_got_message, efhp, mail_thread_new);
+	mail_get_message(folder, uid, emfhp_got_message, efhp, mail_msg_unordered_push);
 
 	return 0;		/* damn async ... */
 }
Index: mail/em-folder-browser.c
===================================================================
--- mail/em-folder-browser.c	(revision 33416)
+++ mail/em-folder-browser.c	(working copy)
@@ -948,7 +948,7 @@ vfolder_setup(CamelFolder *folder, const
 	m->sources_folder = sources_folder;
 	
 	id = m->msg.seq;
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
Index: mail/em-folder-tree.c
===================================================================
--- mail/em-folder-tree.c	(revision 33416)
+++ mail/em-folder-tree.c	(working copy)
@@ -968,7 +968,7 @@ static void
 tree_drag_data_action(struct _DragDataReceivedAsync *m)
 {
 	m->move = m->action == GDK_ACTION_MOVE;
-	e_thread_put (mail_thread_new, (EMsg *) m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 static void
@@ -1917,7 +1917,7 @@ emft_tree_row_expanded (GtkTreeView *tre
 	m->top = full_name;
 	m->flags = CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST;
 	
-	e_thread_put (mail_thread_new, (EMsg *) m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 static gboolean
Index: mail/em-subscribe-editor.c
===================================================================
--- mail/em-subscribe-editor.c	(revision 33416)
+++ mail/em-subscribe-editor.c	(working copy)
@@ -229,7 +229,7 @@ sub_folder_subscribed (struct _mail_msg 
 	next = (struct _zsubscribe_msg *)e_dlist_remhead(&m->sub->subscribe);
 	if (next) {
 		next->sub->subscribe_id = next->msg.seq;
-		e_thread_put(mail_thread_new, (EMsg *)next);
+		mail_msg_unordered_push ((mail_msg_t *) next);
 	} else {
 		/* should it go off the model instead? */
 		sub_selection_changed(gtk_tree_view_get_selection(m->sub->tree), m->sub);
@@ -270,7 +270,7 @@ sub_subscribe_folder (EMSubscribe *sub, 
 	if (sub->subscribe_id == -1) {
 		sub->subscribe_id = id;
 		d(printf("running subscribe folder '%s'\n", spath));
-		e_thread_put (mail_thread_new, (EMsg *)m);
+		mail_msg_unordered_push ((mail_msg_t *) m);
 	} else {
 		d(printf("queueing subscribe folder '%s'\n", spath));
 		e_dlist_addtail(&sub->subscribe, (EDListNode *)m);
@@ -443,7 +443,7 @@ sub_queue_fill_level(EMSubscribe *sub, E
 
 	id = m->msg.seq;
 
-	e_thread_put (mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 	return id;
 }
 
Index: mail/mail-send-recv.c
===================================================================
--- mail/mail-send-recv.c	(revision 33416)
+++ mail/mail-send-recv.c	(working copy)
@@ -821,7 +821,7 @@ receive_update_got_folderinfo(CamelStore
 		m->folders = folders;
 		m->info = sinfo;
 
-		e_thread_put(mail_thread_new, (EMsg *)m);
+		mail_msg_unordered_push ((mail_msg_t *) m);
 	} else {
 		receive_done ("", data);
 	}
Index: mail/mail-ops.c
===================================================================
--- mail/mail-ops.c	(revision 33416)
+++ mail/mail-ops.c	(working copy)
@@ -221,7 +221,7 @@ mail_filter_folder (CamelFolder *source_
 		camel_filter_driver_remove_rule_by_name (m->driver, "new-mail-notification");
 	}
 	
-	e_thread_put (mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 /* convenience functions for it */
@@ -426,7 +426,7 @@ mail_fetch_mail (const char *source, int
 	if (status)
 		camel_filter_driver_set_status_func (fm->driver, status, status_data);
 	
-	e_thread_put (mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 /* ********************************************************************** */
@@ -839,7 +839,7 @@ mail_send_queue(CamelFolder *queue, cons
 	m->driver = camel_session_get_filter_driver (session, type, NULL);
 	camel_filter_driver_set_folder_func (m->driver, get_folder, get_data);
 
-	e_thread_put(mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 /* ** APPEND MESSAGE TO FOLDER ******************************************** */
@@ -921,7 +921,7 @@ mail_append_mail (CamelFolder *folder, C
 	m->done = done;
 	m->data = data;
 	
-	e_thread_put (mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 /* ** TRANSFER MESSAGES **************************************************** */
@@ -1036,7 +1036,7 @@ mail_transfer_messages (CamelFolder *sou
 	m->done = done;
 	m->data = data;
 	
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 /* ** SCAN SUBFOLDERS ***************************************************** */
@@ -1124,7 +1124,7 @@ mail_get_folderinfo (CamelStore *store, 
 	m->data = data;
 	id = m->msg.seq;
 
-	e_thread_put(mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 
 	return id;
 }
@@ -1250,7 +1250,7 @@ static struct _mail_msg_op get_folder_op
 int
 mail_get_folder (const char *uri, guint32 flags,
 		 void (*done)(char *uri, CamelFolder *folder, void *data),
-		 void *data, EThread *thread)
+		 void *data, MailMsgDispatchFunc dispatch)
 {
 	struct _get_folder_msg *m;
 	int id;
@@ -1262,7 +1262,7 @@ mail_get_folder (const char *uri, guint3
 	m->done = done;
 	
 	id = m->msg.seq;
-	e_thread_put(thread, (EMsg *)m);
+	dispatch ((mail_msg_t *) m);
 	return id;
 }
 
@@ -1340,7 +1340,7 @@ mail_get_store (const char *uri, CamelOp
 	m->done = done;
 	
 	id = m->msg.seq;
-	e_thread_put (mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 	return id;
 }
 
@@ -1437,7 +1437,7 @@ mail_remove_folder (const char *uri, voi
 	m->data = data;
 	m->done = done;
 	
-	e_thread_put (mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 /* ** SYNC FOLDER ********************************************************* */
@@ -1498,7 +1498,7 @@ mail_sync_folder(CamelFolder *folder, vo
 	m->data = data;
 	m->done = done;
 
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 /* ** SYNC STORE ********************************************************* */
@@ -1568,7 +1568,7 @@ mail_sync_store(CamelStore *store, int e
 	m->data = data;
 	m->done = done;
 
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 /* ******************************************************************************** */
@@ -1604,7 +1604,7 @@ mail_refresh_folder(CamelFolder *folder,
 	m->data = data;
 	m->done = done;
 
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 /* ******************************************************************************** */
@@ -1640,7 +1640,7 @@ mail_expunge_folder(CamelFolder *folder,
 	m->data = data;
 	m->done = done;
 
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 /* ******************************************************************************** */
@@ -1723,7 +1723,7 @@ mail_empty_trash(EAccount *account, void
 	m->data = data;
 	m->done = done;
 
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 /* ** GET MESSAGE(s) ***************************************************** */
@@ -1783,7 +1783,7 @@ static struct _mail_msg_op get_message_o
 void
 mail_get_message(CamelFolder *folder, const char *uid, void (*done) (CamelFolder *folder, const char *uid,
 								     CamelMimeMessage *msg, void *data),
-		 void *data, EThread *thread)
+		 void *data, MailMsgDispatchFunc dispatch)
 {
 	struct _get_message_msg *m;
 	
@@ -1795,7 +1795,7 @@ mail_get_message(CamelFolder *folder, co
 	m->done = (void (*) (CamelFolder *, const char *, CamelMimeMessage *, void *)) done;
 	m->cancel = camel_operation_new(NULL, NULL);
 	
-	e_thread_put(thread, (EMsg *)m);
+	dispatch ((mail_msg_t *) m);
 }
 
 typedef void (*get_done)(CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data, CamelException *);
@@ -1821,7 +1821,7 @@ static struct _mail_msg_op get_messagex_
    mail_get_message; it adds an exception argument to the callback */
 void
 mail_get_messagex(CamelFolder *folder, const char *uid, void (*done) (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data, CamelException *),
-		 void *data, EThread *thread)
+		 void *data, MailMsgDispatchFunc dispatch)
 {
 	struct _get_message_msg *m;
 	
@@ -1833,7 +1833,7 @@ mail_get_messagex(CamelFolder *folder, c
 	m->done = (void (*) (CamelFolder *, const char *, CamelMimeMessage *, void *)) done;
 	m->cancel = camel_operation_new(NULL, NULL);
 	
-	e_thread_put(thread, (EMsg *)m);
+	dispatch ((mail_msg_t *) m);
 }
 
 /* ********************************************************************** */
@@ -1920,7 +1920,7 @@ mail_get_messages(CamelFolder *folder, G
 	m->data = data;
 	m->done = done;
 
-	e_thread_put(mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 /* ** SAVE MESSAGES ******************************************************* */
@@ -2063,7 +2063,7 @@ mail_save_messages(CamelFolder *folder, 
 	m->done = done;
 
 	id = m->msg.seq;
-	e_thread_put(mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 
 	return id;
 }
@@ -2156,7 +2156,7 @@ mail_save_part (CamelMimePart *part, con
 	m->readonly = readonly;
 	
 	id = m->msg.seq;
-	e_thread_put (mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 	
 	return id;
 }
@@ -2240,7 +2240,7 @@ mail_prep_offline(const char *uri,
 	m->data = data;
 	m->done = done;
 
-	e_thread_put(mail_thread_queued_slow, (EMsg *)m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 /* ** GO OFFLINE ***************************************************** */
@@ -2345,7 +2345,7 @@ mail_store_set_offline (CamelStore *stor
 	m->done = done;
 
 	id = m->msg.seq;
-	e_thread_put(mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 
 	return id;
 }
@@ -2433,7 +2433,7 @@ mail_check_service(const char *url, Came
 	m->data = data;
 	
 	id = m->msg.seq;
-	e_thread_put(mail_thread_new, (EMsg *)m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 
 	return id;
 }
Index: mail/em-composer-utils.c
===================================================================
--- mail/em-composer-utils.c	(revision 33416)
+++ mail/em-composer-utils.c	(working copy)
@@ -534,7 +534,7 @@ em_utils_composer_save_draft_cb (EMsgCom
 	    strcmp (account->drafts_folder_uri, default_drafts_folder_uri) != 0) {
 		int id;
 		
-		id = mail_get_folder (account->drafts_folder_uri, 0, save_draft_folder, &folder, mail_thread_new);
+		id = mail_get_folder (account->drafts_folder_uri, 0, save_draft_folder, &folder, mail_msg_unordered_push);
 		mail_msg_wait (id);
 		
 		if (!folder || !account->enabled) {
@@ -1085,7 +1085,7 @@ em_utils_redirect_message_by_uid (CamelF
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 	g_return_if_fail (uid != NULL);
 	
-	mail_get_message (folder, uid, redirect_msg, NULL, mail_thread_new);
+	mail_get_message (folder, uid, redirect_msg, NULL, mail_msg_unordered_push);
 }
 
 static void
@@ -1116,7 +1116,7 @@ em_utils_handle_receipt (CamelFolder *fo
 	}
 
 	if (msg == NULL) {
-		mail_get_messagex(folder, uid, emu_handle_receipt_message, NULL, mail_thread_new);
+		mail_get_messagex(folder, uid, emu_handle_receipt_message, NULL, mail_msg_unordered_push);
 		camel_message_info_free(info);
 		return;
 	}
@@ -1916,7 +1916,7 @@ em_utils_reply_to_message(CamelFolder *f
 		rd->source = source;
 		if (rd->source)
 			g_object_ref(rd->source);
-		mail_get_message(folder, uid, reply_to_message, rd, mail_thread_new);
+		mail_get_message(folder, uid, reply_to_message, rd, mail_msg_unordered_push);
 
 		return;
 	}
@@ -2088,5 +2088,5 @@ em_utils_post_reply_to_message_by_uid (C
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 	g_return_if_fail (uid != NULL);
 	
-	mail_get_message (folder, uid, post_reply_to_message, NULL, mail_thread_new);
+	mail_get_message (folder, uid, post_reply_to_message, NULL, mail_msg_unordered_push);
 }
Index: mail/mail-ops.h
===================================================================
--- mail/mail-ops.h	(revision 33416)
+++ mail/mail-ops.h	(working copy)
@@ -30,13 +30,14 @@ extern "C" {
 #pragma }
 #endif /* __cplusplus */
 
+#include "mail-mt.h"
+
 #include "camel/camel-store.h"
 #include "camel/camel-folder.h"
 #include "camel/camel-filter-driver.h"
 #include "camel/camel-mime-message.h"
 #include "camel/camel-operation.h"
 
-#include "libedataserver/e-msgport.h"
 #include "libedataserver/e-account.h"
 
 void mail_append_mail (CamelFolder *folder, CamelMimeMessage *message, CamelMessageInfo *info,
@@ -55,12 +56,12 @@ void mail_transfer_messages (CamelFolder
 void mail_get_message (CamelFolder *folder, const char *uid,
 		       void (*done) (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data),
 		       void *data,
-		       EThread *thread);
+		       MailMsgDispatchFunc dispatch);
 
 void
 mail_get_messagex(CamelFolder *folder, const char *uid,
 		  void (*done) (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data, CamelException *),
-		  void *data, EThread *thread);
+		  void *data, MailMsgDispatchFunc dispatch);
 
 /* get several messages */
 void mail_get_messages (CamelFolder *folder, GPtrArray *uids,
@@ -70,7 +71,7 @@ void mail_get_messages (CamelFolder *fol
 /* same for a folder */
 int mail_get_folder (const char *uri, guint32 flags,
 		     void (*done) (char *uri, CamelFolder *folder, void *data), void *data,
-		     EThread *thread);
+		     MailMsgDispatchFunc dispatch);
 
 /* and for a store */
 int mail_get_store (const char *uri, CamelOperation *op,
Index: mail/em-folder-view.c
===================================================================
--- mail/em-folder-view.c	(revision 33416)
+++ mail/em-folder-view.c	(working copy)
@@ -68,6 +68,7 @@
 #include <gtkhtml/gtkhtml-stream.h>
 
 #include <libedataserver/e-data-server-util.h>
+#include <libedataserver/e-msgport.h>
 
 #include "menus/gal-view-etable.h"
 #include "menus/gal-view-factory-etable.h"
@@ -692,7 +693,7 @@ emfv_got_folder(char *uri, CamelFolder *
 static void
 emfv_set_folder_uri(EMFolderView *emfv, const char *uri)
 {
-	mail_get_folder(uri, 0, emfv_got_folder, emfv, mail_thread_queued);
+	mail_get_folder(uri, 0, emfv_got_folder, emfv, mail_msg_fast_ordered_push);
 }
 
 static void
@@ -1612,7 +1613,7 @@ filter_type_uid (CamelFolder *folder, co
 	data->type = type;
 	data->source = source;
 	
-	mail_get_message (folder, uid, filter_type_got_message, data, mail_thread_new);
+	mail_get_message (folder, uid, filter_type_got_message, data, mail_msg_unordered_push);
 }
 
 static void
@@ -1710,7 +1711,7 @@ vfolder_type_uid (CamelFolder *folder, c
 	data->type = type;
 	data->uri = g_strdup (uri);
 	
-	mail_get_message (folder, uid, vfolder_type_got_message, data, mail_thread_new);
+	mail_get_message (folder, uid, vfolder_type_got_message, data, mail_msg_unordered_push);
 }
 
 static void
@@ -2369,7 +2370,7 @@ emfv_message_selected_timeout(void *data
 			g_object_ref (emfv);
 			/* TODO: we should manage our own thread stuff, would make cancelling outstanding stuff easier */
 			e_profile_event_emit("goto.load", emfv->displayed_uid, 0);
-			mail_get_messagex(emfv->folder, emfv->displayed_uid, emfv_list_done_message_selected, emfv, mail_thread_queued);
+			mail_get_messagex(emfv->folder, emfv->displayed_uid, emfv_list_done_message_selected, emfv, mail_msg_fast_ordered_push);
 		} else {
 			e_profile_event_emit("goto.empty", "", 0);
 			g_free(emfv->priv->selected_uid);
Index: mail/mail-mt.c
===================================================================
--- mail/mail-mt.c	(revision 33416)
+++ mail/mail-mt.c	(working copy)
@@ -29,7 +29,6 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 
-#include <libedataserver/e-msgport.h>
 #include <libedataserver/e-data-server-util.h>
 
 #include <camel/camel-url.h>
@@ -82,13 +81,9 @@ static GHashTable *mail_msg_active_table
 static pthread_mutex_t mail_msg_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t mail_msg_cond = PTHREAD_COND_INITIALIZER;
 
-pthread_t mail_gui_thread;
-
 MailAsyncEvent *mail_async_event;
 
-static void mail_msg_destroy(EThread *e, EMsg *msg, void *data);
-
-void *mail_msg_new(mail_msg_op_t *ops, EMsgPort *reply_port, size_t size)
+void *mail_msg_new(mail_msg_op_t *ops, EFlag *processed, size_t size)
 {
 	struct _mail_msg *msg;
 
@@ -112,7 +107,6 @@ void *mail_msg_new(mail_msg_op_t *ops, E
 					fprintf(log, "Logging async operations\n");
 
 				if (log_locks) {
-					fprintf(log, "Logging lock operations, mail_gui_thread = %" G_GINT64_MODIFIER "x\n\n", e_util_pthread_id(mail_gui_thread));
 					fprintf(log, "%" G_GINT64_MODIFIER "x: lock mail_msg_lock\n", e_util_pthread_id(pthread_self()));
 				}
 			} else {
@@ -123,9 +117,9 @@ void *mail_msg_new(mail_msg_op_t *ops, E
 	}
 #endif
 	msg = g_malloc0(size);
+	msg->processed = processed;  /* owned by caller */
 	msg->ops = ops;
 	msg->seq = mail_msg_seq++;
-	msg->msg.reply_port = reply_port;
 	msg->cancel = camel_operation_new(mail_operation_status, GINT_TO_POINTER(msg->seq));
 	camel_exception_init(&msg->ex);
 	msg->priv = g_malloc0(sizeof(*msg->priv));
@@ -308,9 +302,8 @@ void mail_msg_cancel(unsigned int msgid)
 void mail_msg_wait(unsigned int msgid)
 {
 	struct _mail_msg *m;
-	int ismain = pthread_equal(pthread_self(), mail_gui_thread);
 
-	if (ismain) {
+	if (mail_in_main_thread ()) {
 		MAIL_MT_LOCK(mail_msg_lock);
 		m = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid));
 		while (m) {
@@ -347,9 +340,7 @@ int mail_msg_active(unsigned int msgid)
 
 void mail_msg_wait_all(void)
 {
-	int ismain = pthread_equal(pthread_self(), mail_gui_thread);
-
-	if (ismain) {
+	if (mail_in_main_thread ()) {
 		MAIL_MT_LOCK(mail_msg_lock);
 		while (g_hash_table_size(mail_msg_active_table) > 0) {
 			MAIL_MT_UNLOCK(mail_msg_lock);
@@ -420,241 +411,193 @@ void mail_cancel_all(void)
 	MAIL_MT_UNLOCK(mail_msg_lock);
 }
 
-EMsgPort		*mail_gui_port;
-static GIOChannel	*mail_gui_channel;
-static guint		 mail_gui_watch;
-
-/* TODO: Merge these, gui_port2 doesn't do any mail_msg processing on the request (replies, forwards, frees) */
-EMsgPort		*mail_gui_port2;
-static GIOChannel	*mail_gui_channel2;
-static guint		 mail_gui_watch2;
-
-EMsgPort		*mail_gui_reply_port;
-static GIOChannel	*mail_gui_reply_channel;
-
-/* a couple of global threads available */
-#ifdef G_OS_WIN32
-#undef mail_thread_queued
-static
-#endif
-EThread *mail_thread_queued;	/* for operations that can (or should) be queued */
-EThread *mail_thread_queued_slow;	/* for operations that can (or should) be queued, but take a long time */
-EThread *mail_thread_new;	/* for operations that should run in a new thread each time */
-
-#ifdef G_OS_WIN32
-EThread *
-mail_win32_get_mail_thread_queued (void)
+#define PERIODIC_RATE_HZ 10
+static guint periodic_source_id = 0;
+static GAsyncQueue *main_loop_queue = NULL;
+static GAsyncQueue *msg_reply_queue = NULL;
+static GThread *main_thread = NULL;
+
+static void
+periodic_cleanup (void)
 {
-	return mail_thread_queued;
+	periodic_source_id = 0;
+
+	g_assert (main_loop_queue != NULL);
+	g_async_queue_unref (main_loop_queue);
+	main_loop_queue = NULL;
+
+	g_assert (msg_reply_queue != NULL);
+	g_async_queue_unref (msg_reply_queue);
+	msg_reply_queue = NULL;
 }
-#endif
 
 static gboolean
-mail_msgport_replied(GIOChannel *source, GIOCondition cond, void *d)
+periodic_processing (void)
 {
-	EMsgPort *port = (EMsgPort *)d;
-	mail_msg_t *m;
+	mail_msg_t *msg;
 
-	while (( m = (mail_msg_t *)e_msgport_get(port))) {
+	g_assert (main_loop_queue != NULL);
+	g_assert (msg_reply_queue != NULL);
 
-#ifdef MALLOC_CHECK
-		checkmem(m);
-		checkmem(m->cancel);
-		checkmem(m->priv);
-#endif
-
-#ifdef LOG_OPS
-		if (log_ops)
-			fprintf(log, "%p: Replied to GUI thread (exception `%s'\n", m,
-				camel_exception_get_description(&m->ex)?camel_exception_get_description(&m->ex):"None");
-#endif
+	/* check the main loop queue */
+	while ((msg = g_async_queue_try_pop (main_loop_queue)) != NULL) {
+
+		/* If the message has a "processed" EFlag, it must also have
+		 * a receive_msg() callback.  The receive_msg() callback is
+		 * responsible for setting the EFlag, and thread blocked on
+		 * the EFlag is reponsible for freeing it. */
+		if (msg->processed != NULL) {
+			g_assert (msg->ops->receive_msg != NULL);
+			msg->ops->receive_msg (msg);
+		} else {
+			if (msg->ops->receive_msg != NULL)
+				msg->ops->receive_msg (msg);
+			if (msg->ops->reply_msg != NULL)
+				msg->ops->reply_msg (msg);
+			mail_msg_free (msg);
+		}
+	}
 
-		if (m->ops->reply_msg)
-			m->ops->reply_msg(m);
-		mail_msg_check_error(m);
-		mail_msg_free(m);
+	/* check the reply queue */
+	while ((msg = g_async_queue_try_pop (msg_reply_queue)) != NULL) {
+		if (msg->ops->reply_msg != NULL)
+			msg->ops->reply_msg (msg);
+		mail_msg_check_error (msg);
+		mail_msg_free (msg);
 	}
 
 	return TRUE;
 }
 
-static gboolean
-mail_msgport_received(GIOChannel *source, GIOCondition cond, void *d)
+static void
+mail_msg_proxy (mail_msg_t *msg)
 {
-	EMsgPort *port = (EMsgPort *)d;
-	mail_msg_t *m;
+	if (msg->ops->describe_msg != NULL) {
+		gchar *text = msg->ops->describe_msg (msg, FALSE);
+		camel_operation_register (msg->cancel);
+		camel_operation_start (msg->cancel, "%s", text);
+		g_free (text);
+	}
+
+	if (msg->ops->receive_msg != NULL) {
+		mail_enable_stop ();
+		msg->ops->receive_msg (msg);
+		mail_disable_stop ();
+	}
+
+	if (msg->ops->describe_msg != NULL) {
+		camel_operation_end (msg->cancel);
+		camel_operation_unregister (msg->cancel);
+		MAIL_MT_LOCK (mail_msg_lock);
+		camel_operation_unref (msg->cancel);
+		msg->cancel = NULL;
+		MAIL_MT_UNLOCK (mail_msg_lock);
+	}
 
-	while (( m = (mail_msg_t *)e_msgport_get(port))) {
-#ifdef MALLOC_CHECK
-		checkmem(m);
-		checkmem(m->cancel);
-		checkmem(m->priv);
-#endif
+	g_async_queue_push (msg_reply_queue, msg);
+}
 
-#ifdef LOG_OPS
-		if (log_ops)
-			fprintf(log, "%p: Received at GUI thread\n", m);
-#endif
+void
+mail_msg_cleanup (void)
+{
+	GSource *source;
 
-		if (m->ops->receive_msg)
-			m->ops->receive_msg(m);
-		if (m->msg.reply_port)
-			e_msgport_reply((EMsg *)m);
-		else {
-			if (m->ops->reply_msg)
-				m->ops->reply_msg(m);
-			mail_msg_free(m);
-		}
-	}
+	mail_msg_wait_all();
 
-	return TRUE;
+	/* stop periodic processing */
+	source = g_main_context_find_source_by_id (
+		g_main_context_default (), periodic_source_id);
+	g_assert (source != NULL);
+	g_source_destroy (source);
 }
 
-/* Test code, lighterwight, more configurable calls */
-static gboolean
-mail_msgport_received2(GIOChannel *source, GIOCondition cond, void *d)
+void
+mail_msg_init (void)
 {
-	EMsgPort *port = (EMsgPort *)d;
-	mail_msg_t *m;
+	main_loop_queue = g_async_queue_new ();
+	msg_reply_queue = g_async_queue_new ();
 
-	while (( m = (mail_msg_t *)e_msgport_get(port))) {
-#ifdef LOG_OPS
-		if (log_ops)
-			fprintf(log, "%p: Received at GUI2 thread\n", m);
-#endif
+	/* start periodic processing */
+	periodic_source_id = g_timeout_add_full (
+		G_PRIORITY_DEFAULT,
+		1000 / PERIODIC_RATE_HZ,
+		(GSourceFunc) periodic_processing, NULL,
+		(GDestroyNotify) periodic_cleanup);
 
-		if (m->ops->receive_msg)
-			m->ops->receive_msg(m);
-		else
-			mail_msg_free(m);
-	}
+	mail_msg_active_table = g_hash_table_new (NULL, NULL);
+	main_thread = g_thread_self ();
 
-	return TRUE;
+	mail_async_event = mail_async_event_new ();
 }
 
-
-static void
-mail_msg_destroy(EThread *e, EMsg *msg, void *data)
+static gint
+mail_msg_compare (const mail_msg_t *msg1, const mail_msg_t *msg2)
 {
-	mail_msg_t *m = (mail_msg_t *)msg;
+	gint priority1 = msg1->priority;
+	gint priority2 = msg2->priority;
 
-#ifdef MALLOC_CHECK
-	checkmem(m);
-	checkmem(m->cancel);
-	checkmem(m->priv);
-#endif	
+	if (priority1 == priority2)
+		return 0;
 
-	mail_msg_free(m);
+	return (priority1 < priority2) ? 1 : -1;
 }
 
-static void
-mail_msg_received(EThread *e, EMsg *msg, void *data)
+static gpointer
+create_thread_pool (gpointer data)
 {
-	mail_msg_t *m = (mail_msg_t *)msg;
+	GThreadPool *thread_pool;
+	gint max_threads = GPOINTER_TO_INT (data);
 
-#ifdef MALLOC_CHECK
-	checkmem(m);
-	checkmem(m->cancel);
-	checkmem(m->priv);
-#endif
+	/* once created, run forever */
+	thread_pool = g_thread_pool_new (
+		(GFunc) mail_msg_proxy, NULL, max_threads, FALSE, NULL);
+	g_thread_pool_set_sort_function (
+		thread_pool, (GCompareDataFunc) mail_msg_compare, NULL);
 
-	if (m->ops->describe_msg) {
-		char *text = m->ops->describe_msg(m, FALSE);
+	return thread_pool;
+}
 
-#ifdef LOG_OPS
-		if (log_ops)
-			fprintf(log, "%p: Received at thread %" G_GINT64_MODIFIER "x: '%s'\n", m, e_util_pthread_id(pthread_self()), text);
-#endif
+void
+mail_msg_main_loop_push (mail_msg_t *msg)
+{
+	g_async_queue_push_sorted (main_loop_queue, msg,
+		(GCompareDataFunc) mail_msg_compare, NULL);
+}
 
-		d(printf("message received at thread\n"));
-		camel_operation_register(m->cancel);
-		camel_operation_start(m->cancel, "%s", text);
-		g_free(text);
-	}
-#ifdef LOG_OPS
-	else
-		if (log_ops)
-			fprintf(log, "%p: Received at thread %" G_GINT64_MODIFIER "x\n", m, e_util_pthread_id(pthread_self()));
-#endif
+void
+mail_msg_unordered_push (mail_msg_t *msg)
+{
+	static GOnce once = G_ONCE_INIT;
 
-	if (m->ops->receive_msg) {
-		mail_enable_stop();
-		m->ops->receive_msg(m);
-		mail_disable_stop();
-	}
+	g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (10));
 
-	if (m->ops->describe_msg) {
-		camel_operation_end(m->cancel);
-		camel_operation_unregister(m->cancel);
-		MAIL_MT_LOCK(mail_msg_lock);
-		camel_operation_unref(m->cancel);
-		m->cancel = NULL;
-		MAIL_MT_UNLOCK(mail_msg_lock);
-	}
+	g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
 }
 
-void mail_msg_cleanup(void)
+void
+mail_msg_fast_ordered_push (mail_msg_t *msg)
 {
-	mail_msg_wait_all();
-
-	e_thread_destroy(mail_thread_queued_slow);
-	e_thread_destroy(mail_thread_queued);
-	e_thread_destroy(mail_thread_new);
+	static GOnce once = G_ONCE_INIT;
 
-	g_io_channel_unref(mail_gui_channel);
-	g_io_channel_unref(mail_gui_reply_channel);
+	g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (1));
 
-	e_msgport_destroy(mail_gui_port);
-	e_msgport_destroy(mail_gui_reply_port);
+	g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
 }
 
-static guint
-em_channel_setup(EMsgPort **port, GIOChannel **channel, GIOFunc func)
+void
+mail_msg_slow_ordered_push (mail_msg_t *msg)
 {
-	GSource *source;
-	guint id;
+	static GOnce once = G_ONCE_INIT;
 
-	*port = e_msgport_new();
-#ifndef G_OS_WIN32
-	*channel = g_io_channel_unix_new(e_msgport_fd(*port));
-#else
-	*channel = g_io_channel_win32_new_socket(e_msgport_fd(*port));
-#endif
-	source = g_io_create_watch(*channel, G_IO_IN);
-	g_source_set_callback(source, (GSourceFunc)func, *port, NULL);
-	g_source_set_can_recurse(source, FALSE);
-	id = g_source_attach(source, NULL);
-	g_source_unref(source);
+	g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (1));
 
-	return id;
+	g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
 }
 
-void mail_msg_init(void)
+gboolean
+mail_in_main_thread (void)
 {
-	em_channel_setup(&mail_gui_reply_port, &mail_gui_reply_channel, mail_msgport_replied);
-	mail_gui_watch = em_channel_setup(&mail_gui_port, &mail_gui_channel, mail_msgport_received);
-	mail_gui_watch2 = em_channel_setup(&mail_gui_port2, &mail_gui_channel2, mail_msgport_received2);
-
-	mail_thread_queued = e_thread_new(E_THREAD_QUEUE);
-	e_thread_set_msg_destroy(mail_thread_queued, mail_msg_destroy, 0);
-	e_thread_set_msg_received(mail_thread_queued, mail_msg_received, 0);
-	e_thread_set_reply_port(mail_thread_queued, mail_gui_reply_port);
-
-	mail_thread_queued_slow = e_thread_new(E_THREAD_QUEUE);
-	e_thread_set_msg_destroy(mail_thread_queued_slow, mail_msg_destroy, 0);
-	e_thread_set_msg_received(mail_thread_queued_slow, mail_msg_received, 0);
-	e_thread_set_reply_port(mail_thread_queued_slow, mail_gui_reply_port);
-
-	mail_thread_new = e_thread_new(E_THREAD_NEW);
-	e_thread_set_msg_destroy(mail_thread_new, mail_msg_destroy, 0);
-	e_thread_set_msg_received(mail_thread_new, mail_msg_received, 0);
-	e_thread_set_reply_port(mail_thread_new, mail_gui_reply_port);
-	e_thread_set_queue_limit(mail_thread_new, 10);
-
-	mail_msg_active_table = g_hash_table_new(NULL, NULL);
-	mail_gui_thread = pthread_self();
-
-	mail_async_event = mail_async_event_new();
+	return (g_thread_self () == main_thread);
 }
 
 /* ********************************************************************** */
@@ -723,7 +666,6 @@ int mail_async_event_emit(MailAsyncEvent
 {
 	struct _proxy_msg *m;
 	int id;
-	int ismain = pthread_equal(pthread_self(), mail_gui_thread);
 
 	/* we dont have a reply port for this, we dont care when/if it gets executed, just queue it */
 	m = mail_msg_new(&async_event_op, NULL, sizeof(*m));
@@ -743,12 +685,12 @@ int mail_async_event_emit(MailAsyncEvent
 	/* We use an idle function instead of our own message port only because the
 	   gui message ports's notification buffer might overflow and deadlock us */
 	if (type == MAIL_ASYNC_GUI) {
-		if (ismain)
+		if (mail_in_main_thread ())
 			g_idle_add(idle_async_event, m);
 		else
-			e_msgport_put(mail_gui_port, (EMsg *)m);
+			mail_msg_main_loop_push((mail_msg_t *) m);
 	} else
-		e_thread_put(mail_thread_queued, (EMsg *)m);
+		mail_msg_fast_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
@@ -842,6 +784,9 @@ do_call(struct _mail_msg *mm)
 		m->ret = m->func(p1, p2, i1, p3, p4, p5);
 		break;
 	}
+
+	if (mm->processed != NULL)
+		e_flag_set (mm->processed);
 }
 
 static struct _mail_msg_op mail_call_op = {
@@ -856,23 +801,22 @@ void *mail_call_main(mail_call_t type, M
 	struct _call_msg *m;
 	void *ret;
 	va_list ap;
-	EMsgPort *reply = NULL;
-	int ismain = pthread_equal(pthread_self(), mail_gui_thread);
+	EFlag *processed = NULL;
 
 	va_start(ap, func);
 
-	if (!ismain)
-		reply = e_msgport_new();
+	if (!mail_in_main_thread ())
+		processed = e_flag_new ();
 
-	m = mail_msg_new(&mail_call_op, reply, sizeof(*m));
+	m = mail_msg_new(&mail_call_op, processed, sizeof(*m));
 	m->type = type;
 	m->func = func;
 	G_VA_COPY(m->ap, ap);
 
-	if (!ismain) {
-		e_msgport_put(mail_gui_port, (EMsg *)m);
-		e_msgport_wait(reply);
-		e_msgport_destroy(reply);
+	if (processed != NULL) {
+		mail_msg_main_loop_push((mail_msg_t *) m);
+		e_flag_wait (processed);
+		e_flag_free (processed);
 	} else {
 		do_call(&m->msg);
 	}
@@ -909,7 +853,7 @@ void mail_enable_stop(void)
 	busy_state++;
 	if (busy_state == 1) {
 		m = mail_msg_new(&set_busy_op, NULL, sizeof(*m));
-		e_msgport_put(mail_gui_port, (EMsg *)m);
+		mail_msg_main_loop_push((mail_msg_t *) m);
 	}
 	MAIL_MT_UNLOCK(status_lock);
 }
@@ -922,7 +866,7 @@ void mail_disable_stop(void)
 	busy_state--;
 	if (busy_state == 0) {
 		m = mail_msg_new(&set_busy_op, NULL, sizeof(*m));
-		e_msgport_put(mail_gui_port, (EMsg *)m);
+		mail_msg_main_loop_push((mail_msg_t *) m);
 	}
 	MAIL_MT_UNLOCK(status_lock);
 }
@@ -947,7 +891,7 @@ static void do_op_status(struct _mail_ms
 	char *out, *p, *o, c;
 	int pc;
 	
-	g_assert (pthread_equal(mail_gui_thread, pthread_self ()));
+	g_assert (mail_in_main_thread ());
 	
 	MAIL_MT_LOCK (mail_msg_lock);
 	
@@ -1055,7 +999,7 @@ mail_operation_status (struct _CamelOper
 	}
 	m->pc = pc;
 	m->data = data;
-	e_msgport_put(mail_gui_port, (EMsg *)m);
+	mail_msg_main_loop_push((mail_msg_t *) m);
 }
 
 /* ******************** */
Index: mail/mail-mt.h
===================================================================
--- mail/mail-mt.h	(revision 33416)
+++ mail/mail-mt.h	(working copy)
@@ -25,14 +25,15 @@
 
 #include <pthread.h>
 #include "camel/camel-exception.h"
-#include "libedataserver/e-msgport.h"
+#include "libedataserver/e-flag.h"
 #include "camel/camel-object.h"
 #include "camel/camel-operation.h"
 
 typedef struct _mail_msg {
-	EMsg msg;		/* parent type */
+	EFlag *processed;	/* optional */
 	struct _mail_msg_op *ops; /* operation functions */
 	unsigned int seq;	/* seq number for synchronisation */
+	gint priority;		/* priority (default = 0) */
 	CamelOperation *cancel;	/* a cancellation/status handle */
 	CamelException ex;	/* an initialised camel exception, upto the caller to use this */
 	struct _mail_msg_priv *priv; /* private for internal use */
@@ -51,8 +52,10 @@ typedef struct _mail_msg_op {
 void mail_msg_init(void);
 void mail_msg_cleanup (void);
 
+gboolean mail_in_main_thread (void);
+
 /* allocate a new message */
-void *mail_msg_new(mail_msg_op_t *ops, EMsgPort *reply_port, size_t size);
+void *mail_msg_new(mail_msg_op_t *ops, EFlag *processed, size_t size);
 void mail_msg_free(void *msg);
 void mail_msg_check_error(void *msg);
 void mail_msg_cancel(unsigned int msgid);
@@ -60,6 +63,14 @@ void mail_msg_wait(unsigned int msgid);
 void mail_msg_wait_all(void);
 int mail_msg_active(unsigned int msgid);
 
+/* dispatch a message */
+void mail_msg_main_loop_push (mail_msg_t *msg);
+void mail_msg_unordered_push (mail_msg_t *msg);
+void mail_msg_fast_ordered_push (mail_msg_t *msg);
+void mail_msg_slow_ordered_push (mail_msg_t *msg);
+
+typedef void (*MailMsgDispatchFunc) (mail_msg_t *msg);
+
 /* To implement the stop button */
 void *mail_cancel_hook_add(GDestroyNotify func, void *data);
 void mail_cancel_hook_remove(void *handle);
@@ -112,24 +123,6 @@ void *mail_call_main(mail_call_t type, M
 void mail_enable_stop(void);
 void mail_disable_stop(void);
 
-/* a message port that receives messages in the gui thread, used for sending port */
-extern EMsgPort *mail_gui_port;
-/* a message port that receives messages in the gui thread, used for the reply port */
-extern EMsgPort *mail_gui_reply_port;
-
-/* some globally available threads */
-#ifndef G_OS_WIN32
-extern EThread *mail_thread_queued;	/* for operations that can (or should) be queued */
-#else
-EThread *mail_win32_get_mail_thread_queued (void);
-#define mail_thread_queued mail_win32_get_mail_thread_queued ()
-#endif
-extern EThread *mail_thread_new;	/* for operations that should run in a new thread each time */
-extern EThread *mail_thread_queued_slow;	/* for operations that can (or should) be queued, but take a long time */
-
-/* The main thread. */
-extern pthread_t mail_gui_thread;
-
 /* A generic proxy event for anything that can be proxied during the life of the mailer (almost nothing) */
 /* Note that almost all objects care about the lifecycle of their events, so this cannot be used */
 extern MailAsyncEvent *mail_async_event;
Index: mail/importers/mail-importer.c
===================================================================
--- mail/importers/mail-importer.c	(revision 33416)
+++ mail/importers/mail-importer.c	(working copy)
@@ -329,7 +329,7 @@ mail_importer_import_mbox(const char *pa
 	}
 
 	id = m->msg.seq;
-	e_thread_put(mail_thread_queued, (EMsg *)m);
+	mail_msg_fast_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
Index: mail/importers/pine-importer.c
===================================================================
--- mail/importers/pine-importer.c	(revision 33416)
+++ mail/importers/pine-importer.c	(working copy)
@@ -350,7 +350,7 @@ mail_importer_pine_import(EImport *ei, E
 
 	id = m->msg.seq;
 	
-	e_thread_put(mail_thread_queued, (EMsg *)m);
+	mail_msg_fast_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
Index: mail/importers/elm-importer.c
===================================================================
--- mail/importers/elm-importer.c	(revision 33416)
+++ mail/importers/elm-importer.c	(working copy)
@@ -312,7 +312,7 @@ mail_importer_elm_import(EImport *ei, EI
 
 	id = m->msg.seq;
 	
-	e_thread_put(mail_thread_queued, (EMsg *)m);
+	mail_msg_fast_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
Index: mail/mail-folder-cache.c
===================================================================
--- mail/mail-folder-cache.c	(revision 33416)
+++ mail/mail-folder-cache.c	(working copy)
@@ -907,7 +907,7 @@ ping_store (gpointer key, gpointer val, 
 	m->store = store;
 	camel_object_ref (store);
 	
-	e_thread_put (mail_thread_queued_slow, (EMsg *) m);
+	mail_msg_slow_ordered_push ((mail_msg_t *) m);
 }
 
 static gboolean
@@ -952,7 +952,7 @@ mail_note_store(CamelStore *store, Camel
 	int hook = 0;
 	
 	g_assert(CAMEL_IS_STORE(store));
-	g_assert(pthread_equal(pthread_self(), mail_gui_thread));
+	g_assert(mail_in_main_thread());
 
 	LOCK(info_lock);
 
Index: mail/em-sync-stream.c
===================================================================
--- mail/em-sync-stream.c	(revision 33416)
+++ mail/em-sync-stream.c	(working copy)
@@ -25,42 +25,17 @@
 #include <config.h>
 #endif
 
-#include <string.h>
+#include "em-sync-stream.h"
+
 #include <stdio.h>
-#include <camel/camel-stream.h>
+#include <string.h>
 #include <camel/camel-object.h>
-#include <gtk/gtkmain.h>
-#include "em-sync-stream.h"
+#include <libedataserver/e-flag.h>
 
 #include "mail-mt.h"
 
-#define LOG_STREAM
-
-#define d(x) 
-
 #define EMSS_CLASS(x) ((EMSyncStreamClass *)(((CamelObject *)(x))->klass))
 
-struct _EMSyncStreamPrivate {
-	/* FIXME: use a single data port/gui channel for all instances */
-	/* TODO: possibly just use one of the mail-mt ports ... */
-	struct _EMsgPort *data_port, *reply_port;
-	struct _GIOChannel *gui_channel;
-	guint gui_watch;
-
-	char *buf_data;
-	int buf_used;
-	int buf_size;
-
-#ifdef LOG_STREAM
-	FILE *logfd;
-#endif
-};
-
-#ifdef LOG_STREAM
-int dolog;
-#endif
-
-/* Should probably expose messages to outside world ... so subclasses can extend */
 enum _write_msg_t {
 	EMSS_WRITE,
 	EMSS_FLUSH,
@@ -68,275 +43,168 @@ enum _write_msg_t {
 };
 
 struct _write_msg {
-	EMsg msg;
+	EMSyncStream *emss;
+	EFlag *processed;
 
 	enum _write_msg_t op;
 
-	const char *data;
-	size_t n;
+	const gchar *string;
+	gsize len;
 };
 
-static void em_sync_stream_class_init (EMSyncStreamClass *klass);
-static void em_sync_stream_init (CamelObject *object);
-static void em_sync_stream_finalize (CamelObject *object);
-
-static ssize_t stream_write(CamelStream *stream, const char *buffer, size_t n);
-static int stream_close(CamelStream *stream);
-static int stream_flush(CamelStream *stream);
-
 static CamelStreamClass *parent_class = NULL;
 
-CamelType
-em_sync_stream_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-	
-	if (type == CAMEL_INVALID_TYPE) {
-#ifdef LOG_STREAM
-		dolog = getenv("EVOLUTION_MAIL_LOG_HTML") != NULL;
-#endif
-		type = camel_type_register (CAMEL_STREAM_TYPE,
-					    "EMSyncStream",
-					    sizeof (EMSyncStream),
-					    sizeof (EMSyncStreamClass),
-					    (CamelObjectClassInitFunc) em_sync_stream_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) em_sync_stream_init,
-					    (CamelObjectFinalizeFunc) em_sync_stream_finalize);
-	}
-	
-	return type;
-}
-
-static void
-em_sync_stream_class_init (EMSyncStreamClass *klass)
-{
-	CamelStreamClass *stream_class = CAMEL_STREAM_CLASS (klass);
-	
-	parent_class = (CamelStreamClass *) CAMEL_STREAM_TYPE;
-	
-	/* virtual method overload */
-	stream_class->write = stream_write;
-	stream_class->flush = stream_flush;
-	stream_class->close = stream_close;
-}
-
 static gboolean
-emcs_gui_received(GIOChannel *source, GIOCondition cond, void *data)
+emss_process_message (struct _write_msg *msg)
 {
-	EMSyncStream *emss = data;
-	struct _EMSyncStreamPrivate *p = emss->priv;
-	struct _write_msg *msg;
-
-	d(printf("%p: gui sync op job waiting\n", emss));
-
-	msg = (struct _write_msg *)e_msgport_get(p->data_port);
-	/* Should never happen ... */
-	if (msg == NULL)
-		return TRUE;
-
-	d(printf("%p: running sync op %d\n", emss, msg->op));
-
-	/* force out any pending data before doing anything else */
-	if (p->buf_used > 0) {
-		EMSS_CLASS(emss)->sync_write((CamelStream *)emss, p->buf_data, p->buf_used);
-#ifdef LOG_STREAM
-		if (p->logfd)
-			fwrite(p->buf_data, 1, p->buf_used, p->logfd);
-#endif
-		p->buf_used = 0;
-	}
+	struct _EMSyncStream *emss = msg->emss;
 
-	/* FIXME: need to handle return values */
+	/* Force out any pending data before doing anything else. */
+	if (emss->buffer != NULL && emss->buffer->len > 0) {
+		EMSS_CLASS (emss)->sync_write (
+			CAMEL_STREAM (emss), emss->buffer->str,
+			emss->buffer->len);
+		g_string_set_size (emss->buffer, 0);
+	}
 
 	switch (msg->op) {
-	case EMSS_WRITE:
-		EMSS_CLASS(emss)->sync_write((CamelStream *)emss, msg->data, msg->n);
-#ifdef LOG_STREAM
-		if (p->logfd)
-			fwrite(msg->data, 1, msg->n, p->logfd);
-#endif
-		break;
-	case EMSS_FLUSH:
-		EMSS_CLASS(emss)->sync_flush((CamelStream *)emss);
-		break;
-	case EMSS_CLOSE:
-		EMSS_CLASS(emss)->sync_close((CamelStream *)emss);
-#ifdef LOG_STREAM
-		if (p->logfd) {
-			fclose(p->logfd);
-			p->logfd = NULL;
-		}
-#endif
-		break;
+		case EMSS_WRITE:
+			EMSS_CLASS (emss)->sync_write (
+				CAMEL_STREAM (emss), msg->string, msg->len);
+			break;
+		case EMSS_FLUSH:
+			EMSS_CLASS (emss)->sync_flush (
+				CAMEL_STREAM (emss));
+			break;
+		case EMSS_CLOSE:
+			EMSS_CLASS (emss)->sync_close (
+				CAMEL_STREAM (emss));
+			break;
 	}
-	
-	e_msgport_reply((EMsg *)msg);
-	d(printf("%p: gui sync op jobs done\n", emss));
-
-	return TRUE;
-}
-
-static void
-em_sync_stream_init (CamelObject *object)
-{
-	EMSyncStream *emss = (EMSyncStream *)object;
-	struct _EMSyncStreamPrivate *p;
-
-	p = emss->priv = g_malloc0(sizeof(*p));
 
-	p->data_port = e_msgport_new();
-	p->reply_port = e_msgport_new();
+	e_flag_set (msg->processed);
 
-#ifndef G_OS_WIN32
-	p->gui_channel = g_io_channel_unix_new(e_msgport_fd(p->data_port));
-#else
-	p->gui_channel = g_io_channel_win32_new_socket(e_msgport_fd(p->data_port));
-#endif
-	p->gui_watch = g_io_add_watch(p->gui_channel, G_IO_IN, emcs_gui_received, emss);
-
-#ifdef LOG_STREAM
-	if (dolog) {
-		char name[32];
-		static int count;
-
-		sprintf(name, "sync-stream.%d.html", count++);
-		printf("Saving raw data stream to '%s'\n", name);
-		p->logfd = fopen(name, "w");
-	}
-#endif
-
-	d(printf("%p: new emss\n", emss));
+	return FALSE;
 }
 
 static void
-sync_op(EMSyncStream *emss, enum _write_msg_t op, const char *data, size_t n)
+emss_sync_op (EMSyncStream *emss, enum _write_msg_t op,
+              const gchar *string, gsize len)
 {
-	struct _EMSyncStreamPrivate *p = emss->priv;
 	struct _write_msg msg;
-	EMsg *reply_msg;
-
-	d(printf("%p: launching sync op %d\n", emss, op));
 
-	/* we do everything synchronous, we should never have any locks, and
-	   this prevents overflow from banked up data */
-
-	msg.msg.reply_port = p->reply_port;
+	msg.processed = e_flag_new ();
+	msg.emss = emss;
 	msg.op = op;
-	msg.data = data;
-	msg.n = n;
-
-	e_msgport_put(p->data_port, &msg.msg);
-	reply_msg = e_msgport_wait(p->reply_port);
-	g_assert(reply_msg == &msg.msg);
-
-	d(printf("%p: returned sync op %d\n", emss, op));
-}
-
-static void
-em_sync_stream_finalize (CamelObject *object)
-{
-	EMSyncStream *emss = (EMSyncStream *)object;
-	struct _EMSyncStreamPrivate *p = emss->priv;
-
-	/* TODO: is this stuff safe to do in another thread? */
-	g_source_remove(p->gui_watch);
-	g_io_channel_unref(p->gui_channel);
+	msg.string = string;
+	msg.len = len;
 
-	e_msgport_destroy(p->data_port);
-	e_msgport_destroy(p->reply_port);
+	camel_object_ref (emss);
 
-	p->data_port = NULL;
-	p->reply_port = NULL;
+	g_idle_add ((GSourceFunc) emss_process_message, &msg);
 
-	g_free(p->buf_data);
+	e_flag_wait (msg.processed);
+	e_flag_free (msg.processed);
 
-#ifdef LOG_STREAM
-	if (p->logfd)
-		fclose(p->logfd);
-#endif
-
-	g_free(p);
+	camel_object_unref (emss);
 }
 
-static ssize_t
-stream_write (CamelStream *stream, const char *buffer, size_t n)
+static gssize
+emss_stream_write (CamelStream *stream, const gchar *string, gsize len)
 {
 	EMSyncStream *emss = EM_SYNC_STREAM (stream);
-	struct _EMSyncStreamPrivate *p = emss->priv;
 
 	if (emss->cancel)
 		return -1;
 
-	if (pthread_equal(pthread_self(), mail_gui_thread)) {
-		EMSS_CLASS(emss)->sync_write(stream, buffer, n);
-#ifdef LOG_STREAM
-		if (p->logfd)
-			fwrite(buffer, 1, n, p->logfd);
-#endif
-	} else if (p->buf_size > 0) {
-		size_t left = p->buf_size-p->buf_used;
-
-		if (n >= left) {
-			sync_op(emss, EMSS_WRITE, buffer, n);
-		} else {
-			memcpy(p->buf_data + p->buf_used, buffer, n);
-			p->buf_used += n;
-		}
+	if (mail_in_main_thread ()) {
+		EMSS_CLASS (emss)->sync_write (stream, string, len);
+	} else if (emss->buffer != NULL) {
+		if (len < (emss->buffer->allocated_len - emss->buffer->len))
+			g_string_append_len (emss->buffer, string, len);
+		else
+			emss_sync_op (emss, EMSS_WRITE, string, len);
 	} else {
-		sync_op(emss, EMSS_WRITE, buffer, n);
+		emss_sync_op(emss, EMSS_WRITE, string, len);
 	}
 
-	return (ssize_t) n;
+	return (gssize) len;
 }
 
 static int
-stream_flush(CamelStream *stream)
+emss_stream_flush (CamelStream *stream)
 {
-	EMSyncStream *emss = (EMSyncStream *)stream;
+	EMSyncStream *emss = EM_SYNC_STREAM (stream);
 
 	if (emss->cancel)
 		return -1;
 
-	if (pthread_equal(pthread_self(), mail_gui_thread))
-		return ((EMSyncStreamClass *)(((CamelObject *)emss)->klass))->sync_flush(stream);
+	if (mail_in_main_thread ())
+		return EMSS_CLASS (emss)->sync_flush (stream);
 	else
-		sync_op(emss, EMSS_FLUSH, NULL, 0);
+		emss_sync_op (emss, EMSS_FLUSH, NULL, 0);
 
 	return 0;
 }
 
 static int
-stream_close(CamelStream *stream)
+emss_stream_close (CamelStream *stream)
 {
-	EMSyncStream *emss = (EMSyncStream *)stream;
+	EMSyncStream *emss = EM_SYNC_STREAM (stream);
 
 	if (emss->cancel)
 		return -1;
 
-	d(printf("%p: closing stream\n", stream));
-
-	if (pthread_equal(pthread_self(), mail_gui_thread)) {
-#ifdef LOG_STREAM
-		if (emss->priv->logfd) {
-			fclose(emss->priv->logfd);
-			emss->priv->logfd = NULL;
-		}
-#endif
-		return ((EMSyncStreamClass *)(((CamelObject *)emss)->klass))->sync_close(stream);
-	} else
-		sync_op(emss, EMSS_CLOSE, NULL, 0);
+	if (mail_in_main_thread ())
+		return EMSS_CLASS (emss)->sync_close (stream);
+	else
+		emss_sync_op (emss, EMSS_CLOSE, NULL, 0);
 
 	return 0;
 }
 
-void
-em_sync_stream_set_buffer_size(EMSyncStream *emss, size_t size)
+static void
+em_sync_stream_class_init (EMSyncStreamClass *class)
+{
+	CamelStreamClass *stream_class = CAMEL_STREAM_CLASS (class);
+
+	parent_class = (CamelStreamClass *) CAMEL_STREAM_TYPE;
+
+	stream_class->write = emss_stream_write;
+	stream_class->flush = emss_stream_flush;
+	stream_class->close = emss_stream_close;
+}
+
+static void
+em_sync_stream_finalize (EMSyncStream *emss)
+{
+	if (emss->buffer != NULL)
+		g_string_free (emss->buffer, TRUE);
+}
+
+CamelType
+em_sync_stream_get_type (void)
 {
-	struct _EMSyncStreamPrivate *p = emss->priv;
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (G_UNLIKELY (type == CAMEL_INVALID_TYPE))
+		type = camel_type_register (
+			CAMEL_STREAM_TYPE,
+			"EMSyncStream",
+			sizeof (EMSyncStream),
+			sizeof (EMSyncStreamClass),
+			(CamelObjectClassInitFunc) em_sync_stream_class_init,
+			NULL,
+			(CamelObjectInitFunc) NULL,
+			(CamelObjectFinalizeFunc) em_sync_stream_finalize);
 
-	g_free(p->buf_data);
-	p->buf_data = g_malloc(size);
-	p->buf_size = size;
-	p->buf_used = 0;
+	return type;
+}
+
+void
+em_sync_stream_set_buffer_size (EMSyncStream *emss, gsize size)
+{
+	if (emss->buffer != NULL)
+		g_string_free (emss->buffer, TRUE);
+	emss->buffer = g_string_sized_new (size);
 }
Index: mail/em-sync-stream.h
===================================================================
--- mail/em-sync-stream.h	(revision 33416)
+++ mail/em-sync-stream.h	(working copy)
@@ -29,41 +29,45 @@ requests are always handled in the main 
 #ifndef EM_SYNC_STREAM_H
 #define EM_SYNC_STREAM_H
 
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus */
-
-#define EM_SYNC_STREAM_TYPE     (em_sync_stream_get_type ())
-#define EM_SYNC_STREAM(obj)     (CAMEL_CHECK_CAST((obj), EM_SYNC_STREAM_TYPE, EMSyncStream))
-#define EM_SYNC_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), EM_SYNC_STREAM_TYPE, EMSyncStreamClass))
-#define EM_IS_SYNC_STREAM(o)    (CAMEL_CHECK_TYPE((o), EM_SYNC_STREAM_TYPE))
-
 #include <glib.h>
 #include <camel/camel-stream.h>
 
-typedef struct _EMSyncStream {
-	CamelStream parent_stream;
-
-	struct _EMSyncStreamPrivate *priv;
+#define EM_SYNC_STREAM_TYPE \
+	(em_sync_stream_get_type ())
+#define EM_SYNC_STREAM(obj) \
+	(CAMEL_CHECK_CAST \
+	((obj), EM_SYNC_STREAM_TYPE, EMSyncStream))
+#define EM_SYNC_STREAM_CLASS(cls) \
+	(CAMEL_CHECK_CLASS_CAST \
+	((cls), EM_SYNC_STREAM_TYPE, EMSyncStreamClass))
+#define EM_IS_SYNC_STREAM(obj) \
+	(CAMEL_CHECK_TYPE ((obj), EM_SYNC_STREAM_TYPE))
+
+G_BEGIN_DECLS
+
+typedef struct _EMSyncStream EMSyncStream;
+typedef struct _EMSyncStreamClass EMSyncStreamClass;
+
+struct _EMSyncStream {
+	CamelStream parent;
+	GString *buffer;
+	gboolean cancel;
+};
 
-	int cancel;
-} EMSyncStream;
-
-typedef struct {
+struct _EMSyncStreamClass {
 	CamelStreamClass parent_class;
 
-	ssize_t   (*sync_write)      (CamelStream *stream, const char *buffer, size_t n);
-	int       (*sync_close)      (CamelStream *stream);
-	int       (*sync_flush)      (CamelStream *stream);
-	
-} EMSyncStreamClass;
-
-CamelType    em_sync_stream_get_type (void);
-void em_sync_stream_set_buffer_size(EMSyncStream *, size_t size);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+	gssize		(*sync_write)		(CamelStream *stream,
+						 const gchar *string,
+						 gsize len);
+	int		(*sync_close)		(CamelStream *stream);
+	int		(*sync_flush)		(CamelStream *stream);
+};
+
+CamelType	em_sync_stream_get_type		(void);
+void		em_sync_stream_set_buffer_size	(EMSyncStream *stream,
+						 gsize size);
+
+G_END_DECLS
 
 #endif /* EM_SYNC_STREAM_H */
Index: mail/em-format-html.c
===================================================================
--- mail/em-format-html.c	(revision 33416)
+++ mail/em-format-html.c	(working copy)
@@ -1375,7 +1375,7 @@ efh_format_timeout(struct _format_msg *m
 		}
 		
 		efh->priv->format_id = m->msg.seq;
-		e_thread_put(mail_thread_new, (EMsg *)m);
+		mail_msg_unordered_push ((mail_msg_t *) m);
 	}
 
 	efh->priv->format_timeout_id = 0;
Index: mail/mail-session.c
===================================================================
--- mail/mail-session.c	(revision 33416)
+++ mail/mail-session.c	(working copy)
@@ -35,7 +35,7 @@
 #include <libgnome/gnome-sound.h>
 
 #include <libedataserverui/e-passwords.h>
-#include <libedataserver/e-msgport.h>
+#include <libedataserver/e-flag.h>
 
 #include <camel/camel.h>	/* FIXME: this is where camel_init is defined, it shouldn't include everything else */
 #include <camel/camel-filter-driver.h>
@@ -258,7 +258,7 @@ forget_password (CamelSession *session, 
 
 /* ********************************************************************** */
 
-static GtkDialog *message_dialog;
+static gpointer message_dialog;
 static EDList message_list = E_DLIST_INITIALISER(message_list);
 
 struct _user_message_msg {
@@ -285,7 +285,7 @@ user_message_response (GtkDialog *dialog
 	/* if !allow_cancel, then we've already replied */
 	if (m->allow_cancel) {
 		m->result = button == GTK_RESPONSE_OK;
-		e_msgport_reply((EMsg *)m);
+		e_flag_set (m->msg.processed);
 	}
 	
 	/* check for pendings */
@@ -294,22 +294,10 @@ user_message_response (GtkDialog *dialog
 }
 
 static void
-user_message_destroy_notify (struct _user_message_msg *m, GObject *deadbeef)
-{
-	message_dialog = NULL;
-}
-
-/* This is kinda ugly/inefficient, but oh well, it works */
-static const char *error_type[] = {
-	"mail:session-message-info", "mail:session-message-warning", "mail:session-message-error",
-	"mail:session-message-info-cancel", "mail:session-message-warning-cancel", "mail:session-message-error-cancel"
-};
-
-static void
 do_user_message (struct _mail_msg *mm)
 {
 	struct _user_message_msg *m = (struct _user_message_msg *)mm;
-	int type;
+	const gchar *error_type;
 	
 	if (!m->ismain && message_dialog != NULL) {
 		e_dlist_addtail (&message_list, (EDListNode *)m);
@@ -317,24 +305,27 @@ do_user_message (struct _mail_msg *mm)
 	}
 	
 	switch (m->type) {
-	case CAMEL_SESSION_ALERT_INFO:
-		type = 0;
-		break;
-	case CAMEL_SESSION_ALERT_WARNING:
-		type = 1;
-		break;
-	case CAMEL_SESSION_ALERT_ERROR:
-		type = 2;
-		break;
-	default:
-		type = 0;
+		case CAMEL_SESSION_ALERT_INFO:
+			error_type = m->allow_cancel ?
+				"mail:session-message-info-cancel" :
+				"mail:session-message-info";
+			break;
+		case CAMEL_SESSION_ALERT_WARNING:
+			error_type = m->allow_cancel ?
+				"mail:session-message-warning-cancel" :
+				"mail:session-message-warning";
+			break;
+		case CAMEL_SESSION_ALERT_ERROR:
+			error_type = m->allow_cancel ?
+				"mail:session-message-error-cancel" :
+				"mail:session-message-error";
+			break;
+		default:
+			g_assert_not_reached ();
 	}
 
-	if (m->allow_cancel)
-		type += 3;
-	
-	message_dialog = (GtkDialog *)e_error_new(NULL, error_type[type], m->prompt, NULL);
-	g_object_set ((GObject *) message_dialog, "allow_shrink", TRUE, "allow_grow", TRUE, NULL);
+	message_dialog = e_error_new(NULL, error_type, m->prompt, NULL);
+	g_object_set (message_dialog, "allow_shrink", TRUE, "allow_grow", TRUE, NULL);
 	
 	/* We only need to wait for the result if we allow cancel otherwise show but send result back instantly */
 	if (m->allow_cancel) {
@@ -342,12 +333,13 @@ do_user_message (struct _mail_msg *mm)
 			user_message_response(message_dialog, gtk_dialog_run (message_dialog), m);
 		} else {
 			g_signal_connect (message_dialog, "response", G_CALLBACK (user_message_response), m);
-			gtk_widget_show ((GtkWidget *) message_dialog);
+			gtk_widget_show (message_dialog);
 		}
 	} else {
 		g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_widget_destroy), message_dialog);
-		g_object_weak_ref ((GObject *) message_dialog, (GWeakNotify) user_message_destroy_notify, m);
-		gtk_widget_show ((GtkWidget *) message_dialog);
+		g_object_add_weak_pointer (message_dialog, &message_dialog);
+		gtk_widget_show (message_dialog);
+		e_flag_free (mm->processed);
 		mail_msg_free(m);
 	}
 }
@@ -366,17 +358,17 @@ static gboolean
 alert_user(CamelSession *session, CamelSessionAlertType type, const char *prompt, gboolean cancel)
 {
 	MailSession *mail_session = MAIL_SESSION (session);
-	struct _user_message_msg *m, *r;
-	EMsgPort *user_message_reply = NULL;
+	struct _user_message_msg *m;
+	EFlag *processed = NULL;
 	gboolean ret;
 
 	if (!mail_session->interactive)
 		return FALSE;
 
-	if (cancel)
-		user_message_reply = e_msgport_new ();	
-	m = mail_msg_new (&user_message_op, user_message_reply, sizeof (*m));
-	m->ismain = pthread_equal(pthread_self(), mail_gui_thread);
+	processed = e_flag_new ();
+
+	m = mail_msg_new (&user_message_op, processed, sizeof (*m));
+	m->ismain = mail_in_main_thread();
 	m->type = type;
 	m->prompt = g_strdup(prompt);
 	m->allow_cancel = cancel;
@@ -384,18 +376,14 @@ alert_user(CamelSession *session, CamelS
 	if (m->ismain)
 		do_user_message((struct _mail_msg *)m);
 	else {
-		extern EMsgPort *mail_gui_port2;
-
-		e_msgport_put(mail_gui_port2, (EMsg *)m);
+		mail_msg_main_loop_push((mail_msg_t *) m);
 	}
 
 	if (cancel) {
-		r = (struct _user_message_msg *)e_msgport_wait(user_message_reply);
-		g_assert(m == r);
-
+		e_flag_wait (processed);
+		e_flag_free (processed);
 		ret = m->result;
 		mail_msg_free(m);
-		e_msgport_destroy(user_message_reply);
 	} else
 		ret = TRUE;
 
@@ -689,7 +677,7 @@ mail_session_set_interactive (gboolean i
 		/* flush/cancel pending user messages */
 		while ((um = (struct _user_message_msg *) e_dlist_remhead (&message_list))) {
 			d(printf ("Flusing message request: %s\n", um->prompt));
-			e_msgport_reply((EMsg *) um);
+			e_flag_set (um->msg.processed);
 		}
 		
 		/* and the current */
Index: mail/mail-component.c
===================================================================
--- mail/mail-component.c	(revision 33416)
+++ mail/mail-component.c	(working copy)
@@ -996,7 +996,7 @@ impl_handleURI (PortableServer_Servant s
 		if (camel_url_get_param(url, "uid") != NULL) {
 			char *curi = em_uri_to_camel(uri);
 
-			mail_get_folder(curi, 0, handleuri_got_folder, url, mail_thread_new);
+			mail_get_folder(curi, 0, handleuri_got_folder, url, mail_msg_unordered_push);
 			g_free(curi);
 		} else {
 			g_warning("email uri's must include a uid parameter");
Index: mail/message-list.c
===================================================================
--- mail/message-list.c	(revision 33416)
+++ mail/message-list.c	(working copy)
@@ -1888,7 +1888,7 @@ static void
 ml_drop_action(struct _drop_msg *m)
 {
 	m->move = m->action == GDK_ACTION_MOVE;
-	e_thread_put (mail_thread_new, (EMsg *) m);
+	mail_msg_unordered_push ((mail_msg_t *) m);
 }
 
 static void
@@ -3977,7 +3977,7 @@ ml_regen_timeout(struct _regen_list_msg 
 
 	m->ml->regen = g_list_prepend(m->ml->regen, m);
 	/* TODO: we should manage our own thread stuff, would make cancelling outstanding stuff easier */
-	e_thread_put (mail_thread_queued, (EMsg *)m);
+	mail_msg_fast_ordered_push ((mail_msg_t *) m);
 
 	m->ml->regen_timeout_msg = NULL;
 	m->ml->regen_timeout_id = 0;
Index: calendar/gui/alarm-notify/alarm-notify.c
===================================================================
--- calendar/gui/alarm-notify/alarm-notify.c	(revision 33416)
+++ calendar/gui/alarm-notify/alarm-notify.c	(working copy)
@@ -45,10 +45,6 @@ struct _AlarmNotifyPrivate {
         GMutex *mutex;
 };
 
-EThread *alarm_operation_thread;	/* for operations that can (or should) be queued */
-EMsgPort *alarm_reply_port;
-static GIOChannel *alarm_reply_channel;
-
 #define d(x) x
 
 
@@ -286,72 +282,12 @@ alarm_notify_finalize (GObject *object)
 	g_mutex_free (priv->mutex);
 	g_free (priv);
 
-	e_thread_destroy(alarm_operation_thread);
-	g_io_channel_unref(alarm_reply_channel);
-	e_msgport_destroy(alarm_reply_port);
 	if (G_OBJECT_CLASS (parent_class)->finalize)
 		(* G_OBJECT_CLASS (parent_class)->finalize) (object);
 }
 
 
 
-static guint
-alarm_channel_setup(EMsgPort **port, GIOChannel **channel, GIOFunc func)
-{
-	GSource *source;
-	guint id;
-
-	d (printf("%s:%d (alarm_channel_setup) - Channel Setup\n ", __FILE__, __LINE__));
-	*port = e_msgport_new();
-#ifndef G_OS_WIN32
-	*channel = g_io_channel_unix_new(e_msgport_fd(*port));
-#else
-	*channel = g_io_channel_win32_new_socket(e_msgport_fd(*port));
-#endif
-	source = g_io_create_watch(*channel, G_IO_IN);
-	g_source_set_callback(source, (GSourceFunc)func, *port, NULL);
-	g_source_set_can_recurse(source, FALSE);
-	id = g_source_attach(source, NULL);
-	g_source_unref(source);
-
-	return id;
-}
-
-static void
-alarm_msg_destroy(EThread *e, EMsg *msg, void *data)
-{
-	AlarmMsg *m = (AlarmMsg *)msg;
-
-	/* Free the private */
-	g_free (m->data); /* Mostly it is a structure allocated as a carrier*/
-	g_free (m);
-}
-
-static gboolean
-alarm_msgport_replied(GIOChannel *source, GIOCondition cond, void *d)
-{
-	EMsgPort *port = (EMsgPort *)d;
-	EMsg *m;
-
-	while (( m = e_msgport_get(port))) {
-		d (printf("%s:%d (alarm_msgport_replied) - %p: Replied to GUI thread\n", __FILE__, __LINE__, m));
-		alarm_msg_destroy(NULL, m, NULL);
-	}
-
-	return TRUE;
-}
-
-static void
-alarm_msg_received(EThread *e, EMsg *msg, void *data)
-{
-	AlarmMsg *m = (AlarmMsg *)msg;
-	
-	d(printf("%s:%d (alarm_msg_received) - %p: Received at thread %" G_GINT64_MODIFIER "x\n", __FILE__, __LINE__, m, e_util_pthread_id(pthread_self())));	
-	if (m->receive_msg) {
-		m->receive_msg (e, m, data);
-	}
-}
-
 /**
  * alarm_notify_new:
  * 
@@ -363,23 +299,10 @@ alarm_msg_received(EThread *e, EMsg *msg
 AlarmNotify *
 alarm_notify_new (void)
 {
-	AlarmNotify *an;
-	
-	d (printf("%s:%d (alarm_notify_new) - Alarm Notify New \n ", __FILE__, __LINE__));
-
-	/* Create a thread for alarm queue operation*/	
-	alarm_channel_setup(&alarm_reply_port, &alarm_reply_channel, alarm_msgport_replied);
-
-	alarm_operation_thread = e_thread_new(E_THREAD_QUEUE);
-	e_thread_set_msg_destroy(alarm_operation_thread, alarm_msg_destroy, 0);
-	e_thread_set_msg_received(alarm_operation_thread, alarm_msg_received, 0);
-	e_thread_set_reply_port(alarm_operation_thread, alarm_reply_port);
-
-	an = g_object_new (TYPE_ALARM_NOTIFY,
-			   "poa", bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL),
-			   NULL);
-	
-	return an;
+	return g_object_new (TYPE_ALARM_NOTIFY,
+		"poa", bonobo_poa_get_threaded (
+			ORBIT_THREAD_HINT_PER_REQUEST, NULL),
+		NULL);
 }
 
 static void
Index: calendar/gui/alarm-notify/alarm-notify.h
===================================================================
--- calendar/gui/alarm-notify/alarm-notify.h	(revision 33416)
+++ calendar/gui/alarm-notify/alarm-notify.h	(working copy)
@@ -39,19 +39,6 @@ typedef struct _AlarmNotifyClass AlarmNo
 
 typedef struct _AlarmNotifyPrivate AlarmNotifyPrivate;
 
-typedef struct _AlarmMsg AlarmMsg;
-typedef struct _AlarmMsgPrivate AlarmMsgPrivate;
-
-struct _AlarmMsg {
-	 EMsg msg;
-
- 	 void (*receive_msg)(EThread *e, struct _AlarmMsg *msg, void *data);	/* message received */
-	 void *data;
-	 
-	 /* Private Usage */
-	 struct _AlarmMsgPrivate *priv;
-};
-
 struct _AlarmNotify {
 	BonoboObject object;
 
Index: calendar/gui/alarm-notify/alarm-queue.c
===================================================================
--- calendar/gui/alarm-notify/alarm-queue.c	(revision 33416)
+++ calendar/gui/alarm-notify/alarm-queue.c	(working copy)
@@ -115,9 +115,6 @@ static int tray_blink_id = -1;
 static int tray_blink_state = FALSE;
 static AlarmNotify *an;
 
-/* Main Tasks thread for dealing with the global structures */
-extern EThread *alarm_operation_thread;
-
 /* Structure that stores a client we are monitoring */
 typedef struct {
 	/* Monitored client */
@@ -199,6 +196,40 @@ static void on_dialog_objs_removed_cb (E
 static void load_alarms_for_today (ClientAlarms *ca);
 static void midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data);
 
+/* Simple asynchronous message dispatcher */
+
+typedef struct _Message Message;
+typedef void (*MessageFunc) (Message *msg);
+
+struct _Message {
+	MessageFunc func;
+};
+
+static void
+message_proxy (Message *msg)
+{
+	g_return_if_fail (msg->func != NULL);
+
+	msg->func (msg);
+}
+
+static gpointer
+create_thread_pool (void)
+{
+	/* once created, run forever */
+	return g_thread_pool_new ((GFunc) message_proxy, NULL, 1, FALSE, NULL);
+}
+
+static void
+message_push (Message *msg)
+{
+	static GOnce once = G_ONCE_INIT;
+
+	g_once (&once, (GThreadFunc) create_thread_pool, NULL);
+
+	g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
+}
+
 /* Queues an alarm trigger for midnight so that we can load the next day's worth
  * of alarms.
  */
@@ -237,47 +268,41 @@ add_client_alarms_cb (gpointer key, gpoi
 }
 
 struct _midnight_refresh_msg {
+	Message header;
 	gboolean remove;
 };
 
 /* Loads the alarms for the new day every midnight */
 static void
-midnight_refresh_async (EThread *e, AlarmMsg *msg, void *data)
+midnight_refresh_async (struct _midnight_refresh_msg *msg)
 {
-	struct _midnight_refresh_msg *list = msg->data;
-
 	d(printf("%s:%d (midnight_refresh_async) \n",__FILE__, __LINE__));
 	
 	/* Re-load the alarms for all clients */
 	g_hash_table_foreach (client_alarms_hash, add_client_alarms_cb, NULL);
 
 	/* Re-schedule the midnight update */
-	if (list->remove && midnight_refresh_id != NULL) {
+	if (msg->remove && midnight_refresh_id != NULL) {
 		d(printf("%s:%d (midnight_refresh_async) - Reschedule the midnight update \n",__FILE__, __LINE__)); 
 		alarm_remove (midnight_refresh_id);
 		midnight_refresh_id = NULL;
 	}
 
 	queue_midnight_refresh ();
+
+	g_slice_free (struct _midnight_refresh_msg, msg);
 }
 
 static void
 midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data)
 {
-	AlarmMsg *msg;
-	struct _midnight_refresh_msg *list;
-	
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = midnight_refresh_async;
-
-	list = malloc (sizeof (struct _midnight_refresh_msg));
+	struct _midnight_refresh_msg *msg;
 
-	list->remove = TRUE;
-	msg->data = list;
+	msg = g_slice_new (struct _midnight_refresh_msg);
+	msg->header.func = (MessageFunc) midnight_refresh_async;
+	msg->remove = TRUE;
 
-	d(printf("%s:%d (midnight_refresh_cb) - Invoking task for midnight refresh\n",__FILE__, __LINE__));
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	message_push ((Message *) msg);
 }
 
 /* Looks up a client in the client alarms hash table */
@@ -636,6 +661,7 @@ remove_comp (ClientAlarms *ca, ECalCompo
  * alarms.
  */
 struct _query_msg {
+	Message header;
 	ECal *client;
 	GList *objects;
 	gpointer data;
@@ -669,7 +695,7 @@ duplicate_ecal (GList *in_list)
 }
 
 static void
-query_objects_changed_async (EThread *e, AlarmMsg *msg, void *data)
+query_objects_changed_async (struct _query_msg *msg)
 {
 	ClientAlarms *ca;
 	time_t from, day_end;
@@ -678,13 +704,12 @@ query_objects_changed_async (EThread *e,
 	icaltimezone *zone;
 	CompQueuedAlarms *cqa;
 	GList *l;
-	struct _query_msg *list = msg->data;
 	ECal *client;
 	GList *objects;
 		
-	client = list->client;
-	ca = list->data;
-	objects = list->objects;
+	client = msg->client;
+	ca = msg->data;
+	objects = msg->objects;
 	
 	from = config_data_get_last_notification_time ();
 	if (from == -1)
@@ -773,43 +798,38 @@ query_objects_changed_async (EThread *e,
 		comp = NULL;
 	}
 	g_list_free (objects);
+
+	g_slice_free (struct _query_msg, msg);
 }
 
 static void
 query_objects_changed_cb (ECal *client, GList *objects, gpointer data)
 {
-	AlarmMsg *msg;
-	struct _query_msg *list;
+	struct _query_msg *msg;
 
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = query_objects_changed_async;
-	list = malloc (sizeof (struct _query_msg));
-	list->client = client;
-	list->objects = duplicate_ical (objects);
-	list->data = data;
-	msg->data = list;
-
-	d(printf("%s:%d (query_objects_changed_cb) - Posting a task\n",__FILE__, __LINE__));	
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	msg = g_slice_new (struct _query_msg);
+	msg->header.func = (MessageFunc) query_objects_changed_async;
+	msg->client = client;
+	msg->objects = duplicate_ical (objects);
+	msg->data = data;
 
+	message_push ((Message *) msg);
 }
 
 /* Called when a calendar component is removed; we must delete its corresponding
  * alarms.
  */
 static void
-query_objects_removed_async (EThread *e, AlarmMsg *msg, void *data)
+query_objects_removed_async (struct _query_msg *msg)
 {
 	ClientAlarms *ca;
 	GList *l;
-	struct _query_msg *list = msg->data;
 	ECal *client;
 	GList *objects;
 		
-	client = list->client;
-	ca = list->data;
-	objects = list->objects;
+	client = msg->client;
+	ca = msg->data;
+	objects = msg->objects;
 	
 	d(printf("%s:%d (query_objects_removed_async) - Removing %d objects\n",__FILE__, __LINE__, g_list_length(objects)));
 	
@@ -822,27 +842,22 @@ query_objects_removed_async (EThread *e,
 	}
 
 	g_list_free (objects);
+
+	g_slice_free (struct _query_msg, msg);
 }
 
 static void
 query_objects_removed_cb (ECal *client, GList *objects, gpointer data)
 {
-	AlarmMsg *msg;
-	struct _query_msg *list;
-
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = query_objects_removed_async;
-
-	list = malloc (sizeof (struct _query_msg));
-	list->client = client;
-	list->objects = duplicate_ecal (objects);
-	list->data = data;	
-	msg->data = list;
+	struct _query_msg *msg;
 
-	d(printf("%s:%d (query_objects_removed_cb) - Posting a task\n",__FILE__, __LINE__));	
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	msg = g_slice_new (struct _query_msg);
+	msg->header.func = (MessageFunc) query_objects_removed_async;
+	msg->client = client;
+	msg->objects = duplicate_ecal (objects);
+	msg->data = data;
 
+	message_push ((Message *) msg);
 }
 
 
@@ -989,20 +1004,19 @@ free_tray_icon_data (TrayIconData *tray_
 }
 
 static void
-on_dialog_objs_removed_async (EThread *e, AlarmMsg *msg, void *data)
+on_dialog_objs_removed_async (struct _query_msg *msg)
 {
 	const char *our_uid;
 	GList *l;
 	TrayIconData *tray_data;
-	struct _query_msg *list = msg->data;
 	ECal *client;
 	GList *objects;
 
 	d(printf("%s:%d (on_dialog_objs_removed_async)\n",__FILE__, __LINE__));
 	
-	client = list->client;
-	tray_data = list->data;
-	objects = list->objects;
+	client = msg->client;
+	tray_data = msg->data;
+	objects = msg->objects;
 	
 	e_cal_component_get_uid (tray_data->comp, &our_uid);
 	g_return_if_fail (our_uid && *our_uid);
@@ -1020,37 +1034,33 @@ on_dialog_objs_removed_async (EThread *e
 			tray_data = NULL;
 		}
 	}
+
+	g_slice_free (struct _query_msg, msg);
 }
 
 static void
 on_dialog_objs_removed_cb (ECal *client, GList *objects, gpointer data)
 {
-	AlarmMsg *msg;
-	struct _query_msg *list;
+	struct _query_msg *msg;
 
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = on_dialog_objs_removed_async;
-
-	list = malloc (sizeof (struct _query_msg));
-	list->client = client;
-	list->objects = objects;
-	list->data = data;
-	msg->data = list;
+	msg = g_slice_new (struct _query_msg);
+	msg->header.func = (MessageFunc) on_dialog_objs_removed_async;
+	msg->client = client;
+	msg->objects = objects;
+	msg->data = data;
 
-	d(printf("%s:%d (on_dialog_objs_removed_cb) - Posting a task \n",__FILE__, __LINE__));
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);	
+	message_push ((Message *) msg);
 }
 
 struct _tray_cqa_msg {
+	Message header;
 	CompQueuedAlarms *cqa;
 };
 
 static void
-tray_list_remove_cqa_async(EThread *e, AlarmMsg *msg, void *data)
+tray_list_remove_cqa_async (struct _tray_cqa_msg *msg)
 {
-	struct _tray_cqa_msg *tmsg = msg->data;
-	CompQueuedAlarms *cqa = tmsg->cqa;
+	CompQueuedAlarms *cqa = msg->cqa;
 	GList *list = tray_icons_list;
 
 	d(printf("%s:%d (tray_list_remove_cqa_async) - Removing CQA %p from tray list\n",__FILE__, __LINE__, cqa));
@@ -1089,28 +1099,25 @@ tray_list_remove_cqa_async(EThread *e, A
 			gtk_tree_selection_select_iter (sel, &iter);
 		}
 	}
+
+	g_slice_free (struct _tray_cqa_msg, msg);
 }
 
 static void
 tray_list_remove_cqa (CompQueuedAlarms *cqa)
 {
-	AlarmMsg *msg;
-	struct _tray_cqa_msg *list;
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = tray_list_remove_cqa_async;
-
-	list = malloc (sizeof (struct _tray_cqa_msg));
-	list->cqa = cqa;
-	msg->data = list;
+	struct _tray_cqa_msg *msg;
+
+	msg = g_slice_new (struct _tray_cqa_msg);
+	msg->header.func = (MessageFunc) tray_list_remove_cqa_async;
+	msg->cqa = cqa;
 
-	d(printf("%s:%d (tray_list_remove_cqa) - Posting a task\n",__FILE__, __LINE__));
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	message_push ((Message *) msg);
 }
 
 /* Callback used from the alarm notify dialog */
 static void
-tray_list_remove_async(EThread *e, AlarmMsg *msg, void *data)
+tray_list_remove_async (Message *msg)
 {
 	GList *list = tray_icons_list;
 
@@ -1140,55 +1147,50 @@ tray_list_remove_async(EThread *e, Alarm
 		} else
 			list = list->next;
 	}	
+
+	g_slice_free (Message, msg);
 }
 
 static void
-tray_list_remove_icons ()
+tray_list_remove_icons (void)
 {
-	AlarmMsg *msg;
-
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = tray_list_remove_async;
+	Message *msg;
 
-	msg->data = NULL;
+	msg = g_slice_new (Message);
+	msg->func = tray_list_remove_async;
 
-	d(printf("%s:%d (tray_list_remove_icons) - Posting a task\n",__FILE__, __LINE__));
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	message_push (msg);
 }
 
 struct _tray_msg {
+	Message header;
 	TrayIconData *data;
 };
 
 static void
-tray_list_remove_data_async(EThread *e, AlarmMsg *msg, void *data)
+tray_list_remove_data_async (struct _tray_msg *msg)
 {
-	struct _tray_msg *tmsg = msg->data;
-	TrayIconData *tray_data = tmsg->data;
+	TrayIconData *tray_data = msg->data;
 
 	d(printf("%s:%d (tray_list_remove_data_async) - Removing %p from tray list\n",__FILE__, __LINE__, tray_data));
 	
 	tray_icons_list = g_list_remove_all (tray_icons_list, tray_data);
 	free_tray_icon_data (tray_data);
 	tray_data = NULL;
+
+	g_slice_free (struct _tray_msg, msg);
 }
 
 static void
 tray_list_remove_data (TrayIconData *data)
 {
-	AlarmMsg *msg;
-	struct _tray_msg *list;
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = tray_list_remove_data_async;
-
-	list = malloc (sizeof (struct _tray_msg));
-	list->data = data;
-	msg->data = list;
+	struct _tray_msg *msg;
+
+	msg = g_slice_new (struct _tray_msg);
+	msg->header.func = (MessageFunc) tray_list_remove_data_async;
+	msg->data = data;
 
-	d(printf("%s:%d (tray_list_remove_data) - Posting a task\n",__FILE__, __LINE__));
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	message_push ((Message *) msg);
 }
 
 static void
@@ -1396,29 +1398,24 @@ tray_icon_blink_cb (gpointer data)
 /* Add a new data to tray list */
 
 static void
-tray_list_add_async (EThread *e, AlarmMsg *msg, void *data)
+tray_list_add_async (struct _tray_msg *msg)
 {
-	struct _tray_msg *list = msg->data;
-	d(printf("%s:%d (tray_list_add_async) - Add %p\n",__FILE__, __LINE__, list->data));	
-	tray_icons_list = g_list_prepend (tray_icons_list, list->data);
+	d(printf("%s:%d (tray_list_add_async) - Add %p\n",__FILE__, __LINE__, msg->data));	
+	tray_icons_list = g_list_prepend (tray_icons_list, msg->data);
+
+	g_slice_free (struct _tray_msg, msg);
 }
 
 static void
 tray_list_add_new (TrayIconData *data)
 {
-	AlarmMsg *msg;
-	struct _tray_msg *list;
+	struct _tray_msg *msg;
 
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = tray_list_add_async;
-
-	list = malloc (sizeof (struct _tray_msg));
-	list->data = data;
-	msg->data = list;
-	
-	d(printf("%s:%d (tray_list_add_new) - Posting a task\n",__FILE__, __LINE__));	
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	msg = g_slice_new (struct _tray_msg);
+	msg->header.func = (MessageFunc) tray_list_add_async;
+	msg->data = data;
+
+	message_push ((Message *) msg);
 }
 
 /* Performs notification of a display alarm */
@@ -1843,21 +1840,13 @@ check_midnight_refresh (gpointer user_da
 	new_midnight = time_day_end_with_zone (time (NULL), zone);
 
 	if (new_midnight > midnight) {
-		AlarmMsg *msg;
-		struct _midnight_refresh_msg *list;
-	
-		/* These two structures will be freed by the msg destroy function*/
-		msg = malloc (sizeof (AlarmMsg));
-		msg->receive_msg = midnight_refresh_async;
-
-		list = malloc (sizeof (struct _midnight_refresh_msg));
+		struct _midnight_refresh_msg *msg;
 
-		list->remove = FALSE;
-		/* We dont need it. So set it to NULL */
-		msg->data = list;
+		msg = g_slice_new (struct _midnight_refresh_msg);
+		msg->header.func = (MessageFunc) midnight_refresh_async;
+		msg->remove = FALSE;
 
-		d(printf("%s:%d (check_midnight_refresh) - Posting a task to refresh\n",__FILE__, __LINE__));
-		e_thread_put(alarm_operation_thread, (EMsg *)msg);		
+		message_push ((Message *) msg);
 	}
 
 	return TRUE;
@@ -1988,14 +1977,15 @@ hash_ids (gpointer a)
 }
 
 struct _alarm_client_msg {
+	Message header;
 	ECal *client;
 };
 
-static void alarm_queue_add_async (EThread *e, AlarmMsg *msg, void *data)
+static void
+alarm_queue_add_async (struct _alarm_client_msg *msg)
 {
 	ClientAlarms *ca;
-	struct _alarm_client_msg *list = msg->data;
-	ECal *client = list->client;
+	ECal *client = msg->client;
 
 	g_return_if_fail (alarm_queue_inited);
 	g_return_if_fail (client != NULL);
@@ -2026,6 +2016,8 @@ static void alarm_queue_add_async (EThre
 				  G_CALLBACK (cal_opened_cb),
 				  ca);
 	}	
+
+	g_slice_free (struct _alarm_client_msg, msg);
 }
 
 /**
@@ -2045,20 +2037,13 @@ static void alarm_queue_add_async (EThre
 void
 alarm_queue_add_client (ECal *client)
 {
-	AlarmMsg *msg;
-	struct _alarm_client_msg *list;
+	struct _alarm_client_msg *msg;
 
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = alarm_queue_add_async;
-
-	list = malloc (sizeof (struct _alarm_client_msg));
-	list->client = client;
-	g_object_ref (client);
-	msg->data = list;
+	msg = g_slice_new (struct _alarm_client_msg);
+	msg->header.func = (MessageFunc) alarm_queue_add_async;
+	msg->client = g_object_ref (client);
 
-	d(printf("%s:%d (alarm_queue_add_client) - Posting a task\n",__FILE__, __LINE__));
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	message_push ((Message *) msg);
 }
 
 /* Removes a component an its alarms */
@@ -2110,11 +2095,10 @@ remove_client_alarms (ClientAlarms *ca)
  * Removes a calendar client from the alarm queueing system.
  **/
 static void
-alarm_queue_remove_async (EThread *e, AlarmMsg *msg, void *data)
+alarm_queue_remove_async (struct _alarm_client_msg *msg)
 {
 	ClientAlarms *ca;
-	struct _alarm_client_msg *list = msg->data;
-	ECal *client = list->client;
+	ECal *client = msg->client;
 
 	g_return_if_fail (alarm_queue_inited);
 	g_return_if_fail (client != NULL);
@@ -2151,24 +2135,20 @@ alarm_queue_remove_async (EThread *e, Al
 	g_free (ca);
 
 	g_hash_table_remove (client_alarms_hash, client);
+
+	g_slice_free (struct _alarm_client_msg, msg);
 }
 
 void
 alarm_queue_remove_client (ECal *client)
 {
-	AlarmMsg *msg;
-	struct _alarm_client_msg *list;
+	struct _alarm_client_msg *msg;
 
-	/* These two structures will be freed by the msg destroy function*/
-	msg = malloc (sizeof (AlarmMsg));
-	msg->receive_msg = alarm_queue_remove_async;
-
-	list = malloc (sizeof (struct _alarm_client_msg));
-	list->client = client;
-	msg->data = list;
+	msg = g_slice_new (struct _alarm_client_msg);
+	msg->header.func = (MessageFunc) alarm_queue_remove_async;
+	msg->client = client;
 
-	d(printf("%s:%d (alarm_queue_remove_client) - Posting a task\n",__FILE__, __LINE__));
-	e_thread_put(alarm_operation_thread, (EMsg *)msg);
+	message_push ((Message *) msg);
 }
 
 /* Update non-time related variables for various structures on modification of an existing component 
