| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 2017 Red Hat, Inc. (www.redhat.com) |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "evolution-ews-config.h" |
| 7 |
|
| 8 |
#include <glib/gi18n-lib.h> |
| 9 |
|
| 10 |
#include <e-util/e-util.h> |
| 11 |
#include <mail/e-mail-autoconfig.h> |
| 12 |
|
| 13 |
#include "common/camel-ews-settings.h" |
| 14 |
#include "common/e-ews-connection.h" |
| 15 |
#include "e-ews-config-lookup.h" |
| 16 |
|
| 17 |
#define E_TYPE_EWS_CONFIG_LOOKUP_RESULT \ |
| 18 |
(e_ews_config_lookup_result_get_type ()) |
| 19 |
#define E_EWS_CONFIG_LOOKUP_RESULT(obj) \ |
| 20 |
(G_TYPE_CHECK_INSTANCE_CAST \ |
| 21 |
((obj), E_TYPE_EWS_CONFIG_LOOKUP_RESULT, EEwsConfigLookupResult)) |
| 22 |
#define E_IS_EWS_CONFIG_LOOKUP_RESULT(obj) \ |
| 23 |
(G_TYPE_CHECK_INSTANCE_TYPE \ |
| 24 |
((obj), E_TYPE_EWS_CONFIG_LOOKUP_RESULT)) |
| 25 |
|
| 26 |
typedef struct _EEwsConfigLookupResult EEwsConfigLookupResult; |
| 27 |
typedef struct _EEwsConfigLookupResultClass EEwsConfigLookupResultClass; |
| 28 |
|
| 29 |
struct _EEwsConfigLookupResult { |
| 30 |
/*< private >*/ |
| 31 |
EConfigLookupResultSimple parent; |
| 32 |
|
| 33 |
gchar *host; |
| 34 |
}; |
| 35 |
|
| 36 |
struct _EEwsConfigLookupResultClass { |
| 37 |
/*< private >*/ |
| 38 |
EConfigLookupResultSimpleClass parent_class; |
| 39 |
}; |
| 40 |
|
| 41 |
GType e_ews_config_lookup_result_get_type (void) G_GNUC_CONST; |
| 42 |
|
| 43 |
G_DEFINE_TYPE (EEwsConfigLookupResult, e_ews_config_lookup_result, E_TYPE_CONFIG_LOOKUP_RESULT_SIMPLE) |
| 44 |
|
| 45 |
static void |
| 46 |
ews_config_lookup_result_copy_authentication (ESourceAuthentication *src_authentication_extension, |
| 47 |
ESource *des_source) |
| 48 |
{ |
| 49 |
ESourceAuthentication *des_authentication_extension; |
| 50 |
|
| 51 |
g_return_if_fail (E_IS_SOURCE_AUTHENTICATION (src_authentication_extension)); |
| 52 |
g_return_if_fail (E_IS_SOURCE (des_source)); |
| 53 |
|
| 54 |
des_authentication_extension = e_source_get_extension (des_source, E_SOURCE_EXTENSION_AUTHENTICATION); |
| 55 |
|
| 56 |
e_source_authentication_set_host (des_authentication_extension, |
| 57 |
e_source_authentication_get_host (src_authentication_extension)); |
| 58 |
|
| 59 |
e_source_authentication_set_port (des_authentication_extension, |
| 60 |
e_source_authentication_get_port (src_authentication_extension)); |
| 61 |
|
| 62 |
e_source_authentication_set_user (des_authentication_extension, |
| 63 |
e_source_authentication_get_user (src_authentication_extension)); |
| 64 |
} |
| 65 |
|
| 66 |
static gboolean |
| 67 |
ews_config_lookup_result_configure_source (EConfigLookupResult *lookup_result, |
| 68 |
EConfigLookup *config_lookup, |
| 69 |
ESource *source) |
| 70 |
{ |
| 71 |
ESource *other_source; |
| 72 |
ESourceAuthentication *src_authentication_extension; |
| 73 |
ESourceMailAccount *mail_account_extension; |
| 74 |
ESourceMailTransport *mail_transport_extension; |
| 75 |
|
| 76 |
g_return_val_if_fail (E_IS_EWS_CONFIG_LOOKUP_RESULT (lookup_result), FALSE); |
| 77 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), FALSE); |
| 78 |
|
| 79 |
/* Chain up to parent's method. */ |
| 80 |
if (!E_CONFIG_LOOKUP_RESULT_SIMPLE_CLASS (e_ews_config_lookup_result_parent_class)->configure_source (lookup_result, config_lookup, source)) |
| 81 |
return FALSE; |
| 82 |
|
| 83 |
src_authentication_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION); |
| 84 |
|
| 85 |
other_source = e_config_lookup_get_source (config_lookup, E_CONFIG_LOOKUP_SOURCE_MAIL_ACCOUNT); |
| 86 |
mail_account_extension = e_source_get_extension (other_source, E_SOURCE_EXTENSION_MAIL_ACCOUNT); |
| 87 |
ews_config_lookup_result_copy_authentication (src_authentication_extension, other_source); |
| 88 |
e_source_backend_set_backend_name (E_SOURCE_BACKEND (mail_account_extension), "ews"); |
| 89 |
|
| 90 |
other_source = e_config_lookup_get_source (config_lookup, E_CONFIG_LOOKUP_SOURCE_MAIL_TRANSPORT); |
| 91 |
mail_transport_extension = e_source_get_extension (other_source, E_SOURCE_EXTENSION_MAIL_TRANSPORT); |
| 92 |
ews_config_lookup_result_copy_authentication (src_authentication_extension, other_source); |
| 93 |
e_source_backend_set_backend_name (E_SOURCE_BACKEND (mail_transport_extension), "ews"); |
| 94 |
|
| 95 |
return TRUE; |
| 96 |
} |
| 97 |
|
| 98 |
static void |
| 99 |
e_ews_config_lookup_result_class_init (EEwsConfigLookupResultClass *klass) |
| 100 |
{ |
| 101 |
EConfigLookupResultSimpleClass *simple_result_class; |
| 102 |
|
| 103 |
simple_result_class = E_CONFIG_LOOKUP_RESULT_SIMPLE_CLASS (klass); |
| 104 |
simple_result_class->configure_source = ews_config_lookup_result_configure_source; |
| 105 |
} |
| 106 |
|
| 107 |
static void |
| 108 |
e_ews_config_lookup_result_init (EEwsConfigLookupResult *ews_result) |
| 109 |
{ |
| 110 |
} |
| 111 |
|
| 112 |
static EConfigLookupResult * |
| 113 |
e_ews_config_lookup_result_new (EConfigLookupResultKind kind, |
| 114 |
gint priority, |
| 115 |
const gchar *protocol, |
| 116 |
const gchar *display_name, |
| 117 |
const gchar *description, |
| 118 |
const gchar *password) |
| 119 |
{ |
| 120 |
EEwsConfigLookupResult *ews_result; |
| 121 |
|
| 122 |
g_return_val_if_fail (protocol != NULL, NULL); |
| 123 |
g_return_val_if_fail (display_name != NULL, NULL); |
| 124 |
g_return_val_if_fail (description != NULL, NULL); |
| 125 |
|
| 126 |
ews_result = g_object_new (E_TYPE_EWS_CONFIG_LOOKUP_RESULT, |
| 127 |
"kind", kind, |
| 128 |
"priority", priority, |
| 129 |
"is-complete", TRUE, |
| 130 |
"protocol", protocol, |
| 131 |
"display-name", display_name, |
| 132 |
"description", description, |
| 133 |
"password", password, |
| 134 |
NULL); |
| 135 |
|
| 136 |
return E_CONFIG_LOOKUP_RESULT (ews_result); |
| 137 |
} |
| 138 |
|
| 139 |
/* ------------------------------------------------------------------------- */ |
| 140 |
|
| 141 |
/* Standard GObject macros */ |
| 142 |
#define E_TYPE_EWS_CONFIG_LOOKUP \ |
| 143 |
(e_ews_config_lookup_get_type ()) |
| 144 |
#define E_EWS_CONFIG_LOOKUP(obj) \ |
| 145 |
(G_TYPE_CHECK_INSTANCE_CAST \ |
| 146 |
((obj), E_TYPE_EWS_CONFIG_LOOKUP, EEwsConfigLookup)) |
| 147 |
#define E_EWS_CONFIG_LOOKUP_CLASS(cls) \ |
| 148 |
(G_TYPE_CHECK_CLASS_CAST \ |
| 149 |
((cls), E_TYPE_EWS_CONFIG_LOOKUP, EEwsConfigLookupClass)) |
| 150 |
#define E_IS_EWS_CONFIG_LOOKUP(obj) \ |
| 151 |
(G_TYPE_CHECK_INSTANCE_TYPE \ |
| 152 |
((obj), E_TYPE_EWS_CONFIG_LOOKUP)) |
| 153 |
#define E_IS_EWS_CONFIG_LOOKUP_CLASS(cls) \ |
| 154 |
(G_TYPE_CHECK_CLASS_TYPE \ |
| 155 |
((cls), E_TYPE_EWS_CONFIG_LOOKUP)) |
| 156 |
#define E_EWS_CONFIG_LOOKUP_GET_CLASS(obj) \ |
| 157 |
(G_TYPE_INSTANCE_GET_CLASS \ |
| 158 |
((obj), E_TYPE_EWS_CONFIG_LOOKUP, EEwsConfigLookupClass)) |
| 159 |
|
| 160 |
typedef struct _EEwsConfigLookup EEwsConfigLookup; |
| 161 |
typedef struct _EEwsConfigLookupClass EEwsConfigLookupClass; |
| 162 |
|
| 163 |
struct _EEwsConfigLookup { |
| 164 |
EExtension parent; |
| 165 |
}; |
| 166 |
|
| 167 |
struct _EEwsConfigLookupClass { |
| 168 |
EExtensionClass parent_class; |
| 169 |
}; |
| 170 |
|
| 171 |
GType e_ews_config_lookup_get_type (void) G_GNUC_CONST; |
| 172 |
|
| 173 |
static void ews_config_lookup_worker_iface_init (EConfigLookupWorkerInterface *iface); |
| 174 |
|
| 175 |
G_DEFINE_DYNAMIC_TYPE_EXTENDED (EEwsConfigLookup, e_ews_config_lookup, E_TYPE_EXTENSION, 0, |
| 176 |
G_IMPLEMENT_INTERFACE_DYNAMIC (E_TYPE_CONFIG_LOOKUP_WORKER, ews_config_lookup_worker_iface_init)) |
| 177 |
|
| 178 |
static const gchar * |
| 179 |
ews_config_lookup_worker_get_display_name (EConfigLookupWorker *worker) |
| 180 |
{ |
| 181 |
return _("Exchange Web Services autodiscovery"); |
| 182 |
} |
| 183 |
|
| 184 |
static void |
| 185 |
ews_config_lookup_worker_result_from_data (EConfigLookup *config_lookup, |
| 186 |
const gchar *email_address, |
| 187 |
const gchar *hosturl, |
| 188 |
const gchar *oaburl, |
| 189 |
const ENamedParameters *params) |
| 190 |
{ |
| 191 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup)); |
| 192 |
|
| 193 |
if (hosturl && *hosturl) { |
| 194 |
EConfigLookupResult *lookup_result; |
| 195 |
GString *description; |
| 196 |
const gchar *extension_name; |
| 197 |
GUri *uri; |
| 198 |
|
| 199 |
extension_name = e_source_camel_get_extension_name ("ews"); |
| 200 |
|
| 201 |
uri = g_uri_parse (hosturl, SOUP_HTTP_URI_FLAGS | G_URI_FLAGS_PARSE_RELAXED, NULL); |
| 202 |
|
| 203 |
description = g_string_new (""); |
| 204 |
|
| 205 |
if (email_address && *email_address) |
| 206 |
g_string_append_printf (description, _("User: %s"), email_address); |
| 207 |
|
| 208 |
if (description->len) |
| 209 |
g_string_append_c (description, '\n'); |
| 210 |
|
| 211 |
g_string_append_printf (description, _("Host URL: %s"), hosturl); |
| 212 |
|
| 213 |
if (oaburl && *oaburl) { |
| 214 |
g_string_append_c (description, '\n'); |
| 215 |
g_string_append_printf (description, _("OAB URL: %s"), oaburl); |
| 216 |
} |
| 217 |
|
| 218 |
lookup_result = e_ews_config_lookup_result_new (E_CONFIG_LOOKUP_RESULT_COLLECTION, |
| 219 |
E_CONFIG_LOOKUP_RESULT_PRIORITY_IMAP - 100, /* This is better than IMAP */ |
| 220 |
"ews", |
| 221 |
_("Exchange Web Services"), |
| 222 |
description->str, |
| 223 |
params && e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_PASSWORD) && |
| 224 |
e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_REMEMBER_PASSWORD) ? |
| 225 |
e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_PASSWORD) : NULL); |
| 226 |
|
| 227 |
e_config_lookup_result_simple_add_string (lookup_result, E_SOURCE_EXTENSION_COLLECTION, |
| 228 |
"backend-name", "ews"); |
| 229 |
|
| 230 |
e_config_lookup_result_simple_add_string (lookup_result, extension_name, |
| 231 |
"hosturl", hosturl); |
| 232 |
|
| 233 |
e_config_lookup_result_simple_add_string (lookup_result, extension_name, |
| 234 |
"oaburl", oaburl); |
| 235 |
|
| 236 |
if (email_address && *email_address) { |
| 237 |
e_config_lookup_result_simple_add_string (lookup_result, extension_name, |
| 238 |
"email", email_address); |
| 239 |
|
| 240 |
e_config_lookup_result_simple_add_string (lookup_result, |
| 241 |
E_SOURCE_EXTENSION_COLLECTION, |
| 242 |
"identity", email_address); |
| 243 |
|
| 244 |
e_config_lookup_result_simple_add_string (lookup_result, |
| 245 |
E_SOURCE_EXTENSION_AUTHENTICATION, |
| 246 |
"user", email_address); |
| 247 |
} |
| 248 |
|
| 249 |
if (uri && g_uri_get_host (uri) && *g_uri_get_host (uri)) { |
| 250 |
e_config_lookup_result_simple_add_string (lookup_result, |
| 251 |
E_SOURCE_EXTENSION_AUTHENTICATION, |
| 252 |
"host", g_uri_get_host (uri)); |
| 253 |
} |
| 254 |
|
| 255 |
if (uri && g_uri_get_port (uri) > 0) { |
| 256 |
e_config_lookup_result_simple_add_uint (lookup_result, |
| 257 |
E_SOURCE_EXTENSION_AUTHENTICATION, |
| 258 |
"port", g_uri_get_port (uri)); |
| 259 |
} |
| 260 |
|
| 261 |
e_config_lookup_add_result (config_lookup, lookup_result); |
| 262 |
|
| 263 |
g_string_free (description, TRUE); |
| 264 |
if (uri) |
| 265 |
g_uri_unref (uri); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
static void |
| 270 |
ews_config_lookup_worker_result_from_settings (EConfigLookupWorker *lookup_worker, |
| 271 |
EConfigLookup *config_lookup, |
| 272 |
const gchar *email_address, |
| 273 |
CamelEwsSettings *ews_settings, |
| 274 |
const ENamedParameters *params) |
| 275 |
{ |
| 276 |
g_return_if_fail (E_IS_EWS_CONFIG_LOOKUP (lookup_worker)); |
| 277 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup)); |
| 278 |
g_return_if_fail (CAMEL_IS_EWS_SETTINGS (ews_settings)); |
| 279 |
|
| 280 |
ews_config_lookup_worker_result_from_data (config_lookup, |
| 281 |
email_address, |
| 282 |
camel_ews_settings_get_hosturl (ews_settings), |
| 283 |
camel_ews_settings_get_oaburl (ews_settings), |
| 284 |
params); |
| 285 |
} |
| 286 |
|
| 287 |
static void |
| 288 |
ews_config_lookup_worker_run (EConfigLookupWorker *lookup_worker, |
| 289 |
EConfigLookup *config_lookup, |
| 290 |
const ENamedParameters *params, |
| 291 |
ENamedParameters **out_restart_params, |
| 292 |
GCancellable *cancellable, |
| 293 |
GError **error) |
| 294 |
{ |
| 295 |
CamelEwsSettings *ews_settings = NULL; |
| 296 |
ESource *source; |
| 297 |
const gchar *email_address; |
| 298 |
const gchar *password; |
| 299 |
const gchar *extension_name; |
| 300 |
|
| 301 |
g_return_if_fail (E_IS_EWS_CONFIG_LOOKUP (lookup_worker)); |
| 302 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup)); |
| 303 |
g_return_if_fail (params != NULL); |
| 304 |
|
| 305 |
email_address = e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_EMAIL_ADDRESS); |
| 306 |
|
| 307 |
if (!email_address || !*email_address) |
| 308 |
return; |
| 309 |
|
| 310 |
if (!e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_PASSWORD)) { |
| 311 |
g_set_error (error, E_CONFIG_LOOKUP_WORKER_ERROR, E_CONFIG_LOOKUP_WORKER_ERROR_REQUIRES_PASSWORD, |
| 312 |
_("Requires password to continue.")); |
| 313 |
return; |
| 314 |
} |
| 315 |
|
| 316 |
ews_settings = g_object_new (CAMEL_TYPE_EWS_SETTINGS, NULL); |
| 317 |
camel_ews_settings_set_email (ews_settings, email_address); |
| 318 |
|
| 319 |
extension_name = e_source_camel_get_extension_name ("ews"); |
| 320 |
source = e_config_lookup_get_source (config_lookup, E_CONFIG_LOOKUP_SOURCE_COLLECTION); |
| 321 |
if (source && e_source_has_extension (source, extension_name)) { |
| 322 |
ESourceCamel *camel_extension; |
| 323 |
CamelSettings *settings; |
| 324 |
|
| 325 |
camel_extension = e_source_get_extension (source, extension_name); |
| 326 |
settings = e_source_camel_get_settings (camel_extension); |
| 327 |
|
| 328 |
/* Copy only the host url */ |
| 329 |
if (CAMEL_IS_EWS_SETTINGS (settings)) |
| 330 |
camel_ews_settings_set_hosturl (ews_settings, camel_ews_settings_get_hosturl (CAMEL_EWS_SETTINGS (settings))); |
| 331 |
} |
| 332 |
|
| 333 |
password = e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_PASSWORD); |
| 334 |
|
| 335 |
if (password) { |
| 336 |
const gchar *servers; |
| 337 |
gchar *certificate_host = NULL; |
| 338 |
gchar *certificate_pem = NULL; |
| 339 |
GTlsCertificateFlags certificate_errors = 0; |
| 340 |
GError *local_error = NULL; |
| 341 |
|
| 342 |
if (e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_PEM) && |
| 343 |
e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_TRUST) && |
| 344 |
e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_HOST)) { |
| 345 |
GTlsCertificate *certificate; |
| 346 |
const gchar *param_certificate_pem; |
| 347 |
|
| 348 |
param_certificate_pem = e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_PEM); |
| 349 |
certificate = g_tls_certificate_new_from_pem (param_certificate_pem, -1, NULL); |
| 350 |
|
| 351 |
if (certificate) { |
| 352 |
ETrustPromptResponse trust_response; |
| 353 |
|
| 354 |
trust_response = e_config_lookup_decode_certificate_trust ( |
| 355 |
e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_TRUST)); |
| 356 |
|
| 357 |
if (trust_response != E_TRUST_PROMPT_RESPONSE_UNKNOWN) { |
| 358 |
ESourceWebdav *webdav_extension; |
| 359 |
|
| 360 |
webdav_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND); |
| 361 |
e_source_webdav_update_ssl_trust (webdav_extension, |
| 362 |
e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_HOST), |
| 363 |
certificate, trust_response); |
| 364 |
} |
| 365 |
|
| 366 |
g_object_unref (certificate); |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
if (e_ews_autodiscover_ws_url_sync (source, ews_settings, email_address, password, &certificate_pem, &certificate_errors, cancellable, &local_error)) { |
| 371 |
ews_config_lookup_worker_result_from_settings (lookup_worker, config_lookup, email_address, ews_settings, params); |
| 372 |
} else if (g_error_matches (local_error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE)) { |
| 373 |
const gchar *hosturl; |
| 374 |
GUri *uri; |
| 375 |
|
| 376 |
hosturl = camel_ews_settings_get_hosturl (ews_settings); |
| 377 |
uri = g_uri_parse (hosturl, SOUP_HTTP_URI_FLAGS | G_URI_FLAGS_PARSE_RELAXED, NULL); |
| 378 |
if (uri) { |
| 379 |
certificate_host = g_strdup (g_uri_get_host (uri)); |
| 380 |
|
| 381 |
g_uri_unref (uri); |
| 382 |
} |
| 383 |
} else { |
| 384 |
g_clear_error (&local_error); |
| 385 |
} |
| 386 |
|
| 387 |
servers = e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_SERVERS); |
| 388 |
|
| 389 |
if (servers && *servers) { |
| 390 |
gchar **servers_strv; |
| 391 |
gint ii; |
| 392 |
|
| 393 |
servers_strv = g_strsplit (servers, ";", 0); |
| 394 |
|
| 395 |
for (ii = 0; servers_strv && servers_strv[ii] && !g_cancellable_is_cancelled (cancellable) && !local_error; ii++) { |
| 396 |
const gchar *server = servers_strv[ii]; |
| 397 |
gchar *tmp = NULL; |
| 398 |
|
| 399 |
if (*server && !strstr (server, "://")) { |
| 400 |
tmp = g_strconcat ("https://", server, "/EWS/Exchange.asmx", NULL); |
| 401 |
server = tmp; |
| 402 |
} |
| 403 |
|
| 404 |
camel_ews_settings_set_hosturl (ews_settings, server); |
| 405 |
|
| 406 |
if (e_ews_autodiscover_ws_url_sync (source, ews_settings, email_address, password, &certificate_pem, &certificate_errors, cancellable, &local_error)) { |
| 407 |
ews_config_lookup_worker_result_from_settings (lookup_worker, config_lookup, email_address, ews_settings, params); |
| 408 |
} else if (g_error_matches (local_error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE)) { |
| 409 |
const gchar *hosturl; |
| 410 |
GUri *uri; |
| 411 |
|
| 412 |
hosturl = camel_ews_settings_get_hosturl (ews_settings); |
| 413 |
uri = g_uri_parse (hosturl, SOUP_HTTP_URI_FLAGS | G_URI_FLAGS_PARSE_RELAXED, NULL); |
| 414 |
if (uri) { |
| 415 |
certificate_host = g_strdup (g_uri_get_host (uri)); |
| 416 |
|
| 417 |
g_uri_unref (uri); |
| 418 |
} |
| 419 |
} else { |
| 420 |
g_clear_error (&local_error); |
| 421 |
} |
| 422 |
|
| 423 |
g_free (tmp); |
| 424 |
} |
| 425 |
|
| 426 |
g_strfreev (servers_strv); |
| 427 |
} |
| 428 |
|
| 429 |
if (g_error_matches (local_error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE) && |
| 430 |
certificate_pem && *certificate_pem && certificate_errors) { |
| 431 |
gchar *description = e_trust_prompt_describe_certificate_errors (certificate_errors); |
| 432 |
|
| 433 |
if (description) { |
| 434 |
g_set_error_literal (error, E_CONFIG_LOOKUP_WORKER_ERROR, |
| 435 |
E_CONFIG_LOOKUP_WORKER_ERROR_CERTIFICATE, description); |
| 436 |
|
| 437 |
g_free (description); |
| 438 |
|
| 439 |
if (out_restart_params) { |
| 440 |
if (!*out_restart_params) |
| 441 |
*out_restart_params = e_named_parameters_new_clone (params); |
| 442 |
|
| 443 |
e_named_parameters_set (*out_restart_params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_PEM, certificate_pem); |
| 444 |
e_named_parameters_set (*out_restart_params, E_CONFIG_LOOKUP_PARAM_CERTIFICATE_HOST, certificate_host); |
| 445 |
} |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
g_clear_error (&local_error); |
| 450 |
g_free (certificate_host); |
| 451 |
g_free (certificate_pem); |
| 452 |
|
| 453 |
if (out_restart_params && !*out_restart_params) |
| 454 |
*out_restart_params = e_named_parameters_new_clone (params); |
| 455 |
} |
| 456 |
|
| 457 |
g_clear_object (&ews_settings); |
| 458 |
} |
| 459 |
|
| 460 |
static void |
| 461 |
ews_config_lookup_constructed (GObject *object) |
| 462 |
{ |
| 463 |
EConfigLookup *config_lookup; |
| 464 |
|
| 465 |
/* Chain up to parent's method. */ |
| 466 |
G_OBJECT_CLASS (e_ews_config_lookup_parent_class)->constructed (object); |
| 467 |
|
| 468 |
config_lookup = E_CONFIG_LOOKUP (e_extension_get_extensible (E_EXTENSION (object))); |
| 469 |
|
| 470 |
e_config_lookup_register_worker (config_lookup, E_CONFIG_LOOKUP_WORKER (object)); |
| 471 |
} |
| 472 |
|
| 473 |
static void |
| 474 |
e_ews_config_lookup_class_init (EEwsConfigLookupClass *class) |
| 475 |
{ |
| 476 |
GObjectClass *object_class; |
| 477 |
EExtensionClass *extension_class; |
| 478 |
|
| 479 |
object_class = G_OBJECT_CLASS (class); |
| 480 |
object_class->constructed = ews_config_lookup_constructed; |
| 481 |
|
| 482 |
extension_class = E_EXTENSION_CLASS (class); |
| 483 |
extension_class->extensible_type = E_TYPE_CONFIG_LOOKUP; |
| 484 |
} |
| 485 |
|
| 486 |
static void |
| 487 |
e_ews_config_lookup_class_finalize (EEwsConfigLookupClass *class) |
| 488 |
{ |
| 489 |
} |
| 490 |
|
| 491 |
static void |
| 492 |
ews_config_lookup_worker_iface_init (EConfigLookupWorkerInterface *iface) |
| 493 |
{ |
| 494 |
iface->get_display_name = ews_config_lookup_worker_get_display_name; |
| 495 |
iface->run = ews_config_lookup_worker_run; |
| 496 |
} |
| 497 |
|
| 498 |
static void |
| 499 |
e_ews_config_lookup_init (EEwsConfigLookup *extension) |
| 500 |
{ |
| 501 |
} |
| 502 |
|
| 503 |
/* ------------------------------------------------------------------------- */ |
| 504 |
|
| 505 |
#define E_TYPE_MAIL_AUTOCONFIG_EWS_EXTENSION (e_mail_autoconfig_ews_extension_get_type ()) |
| 506 |
|
| 507 |
typedef struct _EMailAutoconfigEwsExtension EMailAutoconfigEwsExtension; |
| 508 |
typedef struct _EMailAutoconfigEwsExtensionClass EMailAutoconfigEwsExtensionClass; |
| 509 |
|
| 510 |
struct _EMailAutoconfigEwsExtension { |
| 511 |
EExtension parent; |
| 512 |
}; |
| 513 |
|
| 514 |
struct _EMailAutoconfigEwsExtensionClass { |
| 515 |
EExtensionClass parent_class; |
| 516 |
}; |
| 517 |
|
| 518 |
GType e_mail_autoconfig_ews_extension_get_type (void) G_GNUC_CONST; |
| 519 |
|
| 520 |
G_DEFINE_DYNAMIC_TYPE (EMailAutoconfigEwsExtension, e_mail_autoconfig_ews_extension, E_TYPE_EXTENSION) |
| 521 |
|
| 522 |
static void |
| 523 |
e_mail_autoconfig_ews_extesion_process_custom_types (EMailAutoconfig *mail_autoconfig, |
| 524 |
EConfigLookup *config_lookup, |
| 525 |
GHashTable *custom_types, |
| 526 |
gpointer user_data) |
| 527 |
{ |
| 528 |
const ENamedParameters *autoconfig_params; |
| 529 |
|
| 530 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup)); |
| 531 |
g_return_if_fail (custom_types != NULL); |
| 532 |
|
| 533 |
autoconfig_params = g_hash_table_lookup (custom_types, "exchange"); |
| 534 |
if (!autoconfig_params) |
| 535 |
return; |
| 536 |
|
| 537 |
ews_config_lookup_worker_result_from_data (config_lookup, |
| 538 |
e_named_parameters_get (autoconfig_params, "user"), |
| 539 |
e_named_parameters_get (autoconfig_params, "ewsURL"), |
| 540 |
NULL, |
| 541 |
NULL); |
| 542 |
} |
| 543 |
|
| 544 |
static void |
| 545 |
e_mail_autoconfig_ews_extension_constructed (GObject *object) |
| 546 |
{ |
| 547 |
EExtensible *extensible; |
| 548 |
|
| 549 |
/* Chain up to parent's method. */ |
| 550 |
G_OBJECT_CLASS (e_mail_autoconfig_ews_extension_parent_class)->constructed (object); |
| 551 |
|
| 552 |
extensible = e_extension_get_extensible (E_EXTENSION (object)); |
| 553 |
|
| 554 |
g_signal_connect (extensible, "process-custom-types", |
| 555 |
G_CALLBACK (e_mail_autoconfig_ews_extesion_process_custom_types), NULL); |
| 556 |
} |
| 557 |
|
| 558 |
static void |
| 559 |
e_mail_autoconfig_ews_extension_class_init (EMailAutoconfigEwsExtensionClass *klass) |
| 560 |
{ |
| 561 |
GObjectClass *object_class; |
| 562 |
EExtensionClass *extension_class; |
| 563 |
|
| 564 |
object_class = G_OBJECT_CLASS (klass); |
| 565 |
object_class->constructed = e_mail_autoconfig_ews_extension_constructed; |
| 566 |
|
| 567 |
extension_class = E_EXTENSION_CLASS (klass); |
| 568 |
extension_class->extensible_type = E_TYPE_MAIL_AUTOCONFIG; |
| 569 |
} |
| 570 |
|
| 571 |
static void |
| 572 |
e_mail_autoconfig_ews_extension_class_finalize (EMailAutoconfigEwsExtensionClass *klass) |
| 573 |
{ |
| 574 |
} |
| 575 |
|
| 576 |
static void |
| 577 |
e_mail_autoconfig_ews_extension_init (EMailAutoconfigEwsExtension *extension) |
| 578 |
{ |
| 579 |
} |
| 580 |
|
| 581 |
/* ------------------------------------------------------------------------- */ |
| 582 |
|
| 583 |
void |
| 584 |
e_ews_config_lookup_type_register (GTypeModule *type_module) |
| 585 |
{ |
| 586 |
/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration |
| 587 |
* function, so we have to wrap it with a public function in |
| 588 |
* order to register types from a separate compilation unit. */ |
| 589 |
e_ews_config_lookup_register_type (type_module); |
| 590 |
e_mail_autoconfig_ews_extension_register_type (type_module); |
| 591 |
} |