Debian Codegraph @

src/Microsoft365/evolution/e-mail-config-m365-backend.c

raw
1 /*
2 * SPDX-FileCopyrightText: (C) 2020 Red Hat (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 <camel/camel.h>
11 #include <libebackend/libebackend.h>
12
13 #include <mail/e-mail-config-auth-check.h>
14 #include <mail/e-mail-config-receiving-page.h>
15
16 #include "common/camel-m365-settings.h"
17 #include "common/e-m365-connection.h"
18
19 #include "e-mail-config-m365-backend.h"
20
21 struct _EMailConfigM365BackendPrivate {
22 GtkWidget *user_entry;
23 GtkWidget *impersonate_user_entry;
24 GtkGrid *oauth2_settings_grid;
25 GtkWidget *oauth2_override_check;
26 GtkWidget *oauth2_tenant_entry;
27 GtkWidget *oauth2_client_id_entry;
28 GtkWidget *oauth2_redirect_uri_entry;
29 GtkWidget *oauth2_endpoint_host_entry;
30 };
31
32 G_DEFINE_DYNAMIC_TYPE_EXTENDED (EMailConfigM365Backend, e_mail_config_m365_backend, E_TYPE_MAIL_CONFIG_SERVICE_BACKEND, 0,
33 G_ADD_PRIVATE_DYNAMIC (EMailConfigM365Backend))
34
35 static ESource *
36 mail_config_m365_backend_new_collection (EMailConfigServiceBackend *backend)
37 {
38 EMailConfigServiceBackendClass *class;
39 ESourceBackend *extension;
40 ESource *source;
41 const gchar *extension_name;
42
43 /* This backend serves double duty. One instance holds the
44 * mail account source, another holds the mail transport source.
45 * We can differentiate by examining the EMailConfigServicePage
46 * the backend is associated with. We return a new collection
47 * for both the Receiving Page and Sending Page. Although the
48 * Sending Page instance ultimately gets discarded, it's still
49 * needed to avoid creating a [Microsoft365 Backend] extension
50 * in the mail transport source. */
51
52 class = E_MAIL_CONFIG_SERVICE_BACKEND_GET_CLASS (backend);
53
54 source = e_source_new (NULL, NULL, NULL);
55 extension_name = E_SOURCE_EXTENSION_COLLECTION;
56 extension = e_source_get_extension (source, extension_name);
57 e_source_backend_set_backend_name (extension, class->backend_name);
58
59 return source;
60 }
61
62 static void
63 mail_config_m365_backend_set_oauth2_tooltip (GtkWidget *widget,
64 const gchar *value,
65 const gchar *when_value_empty,
66 gchar *when_value_filled) /* takes ownership */
67 {
68 g_return_if_fail (GTK_IS_WIDGET (widget));
69
70 gtk_widget_set_tooltip_text (widget, value && *value ? when_value_filled : when_value_empty);
71
72 g_free (when_value_filled);
73 }
74
75 static void
76 mail_config_m365_backend_insert_widgets (EMailConfigServiceBackend *backend,
77 GtkBox *parent)
78 {
79 EMailConfigM365Backend *m365_backend;
80 EMailConfigServicePage *page;
81 ESource *source;
82 ESourceExtension *extension;
83 ESourceAuthentication *auth_extension;
84 CamelSettings *settings;
85 CamelM365Settings *m365_settings;
86 GtkLabel *label;
87 GtkWidget *widget;
88 GtkWidget *container;
89 GtkWidget *expander;
90 GtkWidget *advanced_help;
91 GtkWidget *endpoint_host_label;
92 GtkWidget *redirect_uri_label;
93 const gchar *extension_name;
94 const gchar *text;
95 gchar *markup;
96
97 m365_backend = E_MAIL_CONFIG_M365_BACKEND (backend);
98 page = e_mail_config_service_backend_get_page (backend);
99
100 /* This backend serves double duty. One instance holds the
101 * mail account source, another holds the mail transport source.
102 * We can differentiate by examining the EMailConfigServicePage
103 * the backend is associated with. This method only applies to
104 * the Receiving Page. */
105 if (!E_IS_MAIL_CONFIG_RECEIVING_PAGE (page))
106 return;
107
108 /* This needs to come _after_ the page type check so we don't
109 * introduce a backend extension in the mail transport source. */
110 settings = e_mail_config_service_backend_get_settings (backend);
111
112 text = _("Configuration");
113 markup = g_markup_printf_escaped ("<b>%s</b>", text);
114 widget = gtk_label_new (markup);
115 gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
116 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
117 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
118 gtk_widget_show (widget);
119 g_free (markup);
120
121 widget = gtk_grid_new ();
122 gtk_widget_set_margin_left (widget, 12);
123 gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
124 gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
125 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
126 gtk_widget_show (widget);
127
128 container = widget;
129
130 widget = gtk_label_new_with_mnemonic (_("User_name:"));
131 gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
132 gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
133 gtk_widget_show (widget);
134
135 label = GTK_LABEL (widget);
136
137 widget = gtk_entry_new ();
138 gtk_widget_set_hexpand (widget, TRUE);
139 gtk_label_set_mnemonic_widget (label, widget);
140 gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 2, 1);
141 m365_backend->priv->user_entry = widget; /* do not reference */
142 gtk_widget_show (widget);
143
144 widget = gtk_check_button_new_with_mnemonic (_("Open _Mailbox of other user"));
145 gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1);
146 gtk_widget_show (widget);
147
148 m365_settings = CAMEL_M365_SETTINGS (settings);
149
150 camel_m365_settings_lock (m365_settings);
151
152 if (camel_m365_settings_get_use_impersonation (m365_settings)) {
153 const gchar *impersonate_user = camel_m365_settings_get_impersonate_user (m365_settings);
154
155 if (impersonate_user && !*impersonate_user) {
156 camel_m365_settings_unlock (m365_settings);
157
158 camel_m365_settings_set_impersonate_user (m365_settings, NULL);
159 camel_m365_settings_set_use_impersonation (m365_settings, FALSE);
160
161 camel_m365_settings_lock (m365_settings);
162 }
163 }
164
165 camel_m365_settings_unlock (m365_settings);
166
167 e_binding_bind_property (
168 settings, "use-impersonation",
169 widget, "active",
170 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
171
172 widget = gtk_entry_new ();
173 gtk_widget_set_hexpand (widget, TRUE);
174 gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
175 gtk_widget_show (widget);
176 m365_backend->priv->impersonate_user_entry = widget; /* do not reference */
177
178 e_binding_bind_object_text_property (
179 settings, "impersonate-user",
180 widget, "text",
181 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
182
183 e_binding_bind_property (
184 settings, "use-impersonation",
185 widget, "sensitive",
186 G_BINDING_SYNC_CREATE);
187
188 text = _("Authentication");
189 markup = g_markup_printf_escaped ("<b>%s</b>", text);
190 widget = gtk_label_new (markup);
191 gtk_widget_set_margin_top (widget, 6);
192 gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
193 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
194 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
195 gtk_widget_show (widget);
196 g_free (markup);
197
198 widget = gtk_grid_new ();
199 gtk_widget_set_margin_left (widget, 12);
200 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
201 m365_backend->priv->oauth2_settings_grid = GTK_GRID (widget);
202
203 gtk_grid_set_column_spacing (m365_backend->priv->oauth2_settings_grid, 4);
204 gtk_grid_set_row_spacing (m365_backend->priv->oauth2_settings_grid, 4);
205
206 container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
207 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, container, 0, 0, 2, 1);
208
209 widget = gtk_check_button_new_with_mnemonic (_("_Override Microsoft 365 OAuth2 settings"));
210 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
211 m365_backend->priv->oauth2_override_check = widget;
212
213 markup = g_markup_printf_escaped ("(<a href=\"https://gitlab.gnome.org/GNOME/evolution/-/wikis/EWS-OAuth2\">%s</a>)", _("Help…"));
214 widget = gtk_label_new (markup);
215 gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
216 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
217 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
218 g_free (markup);
219
220 widget = gtk_label_new_with_mnemonic (_("Application I_D:"));
221 gtk_widget_set_margin_left (widget, 12);
222 gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
223 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 0, 1, 1, 1);
224 label = GTK_LABEL (widget);
225
226 e_binding_bind_property (
227 m365_backend->priv->oauth2_override_check, "active",
228 widget, "sensitive",
229 G_BINDING_SYNC_CREATE);
230
231 widget = gtk_entry_new ();
232 gtk_widget_set_hexpand (widget, TRUE);
233 gtk_label_set_mnemonic_widget (label, widget);
234 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 1, 1, 1, 1);
235 m365_backend->priv->oauth2_client_id_entry = widget;
236
237 e_binding_bind_property (
238 m365_backend->priv->oauth2_override_check, "active",
239 widget, "sensitive",
240 G_BINDING_SYNC_CREATE);
241
242 mail_config_m365_backend_set_oauth2_tooltip (widget, MICROSOFT365_CLIENT_ID,
243 _("There is not set any default application ID"),
244 g_strdup_printf (_("Default application ID is “%s”"), MICROSOFT365_CLIENT_ID));
245
246 /* Translators: 'Tenant ID' here means a term used by Microsoft to identify a company or organization in a Microsoft 365 world.
247 You probably do not want to translate it. More for example here: https://powerbi.microsoft.com/en-us/blog/what-is-a-tenant/ */
248 widget = gtk_label_new_with_mnemonic (_("_Tenant ID:"));
249 gtk_widget_set_margin_left (widget, 12);
250 gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
251 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 0, 2, 1, 1);
252 label = GTK_LABEL (widget);
253
254 e_binding_bind_property (
255 m365_backend->priv->oauth2_override_check, "active",
256 widget, "sensitive",
257 G_BINDING_SYNC_CREATE);
258
259 widget = gtk_entry_new ();
260 gtk_widget_set_hexpand (widget, TRUE);
261 gtk_label_set_mnemonic_widget (label, widget);
262 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 1, 2, 1, 1);
263 m365_backend->priv->oauth2_tenant_entry = widget;
264
265 e_binding_bind_property (
266 m365_backend->priv->oauth2_override_check, "active",
267 widget, "sensitive",
268 G_BINDING_SYNC_CREATE);
269
270 mail_config_m365_backend_set_oauth2_tooltip (widget, MICROSOFT365_TENANT,
271 /* Translators: 'Tenant' here means a term used by Microsoft to identify a company or organization in a Microsoft 365 world. Same for 'common', it's a default URL path.
272 You probably do not want to translate it. More for example here: https://powerbi.microsoft.com/en-us/blog/what-is-a-tenant/ */
273 _("Default tenant is “common“"),
274 /* Translators: 'Tenant' here means a term used by Microsoft to identify a company or organization in a Microsoft 365 world.
275 You probably do not want to translate it. More for example here: https://powerbi.microsoft.com/en-us/blog/what-is-a-tenant/ */
276 g_strdup_printf (_("Default tenant is “%s”"), MICROSOFT365_TENANT));
277
278 container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
279 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, container, 0, 3, 2, 1);
280
281 widget = gtk_expander_new_with_mnemonic (_("_Advanced Settings"));
282 gtk_widget_set_margin_left (widget, 12);
283 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
284 expander = widget;
285
286 e_binding_bind_property (
287 m365_backend->priv->oauth2_override_check, "active",
288 widget, "sensitive",
289 G_BINDING_SYNC_CREATE);
290
291 markup = g_markup_printf_escaped ("(<a href=\"https://gitlab.gnome.org/GNOME/evolution/-/wikis/EWS-OAuth2#alternative-endpoints\">%s</a>)", _("Help…"));
292 widget = gtk_label_new (markup);
293 gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
294 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
295 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
296 g_free (markup);
297 advanced_help = widget;
298
299 widget = gtk_label_new_with_mnemonic (_("_Endpoint host:"));
300 gtk_widget_set_margin_left (widget, 12);
301 gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
302 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 0, 4, 1, 1);
303 label = GTK_LABEL (widget);
304 endpoint_host_label = widget;
305
306 e_binding_bind_property (
307 m365_backend->priv->oauth2_override_check, "active",
308 widget, "sensitive",
309 G_BINDING_SYNC_CREATE);
310
311 widget = gtk_entry_new ();
312 gtk_widget_set_hexpand (widget, TRUE);
313 gtk_label_set_mnemonic_widget (label, widget);
314 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 1, 4, 1, 1);
315 m365_backend->priv->oauth2_endpoint_host_entry = widget;
316
317 e_binding_bind_property (
318 m365_backend->priv->oauth2_override_check, "active",
319 widget, "sensitive",
320 G_BINDING_SYNC_CREATE);
321
322 markup = g_strdup_printf (_("Default endpoint host is “%s”"), "login.microsoftonline.com");
323 mail_config_m365_backend_set_oauth2_tooltip (widget, OFFICE365_ENDPOINT_HOST,
324 markup,
325 g_strdup_printf (_("Default endpoint host is “%s”"), OFFICE365_ENDPOINT_HOST));
326 g_free (markup);
327
328 widget = gtk_label_new_with_mnemonic (_("_Redirect URI:"));
329 gtk_widget_set_margin_left (widget, 12);
330 gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
331 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 0, 5, 1, 1);
332 label = GTK_LABEL (widget);
333 redirect_uri_label = widget;
334
335 e_binding_bind_property (
336 m365_backend->priv->oauth2_override_check, "active",
337 widget, "sensitive",
338 G_BINDING_SYNC_CREATE);
339
340 widget = gtk_entry_new ();
341 gtk_widget_set_hexpand (widget, TRUE);
342 gtk_label_set_mnemonic_widget (label, widget);
343 gtk_grid_attach (m365_backend->priv->oauth2_settings_grid, widget, 1, 5, 1, 1);
344 m365_backend->priv->oauth2_redirect_uri_entry = widget;
345
346 e_binding_bind_property (
347 m365_backend->priv->oauth2_override_check, "active",
348 widget, "sensitive",
349 G_BINDING_SYNC_CREATE);
350
351 markup = g_strdup_printf (_("Default redirect URI is “%s”"), "https://login.microsoftonline.com/common/oauth2/nativeclient");
352 mail_config_m365_backend_set_oauth2_tooltip (widget, MICROSOFT365_REDIRECT_URI,
353 markup,
354 g_strdup_printf (_("Default redirect URI is “%s”"), MICROSOFT365_REDIRECT_URI));
355 g_free (markup);
356
357 gtk_widget_show_all (GTK_WIDGET (m365_backend->priv->oauth2_settings_grid));
358
359 camel_m365_settings_lock (m365_settings);
360
361 gtk_expander_set_expanded (GTK_EXPANDER (expander),
362 (e_util_strcmp0 (camel_m365_settings_get_oauth2_endpoint_host (m365_settings), NULL) != 0 &&
363 e_util_strcmp0 (camel_m365_settings_get_oauth2_endpoint_host (m365_settings), MICROSOFT365_ENDPOINT_HOST) != 0) ||
364 (e_util_strcmp0 (camel_m365_settings_get_oauth2_redirect_uri (m365_settings), NULL) != 0 &&
365 e_util_strcmp0 (camel_m365_settings_get_oauth2_redirect_uri (m365_settings), MICROSOFT365_REDIRECT_URI) != 0));
366
367 camel_m365_settings_unlock (m365_settings);
368
369 e_binding_bind_property (
370 expander, "expanded",
371 advanced_help, "visible",
372 G_BINDING_SYNC_CREATE);
373
374 e_binding_bind_property (
375 expander, "expanded",
376 endpoint_host_label, "visible",
377 G_BINDING_SYNC_CREATE);
378
379 e_binding_bind_property (
380 expander, "expanded",
381 m365_backend->priv->oauth2_endpoint_host_entry, "visible",
382 G_BINDING_SYNC_CREATE);
383
384 e_binding_bind_property (
385 expander, "expanded",
386 redirect_uri_label, "visible",
387 G_BINDING_SYNC_CREATE);
388
389 e_binding_bind_property (
390 expander, "expanded",
391 m365_backend->priv->oauth2_redirect_uri_entry, "visible",
392 G_BINDING_SYNC_CREATE);
393
394 e_binding_bind_object_text_property (
395 settings, "user",
396 m365_backend->priv->user_entry, "text",
397 G_BINDING_BIDIRECTIONAL |
398 G_BINDING_SYNC_CREATE);
399
400 e_binding_bind_property (
401 settings, "override-oauth2",
402 m365_backend->priv->oauth2_override_check, "active",
403 G_BINDING_BIDIRECTIONAL |
404 G_BINDING_SYNC_CREATE);
405
406 e_binding_bind_object_text_property (
407 settings, "oauth2-tenant",
408 m365_backend->priv->oauth2_tenant_entry, "text",
409 G_BINDING_BIDIRECTIONAL |
410 G_BINDING_SYNC_CREATE);
411
412 e_binding_bind_object_text_property (
413 settings, "oauth2-client-id",
414 m365_backend->priv->oauth2_client_id_entry, "text",
415 G_BINDING_BIDIRECTIONAL |
416 G_BINDING_SYNC_CREATE);
417
418 e_binding_bind_object_text_property (
419 settings, "oauth2-redirect-uri",
420 m365_backend->priv->oauth2_redirect_uri_entry, "text",
421 G_BINDING_BIDIRECTIONAL |
422 G_BINDING_SYNC_CREATE);
423
424 e_binding_bind_object_text_property (
425 settings, "oauth2-endpoint-host",
426 m365_backend->priv->oauth2_endpoint_host_entry, "text",
427 G_BINDING_BIDIRECTIONAL |
428 G_BINDING_SYNC_CREATE);
429
430 extension_name = E_SOURCE_EXTENSION_COLLECTION;
431 source = e_mail_config_service_backend_get_collection (backend);
432 extension = e_source_get_extension (source, extension_name);
433
434 /* The collection identity is the user name. */
435 e_binding_bind_property (
436 settings, "user",
437 extension, "identity",
438 G_BINDING_BIDIRECTIONAL |
439 G_BINDING_SYNC_CREATE);
440
441 auth_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
442 e_source_authentication_set_host (auth_extension, "graph.microsoft.com");
443 e_source_authentication_set_port (auth_extension, 442);
444 e_source_authentication_set_method (auth_extension, "Microsoft365");
445 }
446
447 static void
448 mail_config_m365_backend_setup_defaults (EMailConfigServiceBackend *backend)
449 {
450 CamelSettings *settings;
451 EMailConfigServicePage *page;
452 const gchar *email_address;
453
454 page = e_mail_config_service_backend_get_page (backend);
455
456 /* This backend serves double duty. One instance holds the
457 * mail account source, another holds the mail transport source.
458 * We can differentiate by examining the EMailConfigServicePage
459 * the backend is associated with. This method only applies to
460 * the Receiving Page. */
461 if (!E_IS_MAIL_CONFIG_RECEIVING_PAGE (page))
462 return;
463
464 /* This needs to come _after_ the page type check so we don't
465 * introduce a backend extension in the mail transport source. */
466 email_address = e_mail_config_service_page_get_email_address (page);
467 settings = e_mail_config_service_backend_get_settings (backend);
468
469 camel_m365_settings_set_email (CAMEL_M365_SETTINGS (settings), email_address);
470 camel_network_settings_set_user (CAMEL_NETWORK_SETTINGS (settings), email_address);
471 }
472
473 static gboolean
474 mail_config_m365_backend_auto_configure (EMailConfigServiceBackend *backend,
475 EConfigLookup *config_lookup,
476 gint *out_priority,
477 gboolean *out_is_complete)
478 {
479 return e_mail_config_service_backend_auto_configure_for_kind (backend, config_lookup,
480 E_CONFIG_LOOKUP_RESULT_COLLECTION, NULL,
481 e_mail_config_service_backend_get_collection (backend),
482 out_priority, out_is_complete);
483 }
484
485 static gboolean
486 mail_config_m365_backend_check_complete (EMailConfigServiceBackend *backend)
487 {
488 EMailConfigServicePage *page;
489 EMailConfigM365Backend *m365_backend;
490 CamelSettings *settings;
491 CamelNetworkSettings *network_settings;
492 const gchar *user;
493 gboolean correct, complete = TRUE;
494
495 m365_backend = E_MAIL_CONFIG_M365_BACKEND (backend);
496 page = e_mail_config_service_backend_get_page (backend);
497
498 /* This backend serves double duty. One instance holds the
499 * mail account source, another holds the mail transport source.
500 * We can differentiate by examining the EMailConfigServicePage
501 * the backend is associated with. This method only applies to
502 * the Receiving Page. */
503 if (!E_IS_MAIL_CONFIG_RECEIVING_PAGE (page))
504 return TRUE;
505
506 /* This needs to come _after_ the page type check so we don't
507 * introduce a backend extension in the mail transport source. */
508 settings = e_mail_config_service_backend_get_settings (backend);
509
510 network_settings = CAMEL_NETWORK_SETTINGS (settings);
511 user = camel_network_settings_get_user (network_settings);
512
513 correct = user != NULL && *user != '\0';
514 complete = complete && correct;
515
516 e_util_set_entry_issue_hint (m365_backend->priv->user_entry, correct ? NULL : _("User name cannot be empty"));
517
518 if (correct) {
519 CamelM365Settings *m365_settings = CAMEL_M365_SETTINGS (settings);
520 const gchar *client_id;
521
522 camel_m365_settings_lock (m365_settings);
523
524 if (camel_m365_settings_get_override_oauth2 (m365_settings)) {
525 client_id = camel_m365_settings_get_oauth2_client_id (m365_settings);
526 } else {
527 client_id = MICROSOFT365_CLIENT_ID;
528 }
529
530 correct = e_util_strcmp0 (client_id, NULL) != 0;
531 complete = complete && correct;
532
533 camel_m365_settings_unlock (m365_settings);
534
535 e_util_set_entry_issue_hint (m365_backend->priv->oauth2_client_id_entry, correct ? NULL : _("Application ID cannot be empty"));
536 }
537
538 return complete;
539 }
540
541 static void
542 mail_config_m365_backend_commit_changes (EMailConfigServiceBackend *backend)
543 {
544 CamelSettings *settings;
545 CamelM365Settings *m365_settings;
546 EMailConfigServicePage *page;
547 const gchar *email_address;
548
549 page = e_mail_config_service_backend_get_page (backend);
550
551 /* This backend serves double duty. One instance holds the
552 * mail account source, another holds the mail transport source.
553 * We can differentiate by examining the EMailConfigServicePage
554 * the backend is associated with. This method only applies to
555 * the Receiving Page. */
556 if (!E_IS_MAIL_CONFIG_RECEIVING_PAGE (page))
557 return;
558
559 /* This needs to come _after_ the page type check so we don't
560 * introduce a backend extension in the mail transport source. */
561 settings = e_mail_config_service_backend_get_settings (backend);
562
563 email_address = e_mail_config_service_page_get_email_address (page);
564 if (email_address != NULL) {
565 m365_settings = CAMEL_M365_SETTINGS (settings);
566 camel_m365_settings_set_email (m365_settings, email_address);
567 }
568 }
569
570 static void
571 e_mail_config_m365_backend_class_init (EMailConfigM365BackendClass *class)
572 {
573 EMailConfigServiceBackendClass *backend_class;
574
575 backend_class = E_MAIL_CONFIG_SERVICE_BACKEND_CLASS (class);
576 backend_class->backend_name = "microsoft365";
577 backend_class->new_collection = mail_config_m365_backend_new_collection;
578 backend_class->insert_widgets = mail_config_m365_backend_insert_widgets;
579 backend_class->setup_defaults = mail_config_m365_backend_setup_defaults;
580 backend_class->auto_configure = mail_config_m365_backend_auto_configure;
581 backend_class->check_complete = mail_config_m365_backend_check_complete;
582 backend_class->commit_changes = mail_config_m365_backend_commit_changes;
583 }
584
585 static void
586 e_mail_config_m365_backend_class_finalize (EMailConfigM365BackendClass *class)
587 {
588 }
589
590 static void
591 e_mail_config_m365_backend_init (EMailConfigM365Backend *backend)
592 {
593 backend->priv = e_mail_config_m365_backend_get_instance_private (backend);
594 }
595
596 void
597 e_mail_config_m365_backend_type_register (GTypeModule *type_module)
598 {
599 /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
600 * function, so we have to wrap it with a public function in
601 * order to register types from a separate compilation unit. */
602 e_mail_config_m365_backend_register_type (type_module);
603 }