e-mail-shell-backend.c 21.1 KB
Newer Older
Matthew Barnes's avatar
Matthew Barnes committed
1
/*
2
 * e-mail-shell-backend.c
Matthew Barnes's avatar
Matthew Barnes committed
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * 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
15
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
Matthew Barnes's avatar
Matthew Barnes committed
16 17 18 19 20 21
 *
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

22 23
#include "e-mail-shell-backend.h"

Matthew Barnes's avatar
Matthew Barnes committed
24 25
#include <glib/gi18n.h>

26 27
#include "e-util/e-import.h"
#include "e-util/e-util.h"
Matthew Barnes's avatar
Matthew Barnes committed
28 29
#include "shell/e-shell.h"
#include "shell/e-shell-window.h"
30
#include "composer/e-msg-composer.h"
31
#include "widgets/misc/e-preferences-window.h"
32
#include "widgets/misc/e-web-view.h"
Matthew Barnes's avatar
Matthew Barnes committed
33

34
#include "e-mail-shell-settings.h"
35
#include "e-mail-shell-sidebar.h"
Matthew Barnes's avatar
Matthew Barnes committed
36 37
#include "e-mail-shell-view.h"

38
#include "e-mail-browser.h"
39
#include "e-mail-reader.h"
40
#include "e-mail-session.h"
41
#include "e-mail-store.h"
42
#include "em-account-editor.h"
43 44
#include "em-account-prefs.h"
#include "em-composer-prefs.h"
45 46
#include "em-composer-utils.h"
#include "em-folder-utils.h"
47 48
#include "em-format-hook.h"
#include "em-format-html-display.h"
49 50
#include "em-mailer-prefs.h"
#include "em-network-prefs.h"
51
#include "em-utils.h"
52
#include "mail-config.h"
53
#include "mail-ops.h"
54 55
#include "mail-send-recv.h"
#include "mail-vfolder.h"
56 57
#include "importers/mail-importer.h"

58 59 60 61 62
#define E_MAIL_SHELL_BACKEND_GET_PRIVATE(obj) \
	(G_TYPE_INSTANCE_GET_PRIVATE \
	((obj), E_TYPE_MAIL_SHELL_BACKEND, EMailShellBackendPrivate))

#define BACKEND_NAME "mail"
Matthew Barnes's avatar
Matthew Barnes committed
63

64 65
struct _EMailShellBackendPrivate {
	gint mail_sync_in_progress;
66
	guint mail_sync_source_id;
67 68 69
};

static gpointer parent_class;
70
static GType mail_shell_backend_type;
Matthew Barnes's avatar
Matthew Barnes committed
71

72 73 74
static void mbox_create_preview_cb (GObject *preview, GtkWidget **preview_widget);
static void mbox_fill_preview_cb (GObject *preview, CamelMimeMessage *msg);

75
static void
76
mail_shell_backend_init_importers (void)
77 78 79 80 81 82 83 84
{
	EImportClass *import_class;
	EImportImporter *importer;

	import_class = g_type_class_ref (e_import_get_type ());

	importer = mbox_importer_peek ();
	e_import_class_add_importer (import_class, importer, NULL, NULL);
85
	mbox_importer_set_preview_funcs (mbox_create_preview_cb, mbox_fill_preview_cb);
86 87 88 89 90 91 92 93 94

	importer = elm_importer_peek ();
	e_import_class_add_importer (import_class, importer, NULL, NULL);

	importer = pine_importer_peek ();
	e_import_class_add_importer (import_class, importer, NULL, NULL);
}

static void
95
mail_shell_backend_mail_icon_cb (EShellWindow *shell_window,
96
                                 const gchar *icon_name)
97 98 99 100
{
	GtkAction *action;

	action = e_shell_window_get_shell_view_action (
101
		shell_window, BACKEND_NAME);
Matthew Barnes's avatar
Matthew Barnes committed
102
	g_object_set (action, "icon-name", icon_name, NULL);
103 104
}

Matthew Barnes's avatar
Matthew Barnes committed
105 106 107 108
static void
action_mail_folder_new_cb (GtkAction *action,
                           EShellWindow *shell_window)
{
109 110 111 112 113 114 115 116
	EMFolderTree *folder_tree = NULL;
	EMailShellSidebar *mail_shell_sidebar;
	EShellSidebar *shell_sidebar;
	EShellView *shell_view;
	const gchar *view_name;

	/* Take care not to unnecessarily load the mail shell view. */
	view_name = e_shell_window_get_active_view (shell_window);
