evolution-3.6.4/mail/e-mail-ui-session.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-ui-session.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-ui-session.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-ui-session.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  * Authors:
 19  *   Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>
 20  *
 21  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 22  * Copyright (C) 2009 Intel Corporation
 23  *
 24  */
 25 
 26 /* mail-session.c: handles the session information and resource manipulation */
 27 
 28 #ifdef HAVE_CONFIG_H
 29 #include <config.h>
 30 #endif
 31 
 32 #include <errno.h>
 33 #include <stdlib.h>
 34 #include <string.h>
 35 
 36 #include <glib/gi18n.h>
 37 #include <glib/gstdio.h>
 38 
 39 #include <gtk/gtk.h>
 40 
 41 #ifdef HAVE_CANBERRA
 42 #include <canberra-gtk.h>
 43 #endif
 44 
 45 #include <libebackend/libebackend.h>
 46 #include <libedataserverui/libedataserverui.h>
 47 
 48 #include "e-mail-account-store.h"
 49 
 50 #include "e-util/e-util.h"
 51 #include "libevolution-utils/e-alert-dialog.h"
 52 #include "e-util/e-util-private.h"
 53 
 54 #include "shell/e-shell.h"
 55 #include "shell/e-shell-view.h"
 56 #include "shell/e-shell-content.h"
 57 #include "shell/e-shell-window.h"
 58 
 59 #include "libemail-engine/e-mail-folder-utils.h"
 60 #include "libemail-engine/e-mail-junk-filter.h"
 61 #include "libemail-engine/e-mail-session.h"
 62 #include "e-mail-ui-session.h"
 63 #include "em-composer-utils.h"
 64 #include "em-filter-context.h"
 65 #include "em-vfolder-editor-context.h"
 66 #include "em-filter-rule.h"
 67 #include "em-utils.h"
 68 #include "libemail-engine/mail-config.h"
 69 #include "libemail-utils/mail-mt.h"
 70 #include "libemail-engine/mail-ops.h"
 71 #include "mail-send-recv.h"
 72 #include "libemail-engine/mail-tools.h"
 73 
 74 #define E_MAIL_UI_SESSION_GET_PRIVATE(obj) \
 75 	(G_TYPE_INSTANCE_GET_PRIVATE \
 76 	((obj), E_TYPE_MAIL_UI_SESSION, EMailUISessionPrivate))
 77 
 78 typedef struct _SourceContext SourceContext;
 79 
 80 struct _EMailUISessionPrivate {
 81 	FILE *filter_logfile;
 82 	ESourceRegistry *registry;
 83 	EMailAccountStore *account_store;
 84 	EMailLabelListStore *label_store;
 85 };
 86 
 87 enum {
 88 	PROP_0,
 89 	PROP_ACCOUNT_STORE,
 90 	PROP_LABEL_STORE
 91 };
 92 
 93 enum {
 94 	ACTIVITY_ADDED,
 95 	LAST_SIGNAL
 96 };
 97 
 98 static guint signals[LAST_SIGNAL];
 99 
