No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-config-remote-accounts.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-config-remote-accounts.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-config-remote-accounts.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 #include <config.h>
20 #include <glib/gi18n-lib.h>
21
22 #include <camel/camel.h>
23 #include <libebackend/libebackend.h>
24
25 #include <misc/e-port-entry.h>
26
27 #include <mail/e-mail-config-auth-check.h>
28 #include <mail/e-mail-config-service-page.h>
29
30 /* Standard GObject macros */
31 #define E_TYPE_MAIL_CONFIG_REMOTE_BACKEND \
32 (e_mail_config_remote_backend_get_type ())
33 #define E_MAIL_CONFIG_REMOTE_BACKEND(obj) \
34 (G_TYPE_CHECK_INSTANCE_CAST \
35 ((obj), E_TYPE_MAIL_CONFIG_REMOTE_BACKEND, EMailConfigRemoteBackend))
36 #define E_MAIL_CONFIG_REMOTE_BACKEND_CLASS(cls) \
37 (G_TYPE_CHECK_CLASS_CAST \
38 ((cls), E_TYPE_MAIL_CONFIG_REMOTE_BACKEND, EMailConfigRemoteBackendClass))
39 #define E_IS_MAIL_CONFIG_REMOTE_BACKEND(obj) \
40 (G_TYPE_CHECK_INSTANCE_TYPE \
41 ((obj), E_TYPE_MAIL_CONFIG_REMOTE_BACKEND))
42 #define E_IS_MAIL_CONFIG_REMOTE_BACKEND_CLASS(cls) \
43 (G_TYPE_CHECK_CLASS_TYPE \
44 ((cls), E_TYPE_MAIL_CONFIG_REMOTE_BACKEND))
45 #define E_MAIL_CONFIG_REMOTE_BACKEND_GET_CLASS(obj) \
46 (G_TYPE_INSTANCE_GET_CLASS \
47 ((obj), E_TYPE_MAIL_CONFIG_REMOTE_BACKEND, EMailConfigRemoteBackendClass))
48
49 typedef struct _EMailConfigRemoteBackend EMailConfigRemoteBackend;
50 typedef struct _EMailConfigRemoteBackendClass EMailConfigRemoteBackendClass;
51
52 typedef EMailConfigRemoteBackend EMailConfigPopBackend;
53 typedef EMailConfigRemoteBackendClass EMailConfigPopBackendClass;
54
55 typedef EMailConfigRemoteBackend EMailConfigNntpBackend;
56 typedef EMailConfigRemoteBackendClass EMailConfigNntpBackendClass;
57
58 typedef EMailConfigRemoteBackend EMailConfigImapBackend;
59 typedef EMailConfigRemoteBackendClass EMailConfigImapBackendClass;
60
61 typedef EMailConfigRemoteBackend EMailConfigImapxBackend;
62 typedef EMailConfigRemoteBackendClass EMailConfigImapxBackendClass;
63
64 struct _EMailConfigRemoteBackend {
65 EMailConfigServiceBackend parent;
66
67 GtkWidget *host_entry; /* not referenced */
68 GtkWidget *port_entry; /* not referenced */
69 GtkWidget *user_entry; /* not referenced */
70 GtkWidget *security_combo_box; /* not referenced */
71 GtkWidget *auth_check; /* not referenced */
72 };
73
74 struct _EMailConfigRemoteBackendClass {
75 EMailConfigServiceBackendClass parent_class;
76 };
77
78 /* Forward Declarations */
79 void e_mail_config_remote_accounts_register_types
80 (GTypeModule *type_module);
81 GType e_mail_config_remote_backend_get_type
82 (void) G_GNUC_CONST;
83 GType e_mail_config_pop_backend_get_type
84 (void) G_GNUC_CONST;
85 GType e_mail_config_nntp_backend_get_type
86 (void) G_GNUC_CONST;
87 GType e_mail_config_imap_backend_get_type
88 (void) G_GNUC_CONST;
89 GType e_mail_config_imapx_backend_get_type
90 (void) G_GNUC_CONST;
91
92 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
93 EMailConfigRemoteBackend,
94 e_mail_config_remote_backend,
95 E_TYPE_MAIL_CONFIG_SERVICE_BACKEND,
96 G_TYPE_FLAG_ABSTRACT,
97 /* no custom code */)
98
99 G_DEFINE_DYNAMIC_TYPE (
100 EMailConfigPopBackend,
101 e_mail_config_pop_backend,
102 E_TYPE_MAIL_CONFIG_REMOTE_BACKEND)
103
104 G_DEFINE_DYNAMIC_TYPE (
105 EMailConfigNntpBackend,
106 e_mail_config_nntp_backend,
107 E_TYPE_MAIL_CONFIG_REMOTE_BACKEND)
108
109 G_DEFINE_DYNAMIC_TYPE (
110 EMailConfigImapBackend,
111 e_mail_config_imap_backend,
112 E_TYPE_MAIL_CONFIG_REMOTE_BACKEND)
113
114 G_DEFINE_DYNAMIC_TYPE (
115 EMailConfigImapxBackend,
116 e_mail_config_imapx_backend,
117 E_TYPE_MAIL_CONFIG_REMOTE_BACKEND)
118
119 static void
120 mail_config_remote_backend_insert_widgets (EMailConfigServiceBackend *backend,
121 GtkBox *parent)
122 {
123 EMailConfigRemoteBackend *remote_backend;
124 CamelProvider *provider;
125 CamelSettings *settings;
126 ESource *source;
127 ESourceBackend *extension;
128 EMailConfigServicePage *page;
129 EMailConfigServicePageClass *class;
130 GtkLabel *label;
131 GtkWidget *widget;
132 GtkWidget *container;
133 const gchar *backend_name;
134 const gchar *extension_name;
135 const gchar *text;
136 gchar *markup;
137
138 remote_backend = E_MAIL_CONFIG_REMOTE_BACKEND (backend);
139
140 page = e_mail_config_service_backend_get_page (backend);
141 source = e_mail_config_service_backend_get_source (backend);
142 settings = e_mail_config_service_backend_get_settings (backend);
143
144 class = E_MAIL_CONFIG_SERVICE_PAGE_GET_CLASS (page);
145 extension_name = class->extension_name;
146 extension = e_source_get_extension (source, extension_name);
147 backend_name = e_source_backend_get_backend_name (extension);
148
149 text = _("Configuration");
150 markup = g_markup_printf_escaped ("<b>%s</b>", text);
151 widget = gtk_label_new (markup);
152 gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
153 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
154 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
155 gtk_widget_show (widget);
156 g_free (markup);
157
158 widget = gtk_grid_new ();
159 gtk_widget_set_margin_left (widget, 12);
160 gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
161 gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
162 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
163 gtk_widget_show (widget);
164
165 container = widget;
166
167 widget = gtk_label_new_with_mnemonic (_("_Server:"));
168 gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
169 gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
170 gtk_widget_show (widget);
171
172 label = GTK_LABEL (widget);
173
174 widget = gtk_entry_new ();
175 gtk_widget_set_hexpand (widget, TRUE);
176 gtk_label_set_mnemonic_widget (label, widget);
177 gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 1, 1);
178 remote_backend->host_entry = widget; /* do not reference */
179 gtk_widget_show (widget);
180
181 widget = gtk_label_new_with_mnemonic (_("_Port:"));
182 gtk_grid_attach (GTK_GRID (container), widget, 2, 0, 1, 1);
183 gtk_widget_show (widget);
184
185 label = GTK_LABEL (widget);
186
187 widget = e_port_entry_new ();
188 gtk_label_set_mnemonic_widget (label, widget);
189 gtk_grid_attach (GTK_GRID (container), widget, 3, 0, 1, 1);
190 remote_backend->port_entry = widget; /* do not reference */
191 gtk_widget_show (widget);
192
193 widget = gtk_label_new_with_mnemonic (_("User_name:"));
194 gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
195 gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
196 gtk_widget_show (widget);
197
198 label = GTK_LABEL (widget);
199
200 widget = gtk_entry_new ();
201 gtk_widget_set_hexpand (widget, TRUE);
202 gtk_label_set_mnemonic_widget (label, widget);
203 gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 3, 1);
204 remote_backend->user_entry = widget; /* do not reference */
205 gtk_widget_show (widget);
206
207 text = _("Security");
208 markup = g_markup_printf_escaped ("<b>%s</b>", text);
209 widget = gtk_label_new (markup);
210 gtk_widget_set_margin_top (widget, 6);
211 gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
212 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
213 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
214 gtk_widget_show (widget);
215 g_free (markup);
216
217 widget = gtk_grid_new ();
218 gtk_widget_set_margin_left (widget, 12);
219 gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
220 gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
221 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
222 gtk_widget_show (widget);
223
224 container = widget;
225
226 widget = gtk_label_new_with_mnemonic (_("Encryption _method:"));
227 gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
228 gtk_widget_show (widget);
229
230 label = GTK_LABEL (widget);
231
232 /* The IDs correspond to the CamelNetworkSecurityMethod enum. */
233 widget = gtk_combo_box_text_new ();
234 gtk_combo_box_text_append (
235 GTK_COMBO_BOX_TEXT (widget),
236 "none",
237 _("No encryption"));
238 gtk_combo_box_text_append (
239 GTK_COMBO_BOX_TEXT (widget),
240 "starttls-on-standard-port",
241 _("STARTTLS after connecting"));
242 gtk_combo_box_text_append (
243 GTK_COMBO_BOX_TEXT (widget),
244 "ssl-on-alternate-port",
245 _("SSL on a dedicated port"));
246 gtk_label_set_mnemonic_widget (label, widget);
247 gtk_widget_set_halign (widget, GTK_ALIGN_START);
248 gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 1, 1);
249 remote_backend->security_combo_box = widget; /* do not reference */
250 gtk_widget_show (widget);
251
252 provider = camel_provider_get (backend_name, NULL);
253 if (provider != NULL && provider->port_entries != NULL)
254 e_port_entry_set_camel_entries (
255 E_PORT_ENTRY (remote_backend->port_entry),
256 provider->port_entries);
257
258 text = _("Authentication");
259 markup = g_markup_printf_escaped ("<b>%s</b>", text);
260 widget = gtk_label_new (markup);
261 gtk_widget_set_margin_top (widget, 6);
262 gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
263 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
264 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
265 gtk_widget_show (widget);
266 g_free (markup);
267
268 widget = e_mail_config_auth_check_new (backend);
269 gtk_widget_set_margin_left (widget, 12);
270 gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
271 remote_backend->auth_check = widget; /* do not reference */
272 gtk_widget_show (widget);
273
274 g_object_bind_property (
275 settings, "host",
276 remote_backend->host_entry, "text",
277 G_BINDING_BIDIRECTIONAL |
278 G_BINDING_SYNC_CREATE);
279
280 g_object_bind_property_full (
281 settings, "security-method",
282 remote_backend->security_combo_box, "active-id",
283 G_BINDING_BIDIRECTIONAL |
284 G_BINDING_SYNC_CREATE,
285 e_binding_transform_enum_value_to_nick,
286 e_binding_transform_enum_nick_to_value,
287 NULL, (GDestroyNotify) NULL);
288
289 g_object_bind_property (
290 settings, "port",
291 remote_backend->port_entry, "port",
292 G_BINDING_BIDIRECTIONAL |
293 G_BINDING_SYNC_CREATE);
294
295 g_object_bind_property (
296 settings, "security-method",
297 remote_backend->port_entry, "security-method",
298 G_BINDING_SYNC_CREATE);
299
300 g_object_bind_property (
301 settings, "user",
302 remote_backend->user_entry, "text",
303 G_BINDING_BIDIRECTIONAL |
304 G_BINDING_SYNC_CREATE);
305
306 /* Don't use G_BINDING_SYNC_CREATE here since the widget
307 * chooses its initial mechanism more intelligently than
308 * a simple property binding would. */
309 g_object_bind_property (
310 settings, "auth-mechanism",
311 remote_backend->auth_check, "active-mechanism",
312 G_BINDING_BIDIRECTIONAL);
313 }
314
315 static gboolean
316 mail_config_remote_backend_check_complete (EMailConfigServiceBackend *backend)
317 {
318 EMailConfigRemoteBackend *remote_backend;
319 CamelSettings *settings;
320 CamelNetworkSettings *network_settings;
321 CamelProvider *provider;
322 EPortEntry *port_entry;
323 const gchar *host;
324 const gchar *user;
325
326 remote_backend = E_MAIL_CONFIG_REMOTE_BACKEND (backend);
327
328 settings = e_mail_config_service_backend_get_settings (backend);
329 provider = e_mail_config_service_backend_get_provider (backend);
330
331 g_return_val_if_fail (provider != NULL, FALSE);
332
333 network_settings = CAMEL_NETWORK_SETTINGS (settings);
334 host = camel_network_settings_get_host (network_settings);
335 user = camel_network_settings_get_user (network_settings);
336
337 if (CAMEL_PROVIDER_NEEDS (provider, CAMEL_URL_PART_HOST) &&
338 (host == NULL || *host == '\0'))
339 return FALSE;
340
341 port_entry = E_PORT_ENTRY (remote_backend->port_entry);
342 if (CAMEL_PROVIDER_NEEDS (provider, CAMEL_URL_PART_PORT) &&
343 !e_port_entry_is_valid (port_entry))
344 return FALSE;
345
346 if (CAMEL_PROVIDER_NEEDS (provider, CAMEL_URL_PART_USER) &&
347 (user == NULL || *user == '\0'))
348 return FALSE;
349
350 return TRUE;
351 }
352
353 static void
354 mail_config_remote_backend_commit_changes (EMailConfigServiceBackend *backend)
355 {
356 /* All CamelNetworkSettings properties are already up-to-date,
357 * and these properties are bound to ESourceExtension properties,
358 * so nothing to do here. */
359 }
360
361 static void
362 e_mail_config_remote_backend_class_init (EMailConfigRemoteBackendClass *class)
363 {
364 EMailConfigServiceBackendClass *backend_class;
365
366 backend_class = E_MAIL_CONFIG_SERVICE_BACKEND_CLASS (class);
367 backend_class->insert_widgets = mail_config_remote_backend_insert_widgets;
368 backend_class->check_complete = mail_config_remote_backend_check_complete;
369 backend_class->commit_changes = mail_config_remote_backend_commit_changes;
370 }
371
372 static void
373 e_mail_config_remote_backend_class_finalize (EMailConfigRemoteBackendClass *class)
374 {
375 }
376
377 static void
378 e_mail_config_remote_backend_init (EMailConfigRemoteBackend *backend)
379 {
380 }
381
382 static gboolean
383 mail_config_pop_backend_auto_configure (EMailConfigServiceBackend *backend,
384 EMailAutoconfig *autoconfig)
385 {
386 ESource *source;
387
388 source = e_mail_config_service_backend_get_source (backend);
389
390 return e_mail_autoconfig_set_pop3_details (autoconfig, source);
391 }
392
393 static void
394 e_mail_config_pop_backend_class_init (EMailConfigRemoteBackendClass *class)
395 {
396 EMailConfigServiceBackendClass *backend_class;
397
398 backend_class = E_MAIL_CONFIG_SERVICE_BACKEND_CLASS (class);
399 backend_class->backend_name = "pop";
400 backend_class->auto_configure = mail_config_pop_backend_auto_configure;
401 }
402
403 static void
404 e_mail_config_pop_backend_class_finalize (EMailConfigRemoteBackendClass *class)
405 {
406 }
407
408 static void
409 e_mail_config_pop_backend_init (EMailConfigRemoteBackend *backend)
410 {
411 }
412
413 static void
414 e_mail_config_nntp_backend_class_init (EMailConfigRemoteBackendClass *class)
415 {
416 EMailConfigServiceBackendClass *backend_class;
417
418 backend_class = E_MAIL_CONFIG_SERVICE_BACKEND_CLASS (class);
419 backend_class->backend_name = "nntp";
420 }
421
422 static void
423 e_mail_config_nntp_backend_class_finalize (EMailConfigRemoteBackendClass *class)
424 {
425 }
426
427 static void
428 e_mail_config_nntp_backend_init (EMailConfigRemoteBackend *backend)
429 {
430 }
431
432 static gboolean
433 mail_config_imap_backend_auto_configure (EMailConfigServiceBackend *backend,
434 EMailAutoconfig *autoconfig)
435 {
436 ESource *source;
437
438 source = e_mail_config_service_backend_get_source (backend);
439
440 return e_mail_autoconfig_set_imap_details (autoconfig, source);
441 }
442
443 static void
444 e_mail_config_imap_backend_class_init (EMailConfigRemoteBackendClass *class)
445 {
446 EMailConfigServiceBackendClass *backend_class;
447
448 backend_class = E_MAIL_CONFIG_SERVICE_BACKEND_CLASS (class);
449 backend_class->backend_name = "imap";
450 backend_class->auto_configure = mail_config_imap_backend_auto_configure;
451 }
452
453 static void
454 e_mail_config_imap_backend_class_finalize (EMailConfigRemoteBackendClass *class)
455 {
456 }
457
458 static void
459 e_mail_config_imap_backend_init (EMailConfigRemoteBackend *backend)
460 {
461 }
462
463 static gboolean
464 mail_config_imapx_backend_auto_configure (EMailConfigServiceBackend *backend,
465 EMailAutoconfig *autoconfig)
466 {
467 ESource *source;
468
469 source = e_mail_config_service_backend_get_source (backend);
470
471 return e_mail_autoconfig_set_imap_details (autoconfig, source);
472 }
473
474 static void
475 e_mail_config_imapx_backend_class_init (EMailConfigRemoteBackendClass *class)
476 {
477 EMailConfigServiceBackendClass *backend_class;
478
479 backend_class = E_MAIL_CONFIG_SERVICE_BACKEND_CLASS (class);
480 backend_class->backend_name = "imapx";
481 backend_class->auto_configure = mail_config_imapx_backend_auto_configure;
482 }
483
484 static void
485 e_mail_config_imapx_backend_class_finalize (EMailConfigRemoteBackendClass *class)
486 {
487 }
488
489 static void
490 e_mail_config_imapx_backend_init (EMailConfigRemoteBackend *backend)
491 {
492 }
493
494 void
495 e_mail_config_remote_accounts_register_types (GTypeModule *type_module)
496 {
497 /* Abstract base type */
498 e_mail_config_remote_backend_register_type (type_module);
499
500 /* Concrete sub-types */
501 e_mail_config_pop_backend_register_type (type_module);
502 e_mail_config_nntp_backend_register_type (type_module);
503 e_mail_config_imap_backend_register_type (type_module);
504 e_mail_config_imapx_backend_register_type (type_module);
505 }