117
	if (g_strcmp0 (view_name, BACKEND_NAME) != 0)
118 119 120 121 122 123 124 125 126
		goto exit;

	shell_view = e_shell_window_get_shell_view (shell_window, view_name);
	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);

	mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar);
	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);

exit:
127 128
	em_folder_utils_create_folder (
		NULL, folder_tree, GTK_WINDOW (shell_window));
Matthew Barnes's avatar
Matthew Barnes committed
129 130 131 132 133 134
}

static void
action_mail_message_new_cb (GtkAction *action,
                            EShellWindow *shell_window)
{
135 136 137
	EMailShellSidebar *mail_shell_sidebar;
	EShellSidebar *shell_sidebar;
	EShellView *shell_view;
138
	EShell *shell;
139 140 141 142
	EMFolderTree *folder_tree;
	const gchar *view_name;
	gchar *uri = NULL;

143 144
	shell = e_shell_window_get_shell (shell_window);

145
	if (!em_utils_check_user_can_send_mail ())
146 147 148 149
		return;

	/* Take care not to unnecessarily load the mail shell view. */
	view_name = e_shell_window_get_active_view (shell_window);
150
	if (g_strcmp0 (view_name, BACKEND_NAME) != 0)
151 152 153 154 155 156 157 158 159 160
		goto exit;

	shell_view = e_shell_window_get_shell_view (shell_window, view_name);
	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);

	mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar);
	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
	uri = em_folder_tree_get_selected_uri (folder_tree);

exit:
161
	em_utils_compose_new_message (shell, uri);
162 163

	g_free (uri);
Matthew Barnes's avatar
Matthew Barnes committed
164 165 166 167 168 169
}

static GtkActionEntry item_entries[] = {

	{ "mail-message-new",
	  "mail-message-new",
170
	  NC_("New", "_Mail Message"),
Matthew Barnes's avatar
Matthew Barnes committed
171 172 173 174 175 176 177 178 179
	  "<Shift><Control>m",
	  N_("Compose a new mail message"),
	  G_CALLBACK (action_mail_message_new_cb) }
};

static GtkActionEntry source_entries[] = {

	{ "mail-folder-new",
	  "folder-new",
180
	  NC_("New", "Mail _Folder"),
Matthew Barnes's avatar
Matthew Barnes committed
181 182 183 184 185
	  NULL,
	  N_("Create a new mail folder"),
	  G_CALLBACK (action_mail_folder_new_cb) }
};

186
static void
187 188
mail_shell_backend_sync_store_done_cb (CamelStore *store,
                                       gpointer user_data)
189
{
190 191 192
	EMailShellBackend *mail_shell_backend = user_data;

	mail_shell_backend->priv->mail_sync_in_progress--;
193 194 195
}

static void
196
mail_shell_backend_sync_store_cb (CamelStore *store,
197
                                  const gchar *display_name,
198
                                  EMailShellBackend *mail_shell_backend)
199
{
200 201 202 203 204 205
	mail_shell_backend->priv->mail_sync_in_progress++;

	mail_sync_store (
		store, FALSE,
		mail_shell_backend_sync_store_done_cb,
		mail_shell_backend);
206 207 208
}

static gboolean
209
mail_shell_backend_mail_sync (EMailShellBackend *mail_shell_backend)
210
{
211 212
	EShell *shell;
	EShellBackend *shell_backend;
213

214 215 216 217 218
	shell_backend = E_SHELL_BACKEND (mail_shell_backend);
	shell = e_shell_backend_get_shell (shell_backend);

	/* Obviously we can only sync in online mode. */
	if (!e_shell_get_online (shell))
219 220
		goto exit;

221 222
	/* If a sync is still in progress, skip this round. */
	if (mail_shell_backend->priv->mail_sync_in_progress)
223 224
		goto exit;

225 226
	e_mail_store_foreach (
		(GHFunc) mail_shell_backend_sync_store_cb,
227
		mail_shell_backend);
228 229

exit:
230
	return TRUE;
231 232
}

