gchar * camel_ews_utils_get_host_name (CamelSettings *settings) { CamelURL *url; gchar *host = NULL, *hosturl; g_return_val_if_fail (settings != NULL, NULL); hosturl = camel_ews_settings_dup_hosturl (CAMEL_EWS_SETTINGS (settings)); url = camel_url_new (hosturl, NULL); if (url) { host = g_strdup (url->host); camel_url_free (url); } if (!host || !*host) { g_free (host); host = camel_network_settings_dup_host (CAMEL_NETWORK_SETTINGS (settings)); } g_free (hosturl); return host; }
static gboolean ews_send_to_sync (CamelTransport *transport, CamelMimeMessage *message, CamelAddress *from, CamelAddress *recipients, gboolean *out_sent_message_saved, GCancellable *cancellable, GError **error) { CamelNetworkSettings *network_settings; CamelEwsSettings *ews_settings; CamelInternetAddress *used_from; CamelSettings *settings; CamelService *service; EEwsConnection *cnc; EwsFolderId *folder_id = NULL; gchar *ews_email; gchar *host_url; gchar *user; gboolean success = FALSE; service = CAMEL_SERVICE (transport); settings = camel_service_ref_settings (service); ews_settings = CAMEL_EWS_SETTINGS (settings); ews_email = camel_ews_settings_dup_email (ews_settings); host_url = camel_ews_settings_dup_hosturl (ews_settings); network_settings = CAMEL_NETWORK_SETTINGS (settings); user = camel_network_settings_dup_user (network_settings); g_object_unref (settings); if (CAMEL_IS_INTERNET_ADDRESS (from)) used_from = CAMEL_INTERNET_ADDRESS (from); else used_from = camel_mime_message_get_from (message); if (!used_from || camel_address_length (CAMEL_ADDRESS (used_from)) == 0) { g_set_error_literal ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Cannot send message with no From address")); goto exit; } else if (camel_address_length (CAMEL_ADDRESS (used_from)) > 1) { g_set_error_literal ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Exchange server cannot send message with " "multiple From addresses")); goto exit; } else { const gchar *used_email = NULL; if (!camel_internet_address_get (used_from, 0, NULL, &used_email)) { g_set_error_literal ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Failed to read From address")); goto exit; } } cnc = ews_transport_ref_connection (CAMEL_EWS_TRANSPORT (service)); if (!cnc) { g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_NOT_CONNECTED, _("Service not connected")); goto exit; } if (ews_transport_can_server_side_sent_folder (service, &folder_id, cancellable)) { if (out_sent_message_saved) *out_sent_message_saved = TRUE; } success = camel_ews_utils_create_mime_message ( cnc, folder_id ? "SendAndSaveCopy" : "SendOnly", folder_id, message, NULL, from, recipients, NULL, NULL, cancellable, error); g_object_unref (cnc); e_ews_folder_id_free (folder_id); exit: g_free (ews_email); g_free (host_url); g_free (user); return success; }
static CamelAuthenticationResult ews_transport_authenticate_sync (CamelService *service, const gchar *mechanism, GCancellable *cancellable, GError **error) { CamelAuthenticationResult result; CamelEwsTransport *ews_transport; CamelSettings *settings; CamelEwsSettings *ews_settings; EEwsConnection *connection; const gchar *password; gchar *hosturl, *new_sync_state = NULL; GSList *folders_created = NULL; GSList *folders_updated = NULL; GSList *folders_deleted = NULL; gboolean includes_last_folder = FALSE; GError *local_error = NULL; ews_transport = CAMEL_EWS_TRANSPORT (service); password = camel_service_get_password (service); settings = camel_service_ref_settings (service); ews_settings = CAMEL_EWS_SETTINGS (settings); hosturl = camel_ews_settings_dup_hosturl (ews_settings); connection = e_ews_connection_new (hosturl, ews_settings); e_ews_connection_set_password (connection, password); g_free (hosturl); g_object_unref (settings); e_binding_bind_property ( service, "proxy-resolver", connection, "proxy-resolver", G_BINDING_SYNC_CREATE); /* XXX We need to run some operation that requires authentication * but does not change any server-side state, so we can check * the error status and determine if our password is valid. * David suggested e_ews_connection_sync_folder_hierarchy(), * since we have to do that eventually anyway. */ e_ews_connection_sync_folder_hierarchy_sync (connection, EWS_PRIORITY_MEDIUM, NULL, &new_sync_state, &includes_last_folder, &folders_created, &folders_updated, &folders_deleted, cancellable, &local_error); g_slist_free_full (folders_created, g_object_unref); g_slist_free_full (folders_updated, g_object_unref); g_slist_free_full (folders_deleted, g_free); g_free (new_sync_state); if (g_error_matches (local_error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_UNAVAILABLE)) { local_error->domain = CAMEL_SERVICE_ERROR; local_error->code = CAMEL_SERVICE_ERROR_UNAVAILABLE; } if (!local_error) { g_mutex_lock (&ews_transport->priv->connection_lock); g_clear_object (&ews_transport->priv->connection); ews_transport->priv->connection = g_object_ref (connection); g_mutex_unlock (&ews_transport->priv->connection_lock); } else { g_mutex_lock (&ews_transport->priv->connection_lock); g_clear_object (&ews_transport->priv->connection); g_mutex_unlock (&ews_transport->priv->connection_lock); } if (!local_error) { result = CAMEL_AUTHENTICATION_ACCEPTED; } else if (g_error_matches (local_error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED)) { g_clear_error (&local_error); result = CAMEL_AUTHENTICATION_REJECTED; } else { g_propagate_error (error, local_error); result = CAMEL_AUTHENTICATION_ERROR; } g_object_unref (connection); return result; }