100 G_DEFINE_TYPE_WITH_CODE (
101 	EMailUISession,
102 	e_mail_ui_session,
103 	E_TYPE_MAIL_SESSION,
104 	G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
105 
106 struct _SourceContext {
107 	EMailUISession *session;
108 	CamelService *service;
109 };
110 
111 /* Support for CamelSession.alert_user() *************************************/
112 
113 static gpointer user_message_dialog;
114 static GQueue user_message_queue = { NULL, NULL, 0 };
115 
116 struct _user_message_msg {
117 	MailMsg base;
118 
119 	CamelSessionAlertType type;
120 	gchar *prompt;
121 	GSList *button_captions;
122 	EFlag *done;
123 
124 	gint result;
125 	guint ismain : 1;
126 };
127 
128 static void user_message_exec (struct _user_message_msg *m,
129                                GCancellable *cancellable,
130                                GError **error);
131 
132 static void
133 user_message_response_free (GtkDialog *dialog,
134                             gint button)
135 {
136 	struct _user_message_msg *m = NULL;
137 
138 	gtk_widget_destroy ((GtkWidget *) dialog);
139 
140 	user_message_dialog = NULL;
141 
142 	/* check for pendings */
143 	if (!g_queue_is_empty (&user_message_queue)) {
144 		GCancellable *cancellable;
145 
146 		m = g_queue_pop_head (&user_message_queue);
147 		cancellable = m->base.cancellable;
148 		user_message_exec (m, cancellable, &m->base.error);
149 		mail_msg_unref (m);
150 	}
151 }
152 
153 /* clicked, send back the reply */
154 static void
155 user_message_response (GtkDialog *dialog,
156                        gint button,
157                        struct _user_message_msg *m)
158 {
159 	/* if !m or !button_captions, then we've already replied */
160 	if (m && m->button_captions) {
161 		m->result = button;
162 		e_flag_set (m->done);
163 	}
164 
165 	user_message_response_free (dialog, button);
166 }
167 
168 static void
169 user_message_exec (struct _user_message_msg *m,
170                    GCancellable *cancellable,
171                    GError **error)
172 {
173 	gboolean info_only;
174 	GtkWindow *parent;
175 	EShell *shell;
176 	const gchar *error_type;
177 	gint index;
178 	GSList *iter;
179 
180 	info_only = g_slist_length (m->button_captions) <= 1;
181 
182 	if (!m->ismain && user_message_dialog != NULL && !info_only) {
183 		g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
184 		return;
185 	}
186 
187 	switch (m->type) {
188 		case CAMEL_SESSION_ALERT_INFO:
189 			error_type = "system:simple-info";
190 			break;
191 		case CAMEL_SESSION_ALERT_WARNING:
192 			error_type = "system:simple-warning";
193 			break;
194 		case CAMEL_SESSION_ALERT_ERROR:
195 			error_type = "system:simple-error";
196 			break;
197 		default:
198 			error_type = NULL;
199 			g_return_if_reached ();
200 	}
201 
202 	shell = e_shell_get_default ();
203 
204 	/* try to find "mail" view to place the informational alert to */
205 	if (info_only) {
206 		GtkWindow *active_window;
207 		EShellWindow *shell_window;
208 		EShellView *shell_view;
209 		EShellContent *shell_content = NULL;
210 
211 		/* check currently active window first, ... */
212 		active_window = e_shell_get_active_window (shell);
213 		if (active_window && E_IS_SHELL_WINDOW (active_window)) {
214 			if (E_IS_SHELL_WINDOW (active_window)) {
215 				shell_window = E_SHELL_WINDOW (active_window);
216 				shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
217 				if (shell_view)
218 					shell_content = e_shell_view_get_shell_content (shell_view);
219 			}
220 		}
221 
222 		if (!shell_content) {
223 			GList *list, *iter;
224 
225 			list = gtk_application_get_windows (GTK_APPLICATION (shell));
226 
227 			/* ...then iterate through all opened
228 			 * windows and pick one which has it */
229 			for (iter = list; iter != NULL && !shell_content; iter = g_list_next (iter)) {
230 				if (E_IS_SHELL_WINDOW (iter->data)) {
231 					shell_window = iter->data;
232 					shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
233 					if (shell_view)
234 						shell_content = e_shell_view_get_shell_content (shell_view);
235 				}
236 			}
237 		}
238 
239 		/* When no shell-content found, which might not happen,
240 		 * but just in case, process the information alert like
241 		 * usual, through an EAlertDialog machinery. */
242 		if (shell_content) {
243 			e_alert_submit (
244 				E_ALERT_SINK (shell_content),
245 				error_type, m->prompt, NULL);
246 			return;
247 		} else if (!m->ismain && user_message_dialog != NULL) {
248 			g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
249 			return;
250 		}
251 	}
252 
253 	/* Pull in the active window from the shell to get a parent window */
254 	parent = e_shell_get_active_window (shell);
255 	user_message_dialog = e_alert_dialog_new_for_args (
256 		parent, error_type, m->prompt, NULL);
257 	g_object_set (user_message_dialog, "resizable", TRUE, NULL);
258 
259 	if (m->button_captions) {
260 		GtkWidget *action_area;
261 		GList *children, *child;
262 
263 		/* remove all default buttons and keep only those requested */
264 		action_area = gtk_dialog_get_action_area (GTK_DIALOG (user_message_dialog));
265 
266 		children = gtk_container_get_children (GTK_CONTAINER (action_area));
267 		for (child = children; child != NULL; child = child->next) {
268 			gtk_container_remove (GTK_CONTAINER (action_area), child->data);
269 		}
270 
271 		g_list_free (children);
272 	}
273 
274 	for (index = 0, iter = m->button_captions; iter; index++, iter = iter->next) {
275 		gtk_dialog_add_button (GTK_DIALOG (user_message_dialog), iter->data, index);
276 	}
277 
278 	/* XXX This is a case where we need to be able to construct
279 	 *     custom EAlerts without a predefined XML definition. */
280 	if (m->ismain) {
281 		gint response;
282 
283 		response = gtk_dialog_run (user_message_dialog);
284 		user_message_response (
285 			user_message_dialog, response, m);
286 	} else {
287 		gpointer user_data = m;
288 
289 		if (g_slist_length (m->button_captions) <= 1)
290 			user_data = NULL;
291 
292 		g_signal_connect (
293 			user_message_dialog, "response",
294 			G_CALLBACK (user_message_response), user_data);
295 		gtk_widget_show (user_message_dialog);
296 	}
297 }
298 
299 static void
300 user_message_free (struct _user_message_msg *m)
301 {
302 	g_free (m->prompt);
303 	g_slist_free_full (m->button_captions, g_free);
304 	e_flag_free (m->done);
305 }
306 
307 static MailMsgInfo user_message_info = {
308 	sizeof (struct _user_message_msg),
309 	(MailMsgDescFunc) NULL,
310 	(MailMsgExecFunc) user_message_exec,
311 	(MailMsgDoneFunc) NULL,
312 	(MailMsgFreeFunc) user_message_free
313 };
314 
315 /* Support for CamelSession.get_filter_driver () *****************************/
316 
317 static CamelFolder *
318 get_folder (CamelFilterDriver *d,
319             const gchar *uri,
320             gpointer user_data,
321             GError **error)
322 {
323 	EMailSession *session = E_MAIL_SESSION (user_data);
324 
325 	/* FIXME Not passing a GCancellable here. */
326 	/* FIXME Need a camel_filter_driver_get_session(). */
327 	return e_mail_session_uri_to_folder_sync (
328 		session, uri, 0, NULL, error);
329 }
330 
331 static gboolean
332 session_play_sound_cb (const gchar *filename)
333 {
334 #ifdef HAVE_CANBERRA
335 	if (filename != NULL && *filename != '\0')
336 		ca_context_play (
337 			ca_gtk_context_get (), 0,
338 			CA_PROP_MEDIA_FILENAME, filename,
339 			NULL);
340 	else
341 #endif
342 		gdk_beep ();
343 
344 	return FALSE;
345 }
346 
347 static void
348 session_play_sound (CamelFilterDriver *driver,
349                     const gchar *filename,
350                     gpointer user_data)
351 {
352 	g_idle_add_full (
353 		G_PRIORITY_DEFAULT_IDLE,
354 		(GSourceFunc) session_play_sound_cb,
355 		g_strdup (filename), (GDestroyNotify) g_free);
356 }
357 
358 static void
359 session_system_beep (CamelFilterDriver *driver,
360                      gpointer user_data)
361 {
362 	g_idle_add ((GSourceFunc) session_play_sound_cb, NULL);
363 }
364 
365 static CamelFilterDriver *
366 main_get_filter_driver (CamelSession *session,
367                         const gchar *type,
368                         GError **error)
369 {
370 	EMailSession *ms = E_MAIL_SESSION (session);
371 	CamelFilterDriver *driver;
372 	EFilterRule *rule = NULL;
373 	const gchar *config_dir;
374 	gchar *user, *system;
375 	GSettings *settings;
376 	ERuleContext *fc;
377 	EMailUISessionPrivate *priv;
378 
379 	priv = E_MAIL_UI_SESSION_GET_PRIVATE (session);
380 
381 	settings = g_settings_new ("org.gnome.evolution.mail");
382 
383 	config_dir = mail_session_get_config_dir ();
384 	user = g_build_filename (config_dir, "filters.xml", NULL);
385 	system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL);
386 	fc = (ERuleContext *) em_filter_context_new (ms);
387 	e_rule_context_load (fc, system, user);
388 	g_free (system);
389 	g_free (user);
390 
391 	driver = camel_filter_driver_new (session);
392 	camel_filter_driver_set_folder_func (driver, get_folder, session);
393 
394 	if (g_settings_get_boolean (settings, "filters-log-actions")) {
395 		if (priv->filter_logfile == NULL) {
396 			gchar *filename;
397 
398 			filename = g_settings_get_string (settings, "filters-log-file");
399 			if (filename) {
400 				priv->filter_logfile = g_fopen (filename, "a+");
401 				g_free (filename);
402 			}
403 		}
404 
405 		if (priv->filter_logfile)
406 			camel_filter_driver_set_logfile (driver, priv->filter_logfile);
407 	}
408 
409 	camel_filter_driver_set_shell_func (driver, mail_execute_shell_command, NULL);
410 	camel_filter_driver_set_play_sound_func (driver, session_play_sound, NULL);
411 	camel_filter_driver_set_system_beep_func (driver, session_system_beep, NULL);
412 
413 	if ((!strcmp (type, E_FILTER_SOURCE_INCOMING) ||
414 		!strcmp (type, E_FILTER_SOURCE_JUNKTEST))
415 		&& camel_session_get_check_junk (session)) {
416 
417 		/* implicit junk check as 1st rule */
418 		camel_filter_driver_add_rule (
419 			driver, "Junk check", "(junk-test)",
420 			"(begin (set-system-flag \"junk\"))");
421 	}
422 
423 	if (strcmp (type, E_FILTER_SOURCE_JUNKTEST) != 0) {
424 		GString *fsearch, *faction;
425 
426 		fsearch = g_string_new ("");
427 		faction = g_string_new ("");
428 
429 		if (!strcmp (type, E_FILTER_SOURCE_DEMAND))
430 			type = E_FILTER_SOURCE_INCOMING;
431 
432 		/* add the user-defined rules next */
433 		while ((rule = e_rule_context_next_rule (fc, rule, type))) {
434 			g_string_truncate (fsearch, 0);
435 			g_string_truncate (faction, 0);
436 
437 			/* skip disabled rules */
438 			if (!rule->enabled)
439 				continue;
440 
441 			e_filter_rule_build_code (rule, fsearch);
442 			em_filter_rule_build_action (
443 				EM_FILTER_RULE (rule), faction);
444 			camel_filter_driver_add_rule (
445 				driver, rule->name,
446 				fsearch->str, faction->str);
447 		}
448 
449 		g_string_free (fsearch, TRUE);
450 		g_string_free (faction, TRUE);
451 	}
452 
453 	g_object_unref (fc);
454 
455 	g_object_unref (settings);
456 
457 	return driver;
458 }
459 
460 static void
461 source_context_free (SourceContext *context)
462 {
463 	if (context->session != NULL)
464 		g_object_unref (context->session);
465 
466 	if (context->service != NULL)
467 		g_object_unref (context->service);
468 
469 	g_slice_free (SourceContext, context);
470 }
471 
472 static gboolean
473 mail_ui_session_add_service_cb (SourceContext *context)
474 {
475 	EMailAccountStore *store;
476 
477 	/* The CamelService should be fully initialized by now. */
478 	store = e_mail_ui_session_get_account_store (context->session);
479 	e_mail_account_store_add_service (store, context->service);
480 
481 	return FALSE;
482 }
483 
484 static void
485 mail_ui_session_get_property (GObject *object,
486                               guint property_id,
487                               GValue *value,
488                               GParamSpec *pspec)
489 {
490 	switch (property_id) {
491 		case PROP_ACCOUNT_STORE:
492 			g_value_set_object (
493 				value,
494 				e_mail_ui_session_get_account_store (
495 				E_MAIL_UI_SESSION (object)));
496 			return;
497 
498 		case PROP_LABEL_STORE:
499 			g_value_set_object (
500 				value,
501 				e_mail_ui_session_get_label_store (
502 				E_MAIL_UI_SESSION (object)));
503 			return;
504 	}
505 
506 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
507 }
508 
509 static void
510 mail_ui_session_dispose (GObject *object)
511 {
512 	EMailUISessionPrivate *priv;
513 
514 	priv = E_MAIL_UI_SESSION_GET_PRIVATE (object);
515 
516 	if (priv->registry != NULL) {
517 		g_object_unref (priv->registry);
518 		priv->registry = NULL;
519 	}
520 
521 	if (priv->account_store != NULL) {
522 		e_mail_account_store_clear (priv->account_store);
523 		g_object_unref (priv->account_store);
524 		priv->account_store = NULL;
525 	}
526 
527 	if (priv->label_store != NULL) {
528 		g_object_unref (priv->label_store);
529 		priv->label_store = NULL;
530 	}
531 
532 	/* Chain up to parent's dispose() method. */
533 	G_OBJECT_CLASS (e_mail_ui_session_parent_class)->dispose (object);
534 }
535 
536 static void
537 mail_ui_session_constructed (GObject *object)
538 {
539 	EMailUISessionPrivate *priv;
540 	EMFolderTreeModel *folder_tree_model;
541 	ESourceRegistry *registry;
542 	EMailSession *session;
543 	EShell *shell;
544 
545 	session = E_MAIL_SESSION (object);
546 	shell = e_shell_get_default ();
547 
548 	/* synchronize online state first, before any CamelService is created */
549 	g_object_bind_property (
550 		shell, "online",
551 		session, "online",
552 		G_BINDING_SYNC_CREATE);
553 
554 	priv = E_MAIL_UI_SESSION_GET_PRIVATE (object);
555 	priv->account_store = e_mail_account_store_new (session);
556 
557 	/* Keep our own reference to the ESourceRegistry so we
558 	 * can easily disconnect signal handlers in dispose(). */
559 	registry = e_mail_session_get_registry (session);
560 	priv->registry = g_object_ref (registry);
561 
562 	/* XXX Make sure the folder tree model is created before we
563 	 *     add built-in CamelStores so it gets signals from the
564 	 *     EMailAccountStore.
565 	 *
566 	 * XXX This is creating a circular reference.  Perhaps the
567 	 *     model should only hold a weak pointer to EMailSession?
568 	 *
569 	 * FIXME EMailSession should just own the default instance.
570 	 */
571 	folder_tree_model = em_folder_tree_model_get_default ();
572 	em_folder_tree_model_set_session (folder_tree_model, session);
573 
574 	/* Chain up to parent's constructed() method. */
575 	G_OBJECT_CLASS (e_mail_ui_session_parent_class)->constructed (object);
576 }
577 
578 static CamelService *
579 mail_ui_session_add_service (CamelSession *session,
580                              const gchar *uid,
581                              const gchar *protocol,
582                              CamelProviderType type,
583                              GError **error)
584 {
585 	CamelService *service;
586 
587 	/* Chain up to parent's constructed() method. */
588 	service = CAMEL_SESSION_CLASS (e_mail_ui_session_parent_class)->
589 		add_service (session, uid, protocol, type, error);
590 
591 	/* Inform the EMailAccountStore of the new CamelService
592 	 * from an idle callback so the service has a chance to
593 	 * fully initialize first. */
594 	if (CAMEL_IS_STORE (service)) {
595 		SourceContext *context;
596 
597 		context = g_slice_new0 (SourceContext);
598 		context->session = g_object_ref (session);
599 		context->service = g_object_ref (service);
600 
601 		/* Prioritize ahead of GTK+ redraws. */
602 		g_idle_add_full (
603 			G_PRIORITY_HIGH_IDLE,
604 			(GSourceFunc) mail_ui_session_add_service_cb,
605 			context, (GDestroyNotify) source_context_free);
606 	}
607 
608 	return service;
609 }
610 
611 static void
612 mail_ui_session_remove_service (CamelSession *session,
613                                 CamelService *service)
614 {
615 	EMailAccountStore *store;
616 	EMailUISession *ui_session;
617 
618 	/* Passing a NULL parent window skips confirmation prompts. */
619 	ui_session = E_MAIL_UI_SESSION (session);
620 	store = e_mail_ui_session_get_account_store (ui_session);
621 	e_mail_account_store_remove_service (store, NULL, service);
622 }
623 
624 gint
625 e_mail_ui_session_alert_user (CamelSession *session,
626                               CamelSessionAlertType type,
627                               const gchar *prompt,
628                               GSList *button_captions)
629 {
630 	struct _user_message_msg *m;
631 	GCancellable *cancellable;
632 	gint result = -1;
633 	GSList *iter;
634 
635 	m = mail_msg_new (&user_message_info);
636 	m->ismain = mail_in_main_thread ();
637 	m->type = type;
638 	m->prompt = g_strdup (prompt);
639 	m->done = e_flag_new ();
640 	m->button_captions = g_slist_copy (button_captions);
641 
642 	for (iter = m->button_captions; iter; iter = iter->next)
643 		iter->data = g_strdup (iter->data);
644 
645 	if (g_slist_length (button_captions) > 1)
646 		mail_msg_ref (m);
647 
648 	cancellable = m->base.cancellable;
649 
650 	if (m->ismain)
651 		user_message_exec (m, cancellable, &m->base.error);
652 	else
653 		mail_msg_main_loop_push (m);
654 
655 	if (g_slist_length (button_captions) > 1) {
656 		e_flag_wait (m->done);
657 		result = m->result;
658 		mail_msg_unref (m);
659 	} else if (m->ismain)
660 		mail_msg_unref (m);
661 
662 	return result;
663 }
664 
665 static CamelFilterDriver *
666 mail_ui_session_get_filter_driver (CamelSession *session,
667                                    const gchar *type,
668                                    GError **error)
669 {
670 	return (CamelFilterDriver *) mail_call_main (
671 		MAIL_CALL_p_ppp, (MailMainFunc) main_get_filter_driver,
672 		session, type, error);
673 }
674 
675 static void
676 mail_ui_session_refresh_service (EMailSession *session,
677                                  CamelService *service)
678 {
679 	if (camel_session_get_online (CAMEL_SESSION (session)))
680 		mail_receive_service (service);
681 }
682 
683 static EMVFolderContext *
684 mail_ui_session_create_vfolder_context (EMailSession *session)
685 {
686 	return (EMVFolderContext *) em_vfolder_editor_context_new (session);
687 }
688 
689 static void
690 e_mail_ui_session_class_init (EMailUISessionClass *class)
691 {
692 	GObjectClass *object_class;
693 	CamelSessionClass *session_class;
694 	EMailSessionClass *mail_session_class;
695 
696 	g_type_class_add_private (class, sizeof (EMailUISessionPrivate));
697 
698 	object_class = G_OBJECT_CLASS (class);
699 	object_class->get_property = mail_ui_session_get_property;
700 	object_class->dispose = mail_ui_session_dispose;
701 	object_class->constructed = mail_ui_session_constructed;
702 
703 	session_class = CAMEL_SESSION_CLASS (class);
704 	session_class->add_service = mail_ui_session_add_service;
705 	session_class->remove_service = mail_ui_session_remove_service;
706 	session_class->alert_user = e_mail_ui_session_alert_user;
707 	session_class->get_filter_driver = mail_ui_session_get_filter_driver;
708 
709 	mail_session_class = E_MAIL_SESSION_CLASS (class);
710 	mail_session_class->create_vfolder_context = mail_ui_session_create_vfolder_context;
711 	mail_session_class->refresh_service = mail_ui_session_refresh_service;
712 
713 	g_object_class_install_property (
714 		object_class,
715 		PROP_LABEL_STORE,
716 		g_param_spec_object (
717 			"label-store",
718 			"Label Store",
719 			"Mail label store",
720 			E_TYPE_MAIL_LABEL_LIST_STORE,
721 			G_PARAM_READABLE |
722 			G_PARAM_STATIC_STRINGS));
723 
724 	signals[ACTIVITY_ADDED] = g_signal_new (
725 		"activity-added",
726 		G_OBJECT_CLASS_TYPE (class),
727 		G_SIGNAL_RUN_LAST,
728 		G_STRUCT_OFFSET (EMailUISessionClass, activity_added),
729 		NULL, NULL,
730 		g_cclosure_marshal_VOID__OBJECT,
731 		G_TYPE_NONE, 1,
732 		E_TYPE_ACTIVITY);
733 }
734 
735 static void
736 e_mail_ui_session_init (EMailUISession *session)
737 {
738 	session->priv = E_MAIL_UI_SESSION_GET_PRIVATE (session);
739 	session->priv->label_store = e_mail_label_list_store_new ();
740 }
741 
742 EMailSession *
743 e_mail_ui_session_new (ESourceRegistry *registry)
744 {
745 	const gchar *user_data_dir;
746 	const gchar *user_cache_dir;
747 
748 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
749 
750 	user_data_dir = mail_session_get_data_dir ();
751 	user_cache_dir = mail_session_get_cache_dir ();
752 
753 	return g_object_new (
754 		E_TYPE_MAIL_UI_SESSION,
755 		"registry", registry,
756 		"user-data-dir", user_data_dir,
757 		"user-cache-dir", user_cache_dir,
758 		NULL);
759 }
760 
761 EMailAccountStore *
762 e_mail_ui_session_get_account_store (EMailUISession *session)
763 {
764 	g_return_val_if_fail (E_IS_MAIL_UI_SESSION (session), NULL);
765 
766 	return session->priv->account_store;
767 }
768 
769 EMailLabelListStore *
770 e_mail_ui_session_get_label_store (EMailUISession *session)
771 {
772 	g_return_val_if_fail (E_IS_MAIL_UI_SESSION (session), NULL);
773 
774 	return session->priv->label_store;
775 }
776 
777 void
778 e_mail_ui_session_add_activity (EMailUISession *session,
779                                 EActivity *activity)
780 {
781 	g_return_if_fail (E_IS_MAIL_UI_SESSION (session));
782 	g_return_if_fail (E_IS_ACTIVITY (activity));
783 
784 	g_signal_emit (session, signals[ACTIVITY_ADDED], 0, activity);
785 }