233
static void
234 235 236
mail_shell_backend_handle_email_uri_cb (gchar *folder_uri,
                                        CamelFolder *folder,
                                        gpointer user_data)
237
{
238
	EShellBackend *shell_backend = user_data;
239
	EShellSettings *shell_settings;
240
	EMailBackend *backend;
241
	CamelURL *url = user_data;
242
	EShell *shell;
243 244 245 246
	const gchar *forward;
	const gchar *reply;
	const gchar *uid;

247
	backend = E_MAIL_BACKEND (shell_backend);
248
	shell = e_shell_backend_get_shell (shell_backend);
249
	shell_settings = e_shell_get_shell_settings (shell);
250

251
	if (folder == NULL) {
252
		g_warning ("Could not open folder '%s'", folder_uri);
253 254 255 256 257 258 259 260
		goto exit;
	}

	forward = camel_url_get_param (url, "forward");
	reply = camel_url_get_param (url, "reply");
	uid = camel_url_get_param (url, "uid");

	if (reply != NULL) {
261 262
		EMailReplyType reply_type;
		EMailReplyStyle reply_style;
263 264

		if (g_strcmp0 (reply, "all") == 0)
265
			reply_type = E_MAIL_REPLY_TO_ALL;
266
		else if (g_strcmp0 (reply, "list") == 0)
267
			reply_type = E_MAIL_REPLY_TO_LIST;
268
		else
269 270 271 272
			reply_type = E_MAIL_REPLY_TO_SENDER;

		reply_style = e_shell_settings_get_int (
			shell_settings, "mail-reply-style");
273

274
		em_utils_reply_to_message (
275 276
			shell, folder, uid, NULL,
			reply_type, reply_style, NULL);
277 278

	} else if (forward != NULL) {
279
		EMailForwardStyle forward_style;
280 281 282 283 284 285
		GPtrArray *uids;

		uids = g_ptr_array_new ();
		g_ptr_array_add (uids, g_strdup (uid));

		if (g_strcmp0 (forward, "attached") == 0)
286
			forward_style = E_MAIL_FORWARD_STYLE_ATTACHED;
287
		else if (g_strcmp0 (forward, "inline") == 0)
288
			forward_style = E_MAIL_FORWARD_STYLE_INLINE;
289
		else if (g_strcmp0 (forward, "quoted") == 0)
290
			forward_style = E_MAIL_FORWARD_STYLE_QUOTED;
291
		else
292 293 294 295 296
			forward_style = e_shell_settings_get_int (
				shell_settings, "mail-forward-style");

		em_utils_forward_messages (
			shell, folder, uids, folder_uri, forward_style);
297

298 299 300
	} else {
		GtkWidget *browser;

301
		/* FIXME Should pass in the shell module. */
302
		browser = e_mail_browser_new (backend);
303 304
		e_mail_reader_set_folder (
			E_MAIL_READER (browser), folder, folder_uri);
305
		e_mail_reader_set_message (E_MAIL_READER (browser), uid);
306 307
		gtk_widget_show (browser);
	}
308 309 310 311 312

exit:
	camel_url_free (url);
}

Matthew Barnes's avatar
Matthew Barnes committed
313
static gboolean
314 315 316
mail_shell_backend_handle_uri_cb (EShell *shell,
                                  const gchar *uri,
                                  EMailShellBackend *mail_shell_backend)
Matthew Barnes's avatar
Matthew Barnes committed
317
{
318 319
	EMailBackend *backend;
	EMailSession *session;
320 321
	gboolean handled = TRUE;

322 323 324
	backend = E_MAIL_BACKEND (mail_shell_backend);
	session = e_mail_backend_get_session (backend);

325
	if (g_str_has_prefix (uri, "mailto:")) {
326
		if (em_utils_check_user_can_send_mail ())
327 328
			em_utils_compose_new_message_with_mailto (
				shell, uri, NULL);
329 330 331 332 333 334 335 336 337

	} else if (g_str_has_prefix (uri, "email:")) {
		CamelURL *url;

		url = camel_url_new (uri, NULL);
		if (camel_url_get_param (url, "uid") != NULL) {
			gchar *curi = em_uri_to_camel (uri);

			mail_get_folder (
338
				session, curi, 0,
339 340
				mail_shell_backend_handle_email_uri_cb,
				mail_shell_backend, mail_msg_unordered_push);
341 342 343 344 345 346 347 348 349
			g_free (curi);

		} else {
			g_warning ("Email URI's must include a uid parameter");
			camel_url_free (url);
		}
	} else
		handled = FALSE;

350
	return handled;
Matthew Barnes's avatar
Matthew Barnes committed
351 352
}

