Index: calendar/gui/alarm-notify/alarm-notify.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-notify.c,v
retrieving revision 1.56
diff -u -p -r1.56 alarm-notify.c
--- calendar/gui/alarm-notify/alarm-notify.c	24 Aug 2006 13:53:20 -0000	1.56
+++ calendar/gui/alarm-notify/alarm-notify.c	16 Oct 2006 16:37:25 -0000
@@ -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
 
 
@@ -284,72 +280,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:
  * 
@@ -361,23 +297,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
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-notify.h,v
retrieving revision 1.14
diff -u -p -r1.14 alarm-notify.h
--- calendar/gui/alarm-notify/alarm-notify.h	21 Apr 2006 19:38:16 -0000	1.14
+++ calendar/gui/alarm-notify/alarm-notify.h	16 Oct 2006 16:37:25 -0000
@@ -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
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-queue.c,v
retrieving revision 1.105
diff -u -p -r1.105 alarm-queue.c
--- calendar/gui/alarm-notify/alarm-queue.c	30 Aug 2006 14:36:04 -0000	1.105
+++ calendar/gui/alarm-notify/alarm-queue.c	16 Oct 2006 16:37:27 -0000
@@ -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));
@@ -1087,28 +1097,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;
 
@@ -1138,55 +1145,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
@@ -1394,29 +1396,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 */
@@ -1836,21 +1833,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;
@@ -1981,14 +1970,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);
@@ -2019,6 +2009,8 @@ static void alarm_queue_add_async (EThre
 				  G_CALLBACK (cal_opened_cb),
 				  ca);
 	}	
