diff options
-rw-r--r-- | mail/e-mail-session-utils.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/mail/e-mail-session-utils.c b/mail/e-mail-session-utils.c index 08270927f4..4e90a19ecf 100644 --- a/mail/e-mail-session-utils.c +++ b/mail/e-mail-session-utils.c @@ -405,6 +405,7 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple, if (camel_address_length (context->recipients) > 0) { CamelProvider *provider; CamelService *service; + gboolean did_connect = FALSE; service = camel_session_get_service ( CAMEL_SESSION (session), context->transport_uid); @@ -418,11 +419,15 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple, return; } - /* XXX This API does not allow for cancellation. */ - if (!camel_service_connect_sync (service, &error)) { - g_simple_async_result_set_from_error (simple, error); - g_error_free (error); - return; + if (camel_service_get_connection_status (service) != CAMEL_SERVICE_CONNECTED) { + did_connect = TRUE; + + /* XXX This API does not allow for cancellation. */ + if (!camel_service_connect_sync (service, &error)) { + g_simple_async_result_set_from_error (simple, error); + g_error_free (error); + return; + } } provider = camel_service_get_provider (service); @@ -435,6 +440,9 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple, context->message, context->from, context->recipients, cancellable, &error); + if (did_connect) + camel_service_disconnect_sync (service, error == NULL, error ? NULL : &error); + if (error != NULL) { g_simple_async_result_set_from_error (simple, error); g_error_free (error); |