353 354 355
static void
mail_shell_backend_prepare_for_quit_cb (EShell *shell,
                                        EActivity *activity,
356
                                        EShellBackend *shell_backend)
357
{
358
	EMailShellBackendPrivate *priv;
359

360
	priv = E_MAIL_SHELL_BACKEND_GET_PRIVATE (shell_backend);
361

362 363 364 365
	/* Prevent a sync from starting while trying to shutdown. */
	if (priv->mail_sync_source_id > 0) {
		g_source_remove (priv->mail_sync_source_id);
		priv->mail_sync_source_id = 0;
366
	}
367 368
}

Matthew Barnes's avatar
Matthew Barnes committed
369
static void
370
mail_shell_backend_window_weak_notify_cb (EShell *shell,
371
                                          GObject *where_the_object_was)
372 373
{
	g_signal_handlers_disconnect_by_func (
374
		shell, mail_shell_backend_mail_icon_cb,
375 376 377 378
		where_the_object_was);
}

static void
379
mail_shell_backend_window_created_cb (EShell *shell,
380 381
                                      GtkWindow *window,
                                      EShellBackend *shell_backend)
Matthew Barnes's avatar
Matthew Barnes committed
382
{
383
	const gchar *backend_name;
Matthew Barnes's avatar
Matthew Barnes committed
384

385 386
	/* This applies to both the composer and signature editor. */
	if (GTKHTML_IS_EDITOR (window)) {
387
		EShellSettings *shell_settings;
388
		GList *spell_languages;
389
		gboolean active = TRUE;
390 391 392 393 394

		spell_languages = e_load_spell_languages ();
		gtkhtml_editor_set_spell_languages (
			GTKHTML_EDITOR (window), spell_languages);
		g_list_free (spell_languages);
395 396 397 398 399 400 401 402 403

		shell_settings = e_shell_get_shell_settings (shell);

		/* Express mode does not honor this setting. */
		if (!e_shell_get_express_mode (shell))
			active = e_shell_settings_get_boolean (
				shell_settings, "composer-format-html");

		gtkhtml_editor_set_html_mode (GTKHTML_EDITOR (window), active);
404 405
	}

406 407 408 409 410 411 412 413 414
	if (E_IS_MSG_COMPOSER (window)) {
		/* Integrate the new composer into the mail module. */
		em_configure_new_composer (E_MSG_COMPOSER (window));
		return;
	}

	if (!E_IS_SHELL_WINDOW (window))
		return;

415
	backend_name = E_SHELL_BACKEND_GET_CLASS (shell_backend)->name;
Matthew Barnes's avatar
Matthew Barnes committed
416 417

	e_shell_window_register_new_item_actions (
418
		E_SHELL_WINDOW (window), backend_name,
Matthew Barnes's avatar
Matthew Barnes committed
419 420 421
		item_entries, G_N_ELEMENTS (item_entries));

	e_shell_window_register_new_source_actions (
422
		E_SHELL_WINDOW (window), backend_name,
Matthew Barnes's avatar
Matthew Barnes committed
423
		source_entries, G_N_ELEMENTS (source_entries));
424 425

	g_signal_connect_swapped (
Matthew Barnes's avatar
Matthew Barnes committed
426
		shell, "event::mail-icon",
427
		G_CALLBACK (mail_shell_backend_mail_icon_cb), window);
428 429

	g_object_weak_ref (
430
		G_OBJECT (window), (GWeakNotify)
431
		mail_shell_backend_window_weak_notify_cb, shell);
Matthew Barnes's avatar
Matthew Barnes committed
432 433
}