+
+	g_slice_free (struct _alarm_client_msg, msg);
 }
 
 /**
@@ -2038,20 +2030,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 */
@@ -2103,11 +2088,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);
@@ -2144,24 +2128,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 
Index: mail/em-composer-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-composer-utils.c,v
retrieving revision 1.54
diff -u -p -r1.54 em-composer-utils.c
--- mail/em-composer-utils.c	18 Apr 2006 20:56:36 -0000	1.54
+++ mail/em-composer-utils.c	16 Oct 2006 16:37:29 -0000
@@ -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/em-folder-browser.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-folder-browser.c,v
retrieving revision 1.92
diff -u -p -r1.92 em-folder-browser.c
--- mail/em-folder-browser.c	29 Sep 2006 07:37:55 -0000	1.92
+++ mail/em-folder-browser.c	16 Oct 2006 16:37:30 -0000
@@ -950,7 +950,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-properties.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-folder-properties.c,v
retrieving revision 1.12
diff -u -p -r1.12 em-folder-properties.c
--- mail/em-folder-properties.c	23 Feb 2006 13:26:41 -0000	1.12
+++ mail/em-folder-properties.c	16 Oct 2006 16:37:30 -0000
@@ -379,7 +379,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-tree.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-folder-tree.c,v
retrieving revision 1.162
diff -u -p -r1.162 em-folder-tree.c
--- mail/em-folder-tree.c	7 Aug 2006 18:55:02 -0000	1.162
+++ mail/em-folder-tree.c	16 Oct 2006 16:37:32 -0000
@@ -966,7 +966,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
@@ -1891,7 +1891,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-folder-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-folder-utils.c,v
retrieving revision 1.7
diff -u -p -r1.7 em-folder-utils.c
--- mail/em-folder-utils.c	8 Feb 2006 11:51:32 -0000	1.7
+++ mail/em-folder-utils.c	16 Oct 2006 16:37:32 -0000
@@ -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/em-folder-view.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-folder-view.c,v
retrieving revision 1.162
diff -u -p -r1.162 em-folder-view.c
--- mail/em-folder-view.c	29 Sep 2006 18:04:39 -0000	1.162
+++ mail/em-folder-view.c	16 Oct 2006 16:37:34 -0000
@@ -694,7 +694,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
@@ -1589,7 +1589,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
@@ -1687,7 +1687,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
@@ -2336,7 +2336,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/em-format-html-print.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-format-html-print.c,v
retrieving revision 1.8
diff -u -p -r1.8 em-format-html-print.c
--- mail/em-format-html-print.c	19 May 2005 06:46:23 -0000	1.8
+++ mail/em-format-html-print.c	16 Oct 2006 16:37:34 -0000
@@ -228,7 +228,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-format-html.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-format-html.c,v
retrieving revision 1.93
diff -u -p -r1.93 em-format-html.c
--- mail/em-format-html.c	29 Sep 2006 17:54:48 -0000	1.93
+++ mail/em-format-html.c	16 Oct 2006 16:37:35 -0000
@@ -1374,7 +1374,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/em-subscribe-editor.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-subscribe-editor.c,v
retrieving revision 1.24
diff -u -p -r1.24 em-subscribe-editor.c
--- mail/em-subscribe-editor.c	24 Jul 2006 09:01:30 -0000	1.24
+++ mail/em-subscribe-editor.c	16 Oct 2006 16:37:36 -0000
@@ -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);
@@ -420,7 +420,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-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.138
diff -u -p -r1.138 mail-component.c
--- mail/mail-component.c	16 Oct 2006 14:41:49 -0000	1.138
+++ mail/mail-component.c	16 Oct 2006 16:37:36 -0000
@@ -966,7 +966,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/mail-folder-cache.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-folder-cache.c,v
retrieving revision 1.107
diff -u -p -r1.107 mail-folder-cache.c
--- mail/mail-folder-cache.c	26 Jul 2006 13:19:18 -0000	1.107
+++ mail/mail-folder-cache.c	16 Oct 2006 16:37:37 -0000
@@ -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
Index: mail/mail-mt.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-mt.c,v
retrieving revision 1.97
diff -u -p -r1.97 mail-mt.c
--- mail/mail-mt.c	16 Oct 2006 14:50:33 -0000	1.97
+++ mail/mail-mt.c	16 Oct 2006 16:37:38 -0000
@@ -86,8 +86,6 @@ 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)
 {
 	struct _mail_msg *msg;
@@ -432,23 +430,6 @@ 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)
-{
-	return mail_thread_queued;
-}
-#endif
-
 static gboolean
 mail_msgport_replied(GIOChannel *source, GIOCondition cond, void *d)
 {
@@ -534,73 +515,37 @@ mail_msgport_received2(GIOChannel *sourc
 
 
 static void
-mail_msg_destroy(EThread *e, EMsg *msg, void *data)
-{
-	mail_msg_t *m = (mail_msg_t *)msg;
-
-#ifdef MALLOC_CHECK
-	checkmem(m);
-	checkmem(m->cancel);
-	checkmem(m->priv);
-#endif	
-
-	mail_msg_free(m);
-}
-
-static void
-mail_msg_received(EThread *e, EMsg *msg, void *data)
+mail_msg_proxy (mail_msg_t *msg)
 {
-	mail_msg_t *m = (mail_msg_t *)msg;
-
-#ifdef MALLOC_CHECK
-	checkmem(m);
-	checkmem(m->cancel);
-	checkmem(m->priv);
-#endif
-
-	if (m->ops->describe_msg) {
-		char *text = m->ops->describe_msg(m, FALSE);
-
-#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
-
-		d(printf("message received at thread\n"));
-		camel_operation_register(m->cancel);
-		camel_operation_start(m->cancel, "%s", text);
-		g_free(text);
+	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);
 	}
-#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
 
-	if (m->ops->receive_msg) {
-		mail_enable_stop();
-		m->ops->receive_msg(m);
-		mail_disable_stop();
+	if (msg->ops->receive_msg != NULL) {
+		mail_enable_stop ();
+		msg->ops->receive_msg (msg);
+		mail_disable_stop ();
 	}
 
-	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);
+	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);
 	}
+
+	e_msgport_put (mail_gui_reply_port, (EMsg *) msg);
 }
 
 void mail_msg_cleanup(void)
 {
 	mail_msg_wait_all();
 
-	e_thread_destroy(mail_thread_queued_slow);
-	e_thread_destroy(mail_thread_queued);
-	e_thread_destroy(mail_thread_new);
-
 	g_io_channel_unref(mail_gui_channel);
 	g_io_channel_unref(mail_gui_reply_channel);
 
@@ -635,28 +580,52 @@ void mail_msg_init(void)
 	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();
 }
 
