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