434 435
static void
mail_shell_backend_constructed (GObject *object)
Matthew Barnes's avatar
Matthew Barnes committed
436 437
{
	EShell *shell;
438
	EShellBackend *shell_backend;
439
	GtkWidget *preferences_window;
Matthew Barnes's avatar
Matthew Barnes committed
440

441 442
	shell_backend = E_SHELL_BACKEND (object);
	shell = e_shell_backend_get_shell (shell_backend);
Matthew Barnes's avatar
Matthew Barnes committed
443

444 445
	/* Chain up to parent's constructed() method. */
	G_OBJECT_CLASS (parent_class)->constructed (object);
446

447 448 449 450 451 452 453
	/* Register format types for EMFormatHook. */
	em_format_hook_register_type (em_format_get_type ());
	em_format_hook_register_type (em_format_html_get_type ());
	em_format_hook_register_type (em_format_html_display_get_type ());

	/* Register plugin hook types. */
	em_format_hook_get_type ();
454

455
	mail_shell_backend_init_importers ();
456

457
	g_signal_connect (
Matthew Barnes's avatar
Matthew Barnes committed
458
		shell, "handle-uri",
459 460
		G_CALLBACK (mail_shell_backend_handle_uri_cb),
		shell_backend);
Matthew Barnes's avatar
Matthew Barnes committed
461

462 463 464 465 466
	g_signal_connect (
		shell, "prepare-for-quit",
		G_CALLBACK (mail_shell_backend_prepare_for_quit_cb),
		shell_backend);

467
	g_signal_connect (
Matthew Barnes's avatar
Matthew Barnes committed
468
		shell, "window-created",
469 470
		G_CALLBACK (mail_shell_backend_window_created_cb),
		shell_backend);
471

472
	e_mail_shell_settings_init (shell_backend);
473

474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
	/* Setup preference widget factories */
	preferences_window = e_shell_get_preferences_window (shell);

	e_preferences_window_add_page (
		E_PREFERENCES_WINDOW (preferences_window),
		"mail-accounts",
		"preferences-mail-accounts",
		_("Mail Accounts"),
		em_account_prefs_new,
		100);

	e_preferences_window_add_page (
		E_PREFERENCES_WINDOW (preferences_window),
		"mail",
		"preferences-mail",
		_("Mail Preferences"),
		em_mailer_prefs_new,
		300);

	e_preferences_window_add_page (
		E_PREFERENCES_WINDOW (preferences_window),
		"composer",
		"preferences-composer",
		_("Composer Preferences"),
		em_composer_prefs_new,
		400);

	e_preferences_window_add_page (
		E_PREFERENCES_WINDOW (preferences_window),
		"system-network-proxy",
		"preferences-system-network-proxy",
		_("Network Preferences"),
		em_network_prefs_new,
		500);
508 509 510 511 512 513 514 515
}

static void
mail_shell_backend_start (EShellBackend *shell_backend)
{
	EMailShellBackendPrivate *priv;
	EShell *shell;
	EShellSettings *shell_settings;
516
	EMailBackend *backend;
517 518 519 520 521 522 523
	gboolean enable_search_folders;

	priv = E_MAIL_SHELL_BACKEND_GET_PRIVATE (shell_backend);

	shell = e_shell_backend_get_shell (shell_backend);
	shell_settings = e_shell_get_shell_settings (shell);

524 525
	backend = E_MAIL_BACKEND (shell_backend);

526 527 528
	enable_search_folders = e_shell_settings_get_boolean (
		shell_settings, "mail-enable-search-folders");
	if (enable_search_folders)
529
		vfolder_load_storage (backend);
530

531
	mail_autoreceive_init (backend);
532 533

	if (g_getenv ("CAMEL_FLUSH_CHANGES") != NULL)
534
		priv->mail_sync_source_id = g_timeout_add_seconds (
535 536 537 538 539
			mail_config_get_sync_timeout (),
			(GSourceFunc) mail_shell_backend_mail_sync,
			shell_backend);
}