+static gpointer
+create_thread_pool (gpointer data)
+{
+	gint max_threads = GPOINTER_TO_INT (data);
+
+	/* once created, run forever */
+	return g_thread_pool_new ((GFunc) mail_msg_proxy,
+		NULL, max_threads, FALSE, NULL);
+}
+
+void
+mail_msg_unordered_push (mail_msg_t *msg)
+{
+	static GOnce once = G_ONCE_INIT;
+
+	g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (10));
+
+	g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
+}
+
+void
+mail_msg_fast_ordered_push (mail_msg_t *msg)
+{
+	static GOnce once = G_ONCE_INIT;
+
+	g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (1));
+
+	g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
+}
+
+void
+mail_msg_slow_ordered_push (mail_msg_t *msg)
+{
+	static GOnce once = G_ONCE_INIT;
+
+	g_once (&once, (GThreadFunc) create_thread_pool, GINT_TO_POINTER (1));
+
+	g_thread_pool_push ((GThreadPool *) once.retval, msg, NULL);
+}
+
 /* ********************************************************************** */
 
 /* locks */
@@ -748,7 +717,7 @@ int mail_async_event_emit(MailAsyncEvent
 		else
 			e_msgport_put(mail_gui_port, (EMsg *)m);
 	} else
-		e_thread_put(mail_thread_queued, (EMsg *)m);
+		mail_msg_fast_ordered_push ((mail_msg_t *) m);
 
 	return id;
 }
