diff --git a/mail/e-http-request.c b/mail/e-http-request.c
index d6fe5d2..88d69b7 100644
--- a/mail/e-http-request.c
+++ b/mail/e-http-request.c
@@ -76,14 +76,6 @@ copy_stream_to_stream (CamelStream *input,
 	return total_len;
 }
 
-static gboolean
-unref_soup_session (SoupSession *session)
-{
-	g_object_unref (session);
-
-	return FALSE;
-}
-
 static void
 handle_http_request (GSimpleAsyncResult *res,
                      GObject *object,
@@ -260,9 +252,14 @@ handle_http_request (GSimpleAsyncResult *res,
 		SoupURI *soup_uri;
 		gsize real_content_length;
 		GInputStream *http_stream;
+		GMainContext *context;
+
+		context = g_main_context_new ();
+		g_main_context_push_thread_default (context);
 
 		session = soup_session_sync_new_with_options (
 				SOUP_SESSION_TIMEOUT, 90,
+				SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
 				NULL);
 
 		requester = soup_requester_new ();
@@ -358,7 +355,9 @@ handle_http_request (GSimpleAsyncResult *res,
 		g_object_unref (cache_stream);
 		g_object_unref (http_request);
 		g_object_unref (msg);
-		g_idle_add ((GSourceFunc) unref_soup_session, session);
+		g_object_unref (session);
+		g_main_context_pop_thread_default (context);
+		g_main_context_unref (context);
 
 		d (printf ("Received image from %s\n"
 			"Content-Type: %s\n"