540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
static gboolean
mail_shell_backend_delete_junk_policy_decision (EMailBackend *backend)
{
	EShell *shell;
	EShellSettings *shell_settings;
	GConfClient *client;
	const gchar *key;
	gboolean delete_junk;
	gint empty_date;
	gint empty_days;
	gint now;
	GError *error = NULL;

	shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend));

	client = e_shell_get_gconf_client (shell);
	shell_settings = e_shell_get_shell_settings (shell);

	now = time (NULL) / 60 / 60 / 24;

	delete_junk = e_shell_settings_get_boolean (
		shell_settings, "mail-empty-junk-on-exit");

	/* XXX No EShellSettings properties for these keys. */

	empty_date = empty_days = 0;

	if (delete_junk) {
		key = "/apps/evolution/mail/junk/empty_on_exit_days";
		empty_days = gconf_client_get_int (client, key, &error);
		if (error != NULL) {
			g_warning ("%s", error->message);
			g_error_free (error);
			return FALSE;
		}
	}

	if (delete_junk) {
		key = "/apps/evolution/mail/junk/empty_date";
		empty_date = gconf_client_get_int (client, key, &error);
		if (error != NULL) {
			g_warning ("%s", error->message);
			g_error_free (error);
			return FALSE;
		}
	}

	delete_junk &= (empty_days == 0) || (empty_date + empty_days <= now);

	if (delete_junk) {
		key = "/apps/evolution/mail/junk/empty_date";
		gconf_client_set_int (client, key, now, NULL);
	}

	return delete_junk;
}

static gboolean
mail_shell_backend_empty_trash_policy_decision (EMailBackend *backend)
{
	EShell *shell;
	EShellSettings *shell_settings;
	GConfClient *client;
	const gchar *key;
	gboolean empty_trash;
	gint empty_date;
	gint empty_days;
	gint now;
	GError *error = NULL;

	shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend));

	client = e_shell_get_gconf_client (shell);
	shell_settings = e_shell_get_shell_settings (shell);

	now = time (NULL) / 60 / 60 / 24;

	empty_trash = e_shell_settings_get_boolean (
		shell_settings, "mail-empty-trash-on-exit");

	/* XXX No EShellSettings properties for these keys. */

	empty_date = empty_days = 0;

	if (empty_trash) {
		key = "/apps/evolution/mail/trash/empty_on_exit_days";
		empty_days = gconf_client_get_int (client, key, &error);
		if (error != NULL) {
			g_warning ("%s", error->message);
			g_error_free (error);
			return FALSE;
		}
	}

	if (empty_trash) {
		key = "/apps/evolution/mail/trash/empty_date";
		empty_date = gconf_client_get_int (client, key, &error);
		if (error != NULL) {
			g_warning ("%s", error->message);
			g_error_free (error);
			return FALSE;
		}
	}

	empty_trash &= (empty_days == 0) || (empty_date + empty_days <= now);

	if (empty_trash) {
		key = "/apps/evolution/mail/trash/empty_date";
		gconf_client_set_int (client, key, now, NULL);
	}

	return empty_trash;
}

654 655 656 657 658
static void
mail_shell_backend_class_init (EMailShellBackendClass *class)
{
	GObjectClass *object_class;
	EShellBackendClass *shell_backend_class;
659
	EMailBackendClass *mail_backend_class;
660 661 662 663 664 665 666 667

	parent_class = g_type_class_peek_parent (class);
	g_type_class_add_private (class, sizeof (EMailShellBackendPrivate));

	object_class = G_OBJECT_CLASS (class);
	object_class->constructed = mail_shell_backend_constructed;

	shell_backend_class = E_SHELL_BACKEND_CLASS (class);
668
	shell_backend_class->shell_view_type = E_TYPE_MAIL_SHELL_VIEW;
669 670 671 672
	shell_backend_class->name = BACKEND_NAME;
	shell_backend_class->aliases = "";
	shell_backend_class->schemes = "mailto:email";
	shell_backend_class->sort_order = 200;
673
	shell_backend_class->preferences_page = "mail-accounts";
674
	shell_backend_class->start = mail_shell_backend_start;
675 676 677 678 679 680

	mail_backend_class = E_MAIL_BACKEND_CLASS (class);
	mail_backend_class->delete_junk_policy_decision =
		mail_shell_backend_delete_junk_policy_decision;
	mail_backend_class->empty_trash_policy_decision =
		mail_shell_backend_empty_trash_policy_decision;
681 682 683 684 685 686 687 688 689 690
}