Index: mail/mail-mt.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-mt.h,v
retrieving revision 1.27
diff -u -p -r1.27 mail-mt.h
--- mail/mail-mt.h	16 Oct 2006 14:50:27 -0000	1.27
+++ mail/mail-mt.h	16 Oct 2006 16:37:38 -0000
@@ -60,6 +60,13 @@ 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_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);
Index: mail/mail-ops.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-ops.c,v
retrieving revision 1.459
diff -u -p -r1.459 mail-ops.c
--- mail/mail-ops.c	16 Oct 2006 14:25:28 -0000	1.459
+++ mail/mail-ops.c	16 Oct 2006 16:37:40 -0000
@@ -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_t ((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 = 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 = 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/mail-ops.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-ops.h,v
retrieving revision 1.74
diff -u -p -r1.74 mail-ops.h
--- mail/mail-ops.h	20 Feb 2006 16:01:01 -0000	1.74
+++ mail/mail-ops.h	16 Oct 2006 16:37:40 -0000
@@ -30,6 +30,8 @@ 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"
@@ -55,12 +57,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 +72,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/mail-send-recv.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-send-recv.c,v
retrieving revision 1.110
diff -u -p -r1.110 mail-send-recv.c
--- mail/mail-send-recv.c	21 Aug 2006 16:25:57 -0000	1.110
+++ mail/mail-send-recv.c	16 Oct 2006 16:37:40 -0000
@@ -817,7 +817,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-vfolder.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-vfolder.c,v
retrieving revision 1.139
diff -u -p -r1.139 mail-vfolder.c
--- mail/mail-vfolder.c	30 Jun 2006 09:46:26 -0000	1.139
+++ mail/mail-vfolder.c	16 Oct 2006 16:37:41 -0000
@@ -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;
 }
Index: mail/message-list.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/message-list.c,v
retrieving revision 1.438
diff -u -p -r1.438 message-list.c
--- mail/message-list.c	28 Sep 2006 08:56:51 -0000	1.438
+++ mail/message-list.c	16 Oct 2006 16:37:43 -0000
@@ -1886,7 +1886,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
@@ -3920,7 +3920,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: mail/importers/elm-importer.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/importers/elm-importer.c,v
retrieving revision 1.12
diff -u -p -r1.12 elm-importer.c
--- mail/importers/elm-importer.c	17 Dec 2005 18:35:37 -0000	1.12
+++ mail/importers/elm-importer.c	16 Oct 2006 16:37:43 -0000
@@ -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/importers/evolution-outlook-importer.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/importers/evolution-outlook-importer.c,v
retrieving revision 1.20
diff -u -p -r1.20 evolution-outlook-importer.c
--- mail/importers/evolution-outlook-importer.c	17 Dec 2005 18:35:37 -0000	1.20
+++ mail/importers/evolution-outlook-importer.c	16 Oct 2006 16:37:43 -0000
@@ -454,7 +454,7 @@ mail_importer_import_outlook(const char 
 	}
 
 	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/mail-importer.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/importers/mail-importer.c,v
retrieving revision 1.13
diff -u -p -r1.13 mail-importer.c
--- mail/importers/mail-importer.c	8 Feb 2006 11:51:32 -0000	1.13
+++ mail/importers/mail-importer.c	16 Oct 2006 16:37:43 -0000
@@ -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/netscape-importer.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/importers/netscape-importer.c,v
retrieving revision 1.22
diff -u -p -r1.22 netscape-importer.c
--- mail/importers/netscape-importer.c	6 Jan 2006 06:44:15 -0000	1.22
+++ mail/importers/netscape-importer.c	16 Oct 2006 16:37:44 -0000
@@ -1772,7 +1772,7 @@ mail_importer_netscape_import(NsImporter
 	if (m->importer->do_settings)
 		netscape_import_accounts(m->importer);
 	
-	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
===================================================================
RCS file: /cvs/gnome/evolution/mail/importers/pine-importer.c,v
retrieving revision 1.18
diff -u -p -r1.18 pine-importer.c
--- mail/importers/pine-importer.c	5 Feb 2006 23:46:26 -0000	1.18
+++ mail/importers/pine-importer.c	16 Oct 2006 16:37:44 -0000
@@ -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: plugins/exchange-operations/exchange-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-folder.c,v
retrieving revision 1.21
diff -u -p -r1.21 exchange-folder.c
--- plugins/exchange-operations/exchange-folder.c	13 Jun 2006 10:15:40 -0000	1.21
+++ plugins/exchange-operations/exchange-folder.c	16 Oct 2006 16:37:45 -0000
@@ -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/folder-unsubscribe/folder-unsubscribe.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/folder-unsubscribe/folder-unsubscribe.c,v
retrieving revision 1.1
diff -u -p -r1.1 folder-unsubscribe.c
--- plugins/folder-unsubscribe/folder-unsubscribe.c	22 Oct 2004 19:32:26 -0000	1.1
+++ plugins/folder-unsubscribe/folder-unsubscribe.c	16 Oct 2006 16:37:46 -0000
@@ -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
===================================================================
RCS file: /cvs/gnome/evolution/plugins/groupwise-features/share-folder-common.c,v
retrieving revision 1.9
diff -u -p -r1.9 share-folder-common.c
--- plugins/groupwise-features/share-folder-common.c	8 Feb 2006 11:08:24 -0000	1.9
+++ plugins/groupwise-features/share-folder-common.c	16 Oct 2006 16:37:46 -0000
@@ -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/mailing-list-actions/mailing-list-actions.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/mailing-list-actions/mailing-list-actions.c,v
retrieving revision 1.10
diff -u -p -r1.10 mailing-list-actions.c
--- plugins/mailing-list-actions/mailing-list-actions.c	23 Aug 2006 08:38:52 -0000	1.10
+++ plugins/mailing-list-actions/mailing-list-actions.c	16 Oct 2006 16:37:46 -0000
@@ -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/mark-all-read/mark-all-read.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/mark-all-read/mark-all-read.c,v
retrieving revision 1.1
diff -u -p -r1.1 mark-all-read.c
--- plugins/mark-all-read/mark-all-read.c	19 May 2005 17:32:41 -0000	1.1
+++ plugins/mark-all-read/mark-all-read.c	16 Oct 2006 16:37:46 -0000
@@ -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/save-attachments/save-attachments.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-attachments/save-attachments.c,v
retrieving revision 1.8
diff -u -p -r1.8 save-attachments.c
--- plugins/save-attachments/save-attachments.c	7 Jul 2006 23:48:24 -0000	1.8
+++ plugins/save-attachments/save-attachments.c	16 Oct 2006 16:37:46 -0000
@@ -407,5 +407,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);
 }
