evolution-3.6.4/modules/mail-config/e-mail-config-smtp-backend.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-config-smtp-backend.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-config-smtp-backend.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-config-smtp-backend.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 "e-mail-config-smtp-backend.h"
 20 
 21 #include <config.h>
 22 #include <glib/gi18n-lib.h>
 23 
 24 #include <camel/camel.h>
 25 #include <libebackend/libebackend.h>
 26 
 27 #include <misc/e-port-entry.h>
 28 
 29 #include <mail/e-mail-config-auth-check.h>
 30 #include <mail/e-mail-config-service-page.h>
 31 
 32 #define E_MAIL_CONFIG_SMTP_BACKEND_GET_PRIVATE(obj) \
 33 	(G_TYPE_INSTANCE_GET_PRIVATE \
 34 	((obj), E_TYPE_MAIL_CONFIG_SMTP_BACKEND, EMailConfigSmtpBackendPrivate))
 35 
 36 struct _EMailConfigSmtpBackendPrivate {
 37 	GtkWidget *host_entry;			/* not referenced */
 38 	GtkWidget *port_entry;			/* not referenced */
 39 	GtkWidget *user_entry;			/* not referenced */
 40 	GtkWidget *security_combo_box;		/* not referenced */
 41 	GtkWidget *auth_required_toggle;	/* not referenced */
 42 	GtkWidget *auth_check;			/* not referenced */
 43 };
 44 
 45 G_DEFINE_DYNAMIC_TYPE (
 46 	EMailConfigSmtpBackend,
 47 	e_mail_config_smtp_backend,
 48 	E_TYPE_MAIL_CONFIG_SERVICE_BACKEND)
 49 
 50 static void
 51 mail_config_smtp_backend_insert_widgets (EMailConfigServiceBackend *backend,
 52                                          GtkBox *parent)
 53 {
 54 	EMailConfigSmtpBackendPrivate *priv;
 55 	CamelProvider *provider;
 56 	CamelSettings *settings;
 57 	ESource *source;
 58 	ESourceBackend *extension;
 59 	EMailConfigServicePage *page;
 60 	EMailConfigServicePageClass *class;
 61 	GtkLabel *label;
 62 	GtkWidget *widget;
 63 	GtkWidget *container;
 64 	const gchar *backend_name;
 65 	const gchar *extension_name;
 66 	const gchar *mechanism;
 67 	const gchar *text;
 68 	guint16 port;
 69 	gchar *markup;
 70 
 71 	priv = E_MAIL_CONFIG_SMTP_BACKEND_GET_PRIVATE (backend);
 72 
 73 	page = e_mail_config_service_backend_get_page (backend);
 74 	source = e_mail_config_service_backend_get_source (backend);
 75 	settings = e_mail_config_service_backend_get_settings (backend);
 76 
 77 	class = E_MAIL_CONFIG_SERVICE_PAGE_GET_CLASS (page);
 78 	extension_name = class->extension_name;
 79 	extension = e_source_get_extension (source, extension_name);
 80 	backend_name = e_source_backend_get_backend_name (extension);
 81 
 82 	text = _("Configuration");
 83 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
 84 	widget = gtk_label_new (markup);
 85 	gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
 86 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
 87 	gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
 88 	gtk_widget_show (widget);
 89 	g_free (markup);
 90 
 91 	widget = gtk_grid_new ();
 92 	gtk_widget_set_margin_left (widget, 12);
 93 	gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
 94 	gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
 95 	gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
 96 	gtk_widget_show (widget);
 97 
 98 	container = widget;
 99 
100 	widget = gtk_label_new_with_mnemonic (_("_Server:"));
101 	gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
102 	gtk_widget_show (widget);
103 
104 	label = GTK_LABEL (widget);
105 
106 	widget = gtk_entry_new ();
107 	gtk_widget_set_hexpand (widget, TRUE);
108 	gtk_label_set_mnemonic_widget (label, widget);
109 	gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 1, 1);
110 	priv->host_entry = widget;  /* do not reference */
111 	gtk_widget_show (widget);
112 
113 	widget = gtk_label_new_with_mnemonic (_("_Port:"));
114 	gtk_grid_attach (GTK_GRID (container), widget, 2, 0, 1, 1);
115 	gtk_widget_show (widget);
116 
117 	label = GTK_LABEL (widget);
118 
119 	widget = e_port_entry_new ();
120 	gtk_label_set_mnemonic_widget (label, widget);
121 	gtk_grid_attach (GTK_GRID (container), widget, 3, 0, 1, 1);
122 	priv->port_entry = widget;  /* do not reference */
123 	gtk_widget_show (widget);
124 
125 	text = _("Ser_ver requires authentication");
126 	widget = gtk_check_button_new_with_mnemonic (text);
127 	gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 3, 1);
128 	priv->auth_required_toggle = widget;  /* do not reference */
129 	gtk_widget_show (widget);
130 
131 	text = _("Security");
132 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
133 	widget = gtk_label_new (markup);
134 	gtk_widget_set_margin_top (widget, 6);
135 	gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
136 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
137 	gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
138 	gtk_widget_show (widget);
139 	g_free (markup);
140 
141 	widget = gtk_grid_new ();
142 	gtk_widget_set_margin_left (widget, 12);
143 	gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
144 	gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
145 	gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
146 	gtk_widget_show (widget);
147 
148 	container = widget;
149 
150 	widget = gtk_label_new_with_mnemonic (_("Encryption _method:"));
151 	gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
152 	gtk_widget_show (widget);
153 
154 	label = GTK_LABEL (widget);
155 
156 	/* The IDs correspond to the CamelNetworkSecurityMethod enum. */
157 	widget = gtk_combo_box_text_new ();
158 	gtk_combo_box_text_append (
159 		GTK_COMBO_BOX_TEXT (widget),
160 		"none",
161 		_("No encryption"));
162 	gtk_combo_box_text_append (
163 		GTK_COMBO_BOX_TEXT (widget),
164 		"starttls-on-standard-port",
165 		_("STARTTLS after connecting"));
166 	gtk_combo_box_text_append (
167 		GTK_COMBO_BOX_TEXT (widget),
168 		"ssl-on-alternate-port",
169 		_("SSL on a dedicated port"));
170 	gtk_label_set_mnemonic_widget (label, widget);
171 	gtk_widget_set_halign (widget, GTK_ALIGN_START);
172 	gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 1, 1);
173 	priv->security_combo_box = widget;  /* do not reference */
174 	gtk_widget_show (widget);
175 
176 	provider = camel_provider_get (backend_name, NULL);
177 	if (provider != NULL && provider->port_entries != NULL)
178 		e_port_entry_set_camel_entries (
179 			E_PORT_ENTRY (priv->port_entry),
180 			provider->port_entries);
181 
182 	text = _("Authentication");
183 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
184 	widget = gtk_label_new (markup);
185 	gtk_widget_set_margin_top (widget, 6);
186 	gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
187 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
188 	gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
189 	gtk_widget_show (widget);
190 	g_free (markup);
191 
192 	g_object_bind_property (
193 		priv->auth_required_toggle, "active",
194 		widget, "sensitive",
195 		G_BINDING_SYNC_CREATE);
196 
197 	widget = gtk_grid_new ();
198 	gtk_widget_set_margin_left (widget, 12);
199 	gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
200 	gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
201 	gtk_box_pack_start (GTK_BOX (parent), widget, FALSE, FALSE, 0);
202 	gtk_widget_show (widget);
203 
204 	g_object_bind_property (
205 		priv->auth_required_toggle, "active",
206 		widget, "sensitive",
207 		G_BINDING_SYNC_CREATE);
208 
209 	container = widget;
210 
211 	widget = gtk_label_new_with_mnemonic (_("T_ype:"));
212 	gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
213 	gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
214 	gtk_widget_show (widget);
215 
216 	label = GTK_LABEL (widget);
217 
218 	/* We can't bind GSettings:auth-mechanism directly to this
219 	 * because the toggle button above influences the value we
220 	 * choose: "none" if the toggle button is inactive or else
221 	 * the active mechanism name from this widget. */
222 	widget = e_mail_config_auth_check_new (backend);
223 	gtk_widget_set_hexpand (widget, TRUE);
224 	gtk_label_set_mnemonic_widget (label, widget);
225 	gtk_grid_attach (GTK_GRID (container), widget, 1, 0, 1, 1);
226 	priv->auth_check = widget;  /* do not reference */
227 	gtk_widget_show (widget);
228 
229 	widget = gtk_label_new_with_mnemonic (_("User_name:"));
230 	gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
231 	gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
232 	gtk_widget_show (widget);
233 
234 	label = GTK_LABEL (widget);
235 
236 	widget = gtk_entry_new ();
237 	gtk_widget_set_hexpand (widget, TRUE);
238 	gtk_label_set_mnemonic_widget (label, widget);
239 	gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 2, 1);
240 	priv->user_entry = widget;  /* do not reference */
241 	gtk_widget_show (widget);
242 
243 	port = 0;
244 	g_object_get (G_OBJECT (settings), "port", &port, NULL);
245 
246 	g_object_bind_property (
247 		settings, "host",
248 		priv->host_entry, "text",
249 		G_BINDING_BIDIRECTIONAL |
250 		G_BINDING_SYNC_CREATE);
251 
252 	g_object_bind_property_full (
253 		settings, "security-method",
254 		priv->security_combo_box, "active-id",
255 		G_BINDING_BIDIRECTIONAL |
256 		G_BINDING_SYNC_CREATE,
257 		e_binding_transform_enum_value_to_nick,
258 		e_binding_transform_enum_nick_to_value,
259 		NULL, (GDestroyNotify) NULL);
260 
261 	g_object_bind_property (
262 		settings, "port",
263 		priv->port_entry, "port",
264 		G_BINDING_BIDIRECTIONAL |
265 		G_BINDING_SYNC_CREATE);
266 
267 	g_object_bind_property (
268 		settings, "security-method",
269 		priv->port_entry, "security-method",
270 		G_BINDING_SYNC_CREATE);
271 
272 	g_object_bind_property (
273 		settings, "user",
274 		priv->user_entry, "text",
275 		G_BINDING_BIDIRECTIONAL |
276 		G_BINDING_SYNC_CREATE);
277 
278 	if (port != 0)
279 		g_object_set (G_OBJECT (priv->port_entry), "port", port, NULL);
280 
281 	/* Enable the auth-required toggle button if
282 	 * we have an authentication mechanism name. */
283 	mechanism = camel_network_settings_get_auth_mechanism (
284 		CAMEL_NETWORK_SETTINGS (settings));
285 	gtk_toggle_button_set_active (
286 		GTK_TOGGLE_BUTTON (priv->auth_required_toggle),
287 		(mechanism != NULL && *mechanism != '\0'));
288 }
289 
290 static gboolean
291 mail_config_smtp_backend_auto_configure (EMailConfigServiceBackend *backend,
292                                          EMailAutoconfig *autoconfig)
293 {
294 	ESource *source;
295 
296 	source = e_mail_config_service_backend_get_source (backend);
297 
298 	return e_mail_autoconfig_set_smtp_details (autoconfig, source);
299 }
300 
301 static gboolean
302 mail_config_smtp_backend_check_complete (EMailConfigServiceBackend *backend)
303 {
304 	EMailConfigSmtpBackendPrivate *priv;
305 	CamelSettings *settings;
306 	CamelNetworkSettings *network_settings;
307 	GtkToggleButton *toggle_button;
308 	EPortEntry *port_entry;
309 	const gchar *host;
310 	const gchar *user;
311 
312 	priv = E_MAIL_CONFIG_SMTP_BACKEND_GET_PRIVATE (backend);
313 
314 	settings = e_mail_config_service_backend_get_settings (backend);
315 
316 	network_settings = CAMEL_NETWORK_SETTINGS (settings);
317 	host = camel_network_settings_get_host (network_settings);
318 	user = camel_network_settings_get_user (network_settings);
319 
320 	if (host == NULL || *host == '\0')
321 		return FALSE;
322 
323 	port_entry = E_PORT_ENTRY (priv->port_entry);
324 
325 	if (!e_port_entry_is_valid (port_entry))
326 		return FALSE;
327 
328 	toggle_button = GTK_TOGGLE_BUTTON (priv->auth_required_toggle);
329 
330 	if (gtk_toggle_button_get_active (toggle_button))
331 		if (user == NULL || *user == '\0')
332 			return FALSE;
333 
334 	return TRUE;
335 }
336 
337 static void
338 mail_config_smtp_backend_commit_changes (EMailConfigServiceBackend *backend)
339 {
340 	EMailConfigSmtpBackendPrivate *priv;
341 	GtkToggleButton *toggle_button;
342 	CamelSettings *settings;
343 	const gchar *mechanism = NULL;
344 
345 	/* The authentication mechanism name depends on both the
346 	 * toggle button and the EMailConfigAuthCheck widget, so
347 	 * we have to set it manually here. */
348 
349 	priv = E_MAIL_CONFIG_SMTP_BACKEND_GET_PRIVATE (backend);
350 
351 	settings = e_mail_config_service_backend_get_settings (backend);
352 
353 	toggle_button = GTK_TOGGLE_BUTTON (priv->auth_required_toggle);
354 
355 	if (gtk_toggle_button_get_active (toggle_button))
356 		mechanism = e_mail_config_auth_check_get_active_mechanism (
357 			E_MAIL_CONFIG_AUTH_CHECK (priv->auth_check));
358 
359 	camel_network_settings_set_auth_mechanism (
360 		CAMEL_NETWORK_SETTINGS (settings), mechanism);
361 }
362 
363 static void
364 e_mail_config_smtp_backend_class_init (EMailConfigSmtpBackendClass *class)
365 {
366 	EMailConfigServiceBackendClass *backend_class;
367 
368 	g_type_class_add_private (
369 		class, sizeof (EMailConfigSmtpBackendPrivate));
370 
371 	backend_class = E_MAIL_CONFIG_SERVICE_BACKEND_CLASS (class);
372 	backend_class->backend_name = "smtp";
373 	backend_class->insert_widgets = mail_config_smtp_backend_insert_widgets;
374 	backend_class->auto_configure = mail_config_smtp_backend_auto_configure;
375 	backend_class->check_complete = mail_config_smtp_backend_check_complete;
376 	backend_class->commit_changes = mail_config_smtp_backend_commit_changes;
377 }
378 
379 static void
380 e_mail_config_smtp_backend_class_finalize (EMailConfigSmtpBackendClass *class)
381 {
382 }
383 
384 static void
385 e_mail_config_smtp_backend_init (EMailConfigSmtpBackend *backend)
386 {
387 	backend->priv = E_MAIL_CONFIG_SMTP_BACKEND_GET_PRIVATE (backend);
388 }
389 
390 void
391 e_mail_config_smtp_backend_type_register (GTypeModule *type_module)
392 {
393 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
394 	 *     function, so we have to wrap it with a public function in
395 	 *     order to register types from a separate compilation unit. */
396 	e_mail_config_smtp_backend_register_type (type_module);
397 }