static void
mail_shell_backend_init (EMailShellBackend *mail_shell_backend)
{
	mail_shell_backend->priv =
		E_MAIL_SHELL_BACKEND_GET_PRIVATE (mail_shell_backend);
}

GType
691
e_mail_shell_backend_get_type (void)
692
{
693
	return mail_shell_backend_type;
694 695 696
}

void
697
e_mail_shell_backend_register_type (GTypeModule *type_module)
698
{
699 700 701 702 703 704 705 706 707 708 709 710 711 712
	const GTypeInfo type_info = {
		sizeof (EMailShellBackendClass),
		(GBaseInitFunc) NULL,
		(GBaseFinalizeFunc) NULL,
		(GClassInitFunc) mail_shell_backend_class_init,
		(GClassFinalizeFunc) NULL,
		NULL,  /* class_data */
		sizeof (EMailShellBackend),
		0,     /* n_preallocs */
		(GInstanceInitFunc) mail_shell_backend_init,
		NULL   /* value_table */
	};

	mail_shell_backend_type = g_type_module_register_type (
713
		type_module, E_TYPE_MAIL_BACKEND,
714
		"EMailShellBackend", &type_info, 0);
Matthew Barnes's avatar
Matthew Barnes committed
715 716
}

717 718
/******************* Code below here belongs elsewhere. *******************/

719
#include "filter/e-filter-option.h"
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
#include "shell/e-shell-settings.h"
#include "mail/e-mail-label-list-store.h"

GSList *
e_mail_labels_get_filter_options (void)
{
	EShell *shell;
	EShellSettings *shell_settings;
	EMailLabelListStore *list_store;
	GtkTreeModel *model;
	GtkTreeIter iter;
	GSList *list = NULL;
	gboolean valid;

	shell = e_shell_get_default ();
	shell_settings = e_shell_get_shell_settings (shell);
	list_store = e_shell_settings_get_object (
		shell_settings, "mail-label-list-store");

	model = GTK_TREE_MODEL (list_store);
	valid = gtk_tree_model_get_iter_first (model, &iter);

	while (valid) {
		struct _filter_option *option;
		gchar *name, *tag;

		name = e_mail_label_list_store_get_name (list_store, &iter);
		tag = e_mail_label_list_store_get_tag (list_store, &iter);

749 750 751 752 753 754 755 756
		if (g_str_has_prefix (tag, "$Label")) {
			gchar *tmp = tag;

			tag = g_strdup (tag + 6);

			g_free (tmp);
		}

757 758 759
		option = g_new0 (struct _filter_option, 1);
		option->title = e_str_without_underscores (name);
		option->value = tag;  /* takes ownership */
760
		list = g_slist_prepend (list, option);
761 762 763 764 765 766 767 768

		g_free (name);

		valid = gtk_tree_model_iter_next (model, &iter);
	}

	g_object_unref (list_store);

769
	return g_slist_reverse (list);
770
}
771 772 773 774 775 776

/* utility functions for mbox importer */
static void
mbox_create_preview_cb (GObject *preview, GtkWidget **preview_widget)
{
	EMFormatHTMLDisplay *format;
777
	EWebView *web_view;
778 779 780 781 782

	g_return_if_fail (preview != NULL);
	g_return_if_fail (preview_widget != NULL);

	format = em_format_html_display_new ();
783 784 785 786 787
	g_object_set_data_full (
		preview, "mbox-imp-formatter", format, g_object_unref);
	web_view = em_format_html_get_web_view (EM_FORMAT_HTML (format));

	*preview_widget = GTK_WIDGET (web_view);
788 789 790 791 792 793 794 795 796 797 798 799 800
}

static void
mbox_fill_preview_cb (GObject *preview, CamelMimeMessage *msg)
{
	EMFormatHTMLDisplay *format;

	g_return_if_fail (preview != NULL);
	g_return_if_fail (msg != NULL);

	format = g_object_get_data (preview, "mbox-imp-formatter");
	g_return_if_fail (format != NULL);

801 802
	/* FIXME Not passing a GCancellable here. */
	em_format_format (EM_FORMAT (format), NULL, NULL, msg, NULL);
803
}