Blame SOURCES/evolution-3.12.11-initial-setup-mail-remote-folders.patch

7d1446
diff -up evolution-3.12.11/libemail-engine/e-mail-store-utils.c.initial-setup-mail-remote-folders evolution-3.12.11/libemail-engine/e-mail-store-utils.c
7d1446
--- evolution-3.12.11/libemail-engine/e-mail-store-utils.c.initial-setup-mail-remote-folders	2014-03-24 10:25:23.000000000 +0100
7d1446
+++ evolution-3.12.11/libemail-engine/e-mail-store-utils.c	2016-03-21 13:36:48.176689316 +0100
7d1446
@@ -19,6 +19,7 @@
7d1446
 #include <config.h>
7d1446
 #endif
7d1446
 
7d1446
+#include "e-mail-folder-utils.h"
7d1446
 #include "e-mail-utils.h"
7d1446
 
7d1446
 #include "e-mail-store-utils.h"
7d1446
@@ -402,3 +403,152 @@ e_mail_store_prepare_for_offline_finish
7d1446
 	/* Assume success unless a GError is set. */
7d1446
 	return !g_simple_async_result_propagate_error (simple, error);
7d1446
 }
7d1446
+
7d1446
+static gboolean
7d1446
+mail_store_save_setup_key (CamelStore *store,
7d1446
+			   ESource *source,
7d1446
+			   const gchar *extension_name,
7d1446
+			   const gchar *property_name,
7d1446
+			   const gchar *type_id,
7d1446
+			   const gchar *value)
7d1446
+{
7d1446
+	gpointer extension;
7d1446
+	GObjectClass *klass;
7d1446
+
7d1446
+	g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
7d1446
+	if (source)
7d1446
+		g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
7d1446
+	g_return_val_if_fail (extension_name != NULL, FALSE);
7d1446
+	g_return_val_if_fail (property_name != NULL, FALSE);
7d1446
+	g_return_val_if_fail (value != NULL, FALSE);
7d1446
+
7d1446
+	if (!source)
7d1446
+		return FALSE;
7d1446
+
7d1446
+	extension = e_source_get_extension (source, extension_name);
7d1446
+	if (!extension) {
7d1446
+		g_warning ("%s: Cannot find extension '%s'", G_STRFUNC, extension_name);
7d1446
+		return FALSE;
7d1446
+	}
7d1446
+
7d1446
+	klass = G_OBJECT_GET_CLASS (extension);
7d1446
+	g_return_val_if_fail (klass != NULL, FALSE);
7d1446
+
7d1446
+	if (!g_object_class_find_property (klass, property_name)) {
7d1446
+		g_warning ("%s: Extension '%s' doesn't have property '%s'", G_STRFUNC, extension_name, property_name);
7d1446
+		return FALSE;
7d1446
+	}
7d1446
+
7d1446
+	if (!type_id || g_str_equal (type_id, "s")) {
7d1446
+		g_object_set (extension, property_name, value, NULL);
7d1446
+	} else if (g_str_equal (type_id, "b")) {
7d1446
+		gboolean val;
7d1446
+
7d1446
+		val = g_strcmp0 (value, "false") != 0 && g_strcmp0 (value, "0") != 0;
7d1446
+
7d1446
+		g_object_set (extension, property_name, val, NULL);
7d1446
+	} else if (g_str_equal (type_id, "i")) {
7d1446
+		gint val;
7d1446
+
7d1446
+		val = (gint) g_ascii_strtoll (value, NULL, 10);
7d1446
+
7d1446
+		g_object_set (extension, property_name, val, NULL);
7d1446
+	} else if (g_str_equal (type_id, "f")) {
7d1446
+		gchar *folder_uri;
7d1446
+
7d1446
+		folder_uri = e_mail_folder_uri_build (store, value);
7d1446
+		g_object_set (extension, property_name, folder_uri, NULL);
7d1446
+		g_free (folder_uri);
7d1446
+	} else {
7d1446
+		g_warning ("%s: Unknown type identifier '%s' provided", G_STRFUNC, type_id);
7d1446
+		return FALSE;
7d1446
+	}
7d1446
+
7d1446
+	return TRUE;
7d1446
+}
7d1446
+
7d1446
+gboolean
7d1446
+e_mail_store_save_initial_setup_sync (CamelStore *store,
7d1446
+				      GHashTable *save_setup,
7d1446
+				      ESource *collection_source,
7d1446
+				      ESource *account_source,
7d1446
+				      ESource *submission_source,
7d1446
+				      ESource *transport_source,
7d1446
+				      gboolean write_sources,
7d1446
+				      GCancellable *cancellable,
7d1446
+				      GError **error)
7d1446
+{
7d1446
+	gboolean collection_changed = FALSE;
7d1446
+	gboolean account_changed = FALSE;
7d1446
+	gboolean submission_changed = FALSE;
7d1446
+	gboolean transport_changed = FALSE;
7d1446
+	gboolean success = TRUE;
7d1446
+	GHashTableIter iter;
7d1446
+	gpointer key, value;
7d1446
+
7d1446
+	g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
7d1446
+	g_return_val_if_fail (save_setup != NULL, FALSE);
7d1446
+	g_return_val_if_fail (E_IS_SOURCE (account_source), FALSE);
7d1446
+
7d1446
+	if (!g_hash_table_size (save_setup))
7d1446
+		return TRUE;
7d1446
+
7d1446
+	/* The key name consists of up to four parts: Source:Extension:Property[:Type]
7d1446
+	   Source can be 'Collection', 'Account', 'Submission', 'Transport', 'Backend'
7d1446
+	   Extension is any extension name; it's up to the key creator to make sure
7d1446
+	   the extension belongs to that particular Source.
7d1446
+	   Property is a property name in the Extension.
7d1446
+	   Type is an optional letter describing the type of the value; if not set, then
7d1446
+	   string is used. Available values are: 'b' for boolean, 'i' for integer,
7d1446
+	   's' for string, 'f' for folder full path.
7d1446
+	   All the part values are case sensitive.
7d1446
+	*/
7d1446
+
7d1446
+	g_hash_table_iter_init (&iter, save_setup);
7d1446
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
7d1446
+		gchar **keys;
7d1446
+
7d1446
+		keys = g_strsplit (key, ":", -1);
7d1446
+		if (g_strv_length (keys) < 3 || g_strv_length (keys) > 4) {
7d1446
+			g_warning ("%s: Incorrect store setup key, expects 3 or 4 parts, but %d given in '%s'",
7d1446
+				G_STRFUNC, g_strv_length (keys), (const gchar *) key);
7d1446
+		} else if (g_str_equal (keys[0], "Collection")) {
7d1446
+			if (mail_store_save_setup_key (store, collection_source, keys[1], keys[2], keys[3], value))
7d1446
+				collection_changed = TRUE;
7d1446
+		} else if (g_str_equal (keys[0], "Account")) {
7d1446
+			if (mail_store_save_setup_key (store, account_source, keys[1], keys[2], keys[3], value))
7d1446
+				account_changed = TRUE;
7d1446
+		} else if (g_str_equal (keys[0], "Submission")) {
7d1446
+			if (mail_store_save_setup_key (store, submission_source, keys[1], keys[2], keys[3], value))
7d1446
+				submission_changed = TRUE;
7d1446
+		} else if (g_str_equal (keys[0], "Transport")) {
7d1446
+			if (mail_store_save_setup_key (store, transport_source, keys[1], keys[2], keys[3], value))
7d1446
+				transport_changed = TRUE;
7d1446
+		} else if (g_str_equal (keys[0], "Backend")) {
7d1446
+			ESource *backend_source = NULL;
7d1446
+
7d1446
+			if (collection_source && e_source_has_extension (collection_source, keys[1]))
7d1446
+				backend_source = collection_source;
7d1446
+			else if (account_source && e_source_has_extension (account_source, keys[1]))
7d1446
+				backend_source = account_source;
7d1446
+
7d1446
+			if (mail_store_save_setup_key (store, backend_source, keys[1], keys[2], keys[3], value))
7d1446
+				transport_changed = TRUE;
7d1446
+		} else {
7d1446
+			g_warning ("%s: Unknown source name '%s' given in '%s'", G_STRFUNC, keys[0], (const gchar *) key);
7d1446
+		}
7d1446
+	}
7d1446
+
7d1446
+	if (write_sources) {
7d1446
+		if (transport_changed && success && e_source_get_writable (transport_source))
7d1446
+			success = e_source_write_sync (transport_source, cancellable, error);
7d1446
+		if (submission_changed && success && e_source_get_writable (submission_source))
7d1446
+			success = e_source_write_sync (submission_source, cancellable, error);
7d1446
+		if (account_changed && success && e_source_get_writable (account_source))
7d1446
+			success = e_source_write_sync (account_source, cancellable, error);
7d1446
+		if (collection_changed && success && e_source_get_writable (collection_source))
7d1446
+			success = e_source_write_sync (collection_source, cancellable, error);
7d1446
+	}
7d1446
+
7d1446
+	return success;
7d1446
+}
7d1446
diff -up evolution-3.12.11/libemail-engine/e-mail-store-utils.h.initial-setup-mail-remote-folders evolution-3.12.11/libemail-engine/e-mail-store-utils.h
7d1446
--- evolution-3.12.11/libemail-engine/e-mail-store-utils.h.initial-setup-mail-remote-folders	2014-03-24 10:25:23.000000000 +0100
7d1446
+++ evolution-3.12.11/libemail-engine/e-mail-store-utils.h	2016-03-21 13:36:48.177689307 +0100
7d1446
@@ -78,6 +78,17 @@ gboolean	e_mail_store_prepare_for_offlin
7d1446
 						 GAsyncResult *result,
7d1446
 						 GError **error);
7d1446
 
7d1446
+gboolean	e_mail_store_save_initial_setup_sync
7d1446
+						(CamelStore *store,
7d1446
+						 GHashTable *save_setup,
7d1446
+						 ESource *collection_source,
7d1446
+						 ESource *account_source,
7d1446
+						 ESource *submission_source,
7d1446
+						 ESource *transport_source,
7d1446
+						 gboolean write_sources,
7d1446
+						 GCancellable *cancellable,
7d1446
+						 GError **error);
7d1446
+
7d1446
 G_END_DECLS
7d1446
 
7d1446
 #endif /* E_MAIL_STORE_UTILS_H */
7d1446
diff -up evolution-3.12.11/libemail-engine/mail-folder-cache.c.initial-setup-mail-remote-folders evolution-3.12.11/libemail-engine/mail-folder-cache.c
7d1446
--- evolution-3.12.11/libemail-engine/mail-folder-cache.c.initial-setup-mail-remote-folders	2014-06-25 19:07:24.000000000 +0200
7d1446
+++ evolution-3.12.11/libemail-engine/mail-folder-cache.c	2016-03-21 13:36:48.177689307 +0100
7d1446
@@ -1658,6 +1658,163 @@ mail_folder_cache_ref_main_context (Mail
7d1446
 	return g_main_context_ref (cache->priv->main_context);
7d1446
 }
7d1446
 
7d1446
+static ESource *
7d1446
+mail_folder_cache_ref_related_source (ESourceRegistry *registry,
7d1446
+				      ESource *account_source,
7d1446
+				      ESource *collection_source,
7d1446
+				      const gchar *extension_name)
7d1446
+{
7d1446
+	ESource *found_source = NULL;
7d1446
+	GList *sources, *link;
7d1446
+	const gchar *parent1, *parent2;
7d1446
+
7d1446
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
7d1446
+	g_return_val_if_fail (E_IS_SOURCE (account_source), NULL);
7d1446
+	if (collection_source)
7d1446
+		g_return_val_if_fail (E_IS_SOURCE (collection_source), NULL);
7d1446
+	g_return_val_if_fail (extension_name != NULL, NULL);
7d1446
+
7d1446
+	parent1 = e_source_get_uid (account_source);
7d1446
+	parent2 = collection_source ? e_source_get_uid (collection_source) : NULL;
7d1446
+
7d1446
+	sources = e_source_registry_list_sources (registry, extension_name);
7d1446
+	for (link = sources; link; link = g_list_next (link)) {
7d1446
+		ESource *source = link->data;
7d1446
+		const gchar *parent;
7d1446
+
7d1446
+		if (!source)
7d1446
+			continue;
7d1446
+
7d1446
+		parent = e_source_get_parent (source);
7d1446
+		if (!parent)
7d1446
+			continue;
7d1446
+
7d1446
+		if (g_strcmp0 (parent, parent1) == 0 ||
7d1446
+		    g_strcmp0 (parent, parent2) == 0) {
7d1446
+			found_source = g_object_ref (source);
7d1446
+			break;
7d1446
+		}
7d1446
+	}
7d1446
+
7d1446
+	g_list_free_full (sources, g_object_unref);
7d1446
+
7d1446
+	return found_source;
7d1446
+}
7d1446
+
7d1446
+static gboolean
7d1446
+mail_folder_cache_store_save_setup_sync (CamelService *service,
7d1446
+					 ESourceRegistry *registry,
7d1446
+					 ESource *account_source,
7d1446
+					 GHashTable *save_setup,
7d1446
+					 GCancellable *cancellable,
7d1446
+					 GError **error)
7d1446
+{
7d1446
+	ESource *collection_source = NULL;
7d1446
+	ESource *submission_source = NULL;
7d1446
+	ESource *transport_source = NULL;
7d1446
+	gboolean success = TRUE;
7d1446
+
7d1446
+	/* The sources are either:
7d1446
+		Account
7d1446
+		 - Submission
7d1446
+		 - Transport
7d1446
+	or
7d1446
+		Collection
7d1446
+		 - Account
7d1446
+		 - Submission
7d1446
+		 - Transport
7d1446
+	*/
7d1446
+
7d1446
+	g_return_val_if_fail (CAMEL_IS_STORE (service), FALSE);
7d1446
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
7d1446
+	g_return_val_if_fail (E_IS_SOURCE (account_source), FALSE);
7d1446
+	g_return_val_if_fail (save_setup != NULL, FALSE);
7d1446
+
7d1446
+	if (!g_hash_table_size (save_setup))
7d1446
+		return TRUE;
7d1446
+
7d1446
+	if (e_source_get_parent (account_source)) {
7d1446
+		collection_source = e_source_registry_ref_source (registry, e_source_get_parent (account_source));
7d1446
+		if (!collection_source || !e_source_has_extension (collection_source, E_SOURCE_EXTENSION_COLLECTION)) {
7d1446
+			g_clear_object (&collection_source);
7d1446
+		}
7d1446
+	}
7d1446
+
7d1446
+	submission_source = mail_folder_cache_ref_related_source (registry, account_source,
7d1446
+		collection_source, E_SOURCE_EXTENSION_MAIL_SUBMISSION);
7d1446
+	transport_source = mail_folder_cache_ref_related_source (registry, account_source,
7d1446
+		collection_source, E_SOURCE_EXTENSION_MAIL_TRANSPORT);
7d1446
+
7d1446
+	success = e_mail_store_save_initial_setup_sync (CAMEL_STORE (service), save_setup,
7d1446
+		collection_source, account_source, submission_source, transport_source,
7d1446
+		TRUE, cancellable, error);
7d1446
+
7d1446
+	g_clear_object (&collection_source);
7d1446
+	g_clear_object (&submission_source);
7d1446
+	g_clear_object (&transport_source);
7d1446
+
7d1446
+	return success;
7d1446
+}
7d1446
+
7d1446
+static gboolean
7d1446
+mail_folder_cache_maybe_run_initial_setup_sync (CamelService *service,
7d1446
+						GCancellable *cancellable,
7d1446
+						GError **error)
7d1446
+{
7d1446
+	CamelSession *session;
7d1446
+	ESourceRegistry *registry;
7d1446
+	ESource *source;
7d1446
+	ESourceMailAccount *mail_account;
7d1446
+	gboolean success = TRUE;
7d1446
+
7d1446
+	g_return_val_if_fail (CAMEL_IS_STORE (service), FALSE);
7d1446
+
7d1446
+	session = camel_service_ref_session (service);
7d1446
+
7d1446
+	/* It can be NULL, in some corner cases, thus do not consider it a problem */
7d1446
+	if (!session)
7d1446
+		return TRUE;
7d1446
+
7d1446
+	g_return_val_if_fail (E_IS_MAIL_SESSION (session), FALSE);
7d1446
+
7d1446
+	registry = e_mail_session_get_registry (E_MAIL_SESSION (session));
7d1446
+	source = e_source_registry_ref_source (registry, camel_service_get_uid (service));
7d1446
+
7d1446
+	if (source) {
7d1446
+		mail_account = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
7d1446
+		if (e_source_mail_account_get_needs_initial_setup (mail_account)) {
7d1446
+			CamelStore *store = CAMEL_STORE (service);
7d1446
+			GHashTable *save_setup = NULL;
7d1446
+
7d1446
+			/* The store doesn't support the function, thus silently pretend success.
7d1446
+			   Still update the ESource flag, in case the store would implement
7d1446
+			   the function in the future. */
7d1446
+			if (!(store->flags & CAMEL_STORE_SUPPORTS_INITIAL_SETUP))
7d1446
+				success = TRUE;
7d1446
+			else
7d1446
+				success = camel_store_initial_setup_sync (store, &save_setup, cancellable, error);
7d1446
+
7d1446
+			if (success) {
7d1446
+				e_source_mail_account_set_needs_initial_setup (mail_account, FALSE);
7d1446
+
7d1446
+				if (save_setup)
7d1446
+					success = mail_folder_cache_store_save_setup_sync (service, registry, source, save_setup, cancellable, error);
7d1446
+
7d1446
+				if (success && e_source_get_writable (source))
7d1446
+					success = e_source_write_sync (source, cancellable, error);
7d1446
+			}
7d1446
+
7d1446
+			if (save_setup)
7d1446
+				g_hash_table_destroy (save_setup);
7d1446
+		}
7d1446
+	}
7d1446
+
7d1446
+	g_clear_object (&session);
7d1446
+	g_clear_object (&source);
7d1446
+
7d1446
+	return success;
7d1446
+}
7d1446
+
7d1446
 /* Helper for mail_folder_cache_note_store() */
7d1446
 static void
7d1446
 mail_folder_cache_first_update (MailFolderCache *cache,
7d1446
@@ -1752,6 +1909,11 @@ mail_folder_cache_note_store_thread (GSi
7d1446
 				goto exit;
7d1446
 			}
7d1446
 		}
7d1446
+
7d1446
+		if (!mail_folder_cache_maybe_run_initial_setup_sync (service, cancellable, &local_error)) {
7d1446
+			g_simple_async_result_take_error (simple, local_error);
7d1446
+			goto exit;
7d1446
+		}
7d1446
 	}
7d1446
 
7d1446
 	/* No folder hierarchy means we're done. */
7d1446
diff -up evolution-3.12.11/mail/e-mail-config-defaults-page.c.initial-setup-mail-remote-folders evolution-3.12.11/mail/e-mail-config-defaults-page.c
7d1446
--- evolution-3.12.11/mail/e-mail-config-defaults-page.c.initial-setup-mail-remote-folders	2014-07-17 12:48:14.000000000 +0200
7d1446
+++ evolution-3.12.11/mail/e-mail-config-defaults-page.c	2016-03-21 13:36:48.177689307 +0100
7d1446
@@ -15,15 +15,18 @@
7d1446
  *
7d1446
  */
7d1446
 
7d1446
-#include "e-mail-config-defaults-page.h"
7d1446
-
7d1446
 #include <config.h>
7d1446
 #include <glib/gi18n-lib.h>
7d1446
 
7d1446
 #include <libebackend/libebackend.h>
7d1446
 
7d1446
-#include <mail/e-mail-config-page.h>
7d1446
-#include <mail/em-folder-selection-button.h>
7d1446
+#include "libemail-engine/libemail-engine.h"
7d1446
+
7d1446
+#include "e-mail-config-page.h"
7d1446
+#include "e-mail-config-activity-page.h"
7d1446
+#include "em-folder-selection-button.h"
7d1446
+
7d1446
+#include "e-mail-config-defaults-page.h"
7d1446
 
7d1446
 #define E_MAIL_CONFIG_DEFAULTS_PAGE_GET_PRIVATE(obj) \
7d1446
 	(G_TYPE_INSTANCE_GET_PRIVATE \
7d1446
@@ -32,7 +35,10 @@
7d1446
 struct _EMailConfigDefaultsPagePrivate {
7d1446
 	EMailSession *session;
7d1446
 	ESource *account_source;
7d1446
+	ESource *collection_source;
7d1446
 	ESource *identity_source;
7d1446
+	ESource *original_source;
7d1446
+	ESource *transport_source;
7d1446
 
7d1446
 	GtkWidget *drafts_button;  /* not referenced */
7d1446
 	GtkWidget *sent_button;    /* not referenced */
7d1446
@@ -44,7 +50,10 @@ struct _EMailConfigDefaultsPagePrivate {
7d1446
 enum {
7d1446
 	PROP_0,
7d1446
 	PROP_ACCOUNT_SOURCE,
7d1446
+	PROP_COLLECTION_SOURCE,
7d1446
 	PROP_IDENTITY_SOURCE,
7d1446
+	PROP_ORIGINAL_SOURCE,
7d1446
+	PROP_TRANSPORT_SOURCE,
7d1446
 	PROP_SESSION
7d1446
 };
7d1446
 
7d1446
@@ -55,7 +64,7 @@ static void	e_mail_config_defaults_page_
7d1446
 G_DEFINE_TYPE_WITH_CODE (
7d1446
 	EMailConfigDefaultsPage,
7d1446
 	e_mail_config_defaults_page,
7d1446
-	GTK_TYPE_BOX,
7d1446
+	E_TYPE_MAIL_CONFIG_ACTIVITY_PAGE,
7d1446
 	G_IMPLEMENT_INTERFACE (
7d1446
 		E_TYPE_EXTENSIBLE, NULL)
7d1446
 	G_IMPLEMENT_INTERFACE (
7d1446
@@ -275,6 +284,105 @@ mail_config_defaults_page_restore_folder
7d1446
 	}
7d1446
 }
7d1446
 
7d1446
+typedef struct _AsyncContext
7d1446
+{
7d1446
+	EActivity *activity;
7d1446
+	EMailConfigDefaultsPage *page;
7d1446
+	GtkWidget *button;
7d1446
+} AsyncContext;
7d1446
+
7d1446
+static void
7d1446
+async_context_free (AsyncContext *async_context)
7d1446
+{
7d1446
+	if (async_context) {
7d1446
+		g_clear_object (&async_context->activity);
7d1446
+		g_clear_object (&async_context->page);
7d1446
+		g_clear_object (&async_context->button);
7d1446
+
7d1446
+		g_slice_free (AsyncContext, async_context);
7d1446
+	}
7d1446
+}
7d1446
+
7d1446
+static void
7d1446
+mail_config_defaults_initial_setup_done_cb (GObject *source_object,
7d1446
+					    GAsyncResult *result,
7d1446
+					    gpointer user_data)
7d1446
+{
7d1446
+	AsyncContext *async_context = user_data;
7d1446
+	CamelStore *store = CAMEL_STORE (source_object);
7d1446
+	EAlertSink *alert_sink;
7d1446
+	GHashTable *save_setup = NULL;
7d1446
+	GError *error = NULL;
7d1446
+
7d1446
+	alert_sink = e_activity_get_alert_sink (async_context->activity);
7d1446
+
7d1446
+	camel_store_initial_setup_finish (store, result, &save_setup, &error);
7d1446
+
7d1446
+	if (e_activity_handle_cancellation (async_context->activity, error)) {
7d1446
+		g_warn_if_fail (save_setup == NULL);
7d1446
+		g_error_free (error);
7d1446
+
7d1446
+	} else if (error != NULL) {
7d1446
+		g_warn_if_fail (save_setup == NULL);
7d1446
+		e_alert_submit (
7d1446
+			alert_sink,
7d1446
+			"mail:initial-setup-error",
7d1446
+			error->message, NULL);
7d1446
+		g_error_free (error);
7d1446
+
7d1446
+	} else if (save_setup) {
7d1446
+		e_mail_store_save_initial_setup_sync (store, save_setup,
7d1446
+			async_context->page->priv->collection_source,
7d1446
+			async_context->page->priv->account_source,
7d1446
+			async_context->page->priv->identity_source,
7d1446
+			async_context->page->priv->transport_source,
7d1446
+			FALSE, NULL, NULL);
7d1446
+
7d1446
+		g_hash_table_destroy (save_setup);
7d1446
+	}
7d1446
+
7d1446
+	gtk_widget_set_sensitive (async_context->button, TRUE);
7d1446
+
7d1446
+	async_context_free (async_context);
7d1446
+}
7d1446
+
7d1446
+static void
7d1446
+mail_config_defaults_page_autodetect_folders_cb (EMailConfigDefaultsPage *page,
7d1446
+						 GtkWidget *button)
7d1446
+{
7d1446
+	CamelService *service;
7d1446
+	EActivity *activity;
7d1446
+	AsyncContext *async_context;
7d1446
+	GCancellable *cancellable;
7d1446
+
7d1446
+	g_return_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page));
7d1446
+
7d1446
+	service = camel_session_ref_service (CAMEL_SESSION (page->priv->session), e_source_get_uid (page->priv->original_source));
7d1446
+
7d1446
+	if (!service || !CAMEL_IS_STORE (service)) {
7d1446
+		g_clear_object (&service);
7d1446
+		return;
7d1446
+	}
7d1446
+
7d1446
+	activity = e_mail_config_activity_page_new_activity (E_MAIL_CONFIG_ACTIVITY_PAGE (page));
7d1446
+
7d1446
+	cancellable = e_activity_get_cancellable (activity);
7d1446
+	e_activity_set_text (activity, _("Checking server settings..."));
7d1446
+
7d1446
+	gtk_widget_set_sensitive (button, FALSE);
7d1446
+
7d1446
+	async_context = g_slice_new (AsyncContext);
7d1446
+	async_context->activity = activity;
7d1446
+	async_context->page = g_object_ref (page);
7d1446
+	async_context->button = g_object_ref (button);
7d1446
+
7d1446
+	camel_store_initial_setup (
7d1446
+		CAMEL_STORE (service), G_PRIORITY_DEFAULT, cancellable,
7d1446
+		mail_config_defaults_initial_setup_done_cb, async_context);
7d1446
+
7d1446
+	g_object_unref (service);
7d1446
+}
7d1446
+
7d1446
 static void
7d1446
 mail_config_defaults_page_restore_real_folder (GtkToggleButton *toggle_button)
7d1446
 {
7d1446
@@ -370,6 +478,17 @@ mail_config_defaults_page_add_real_folde
7d1446
 }
7d1446
 
7d1446
 static void
7d1446
+mail_config_defaults_page_set_collection_source (EMailConfigDefaultsPage *page,
7d1446
+						 ESource *collection_source)
7d1446
+{
7d1446
+	if (collection_source)
7d1446
+		g_return_if_fail (E_IS_SOURCE (collection_source));
7d1446
+	g_return_if_fail (page->priv->collection_source == NULL);
7d1446
+
7d1446
+	page->priv->collection_source = collection_source ? g_object_ref (collection_source) : NULL;
7d1446
+}
7d1446
+
7d1446
+static void
7d1446
 mail_config_defaults_page_set_account_source (EMailConfigDefaultsPage *page,
7d1446
                                               ESource *account_source)
7d1446
 {
7d1446
@@ -390,6 +509,28 @@ mail_config_defaults_page_set_identity_s
7d1446
 }
7d1446
 
7d1446
 static void
7d1446
+mail_config_defaults_page_set_original_source (EMailConfigDefaultsPage *page,
7d1446
+					       ESource *original_source)
7d1446
+{
7d1446
+	if (original_source)
7d1446
+		g_return_if_fail (E_IS_SOURCE (original_source));
7d1446
+	g_return_if_fail (page->priv->original_source == NULL);
7d1446
+
7d1446
+	page->priv->original_source = original_source ? g_object_ref (original_source) : NULL;
7d1446
+}
7d1446
+
7d1446
+static void
7d1446
+mail_config_defaults_page_set_transport_source (EMailConfigDefaultsPage *page,
7d1446
+						ESource *transport_source)
7d1446
+{
7d1446
+	if (transport_source)
7d1446
+		g_return_if_fail (E_IS_SOURCE (transport_source));
7d1446
+	g_return_if_fail (page->priv->transport_source == NULL);
7d1446
+
7d1446
+	page->priv->transport_source = transport_source ? g_object_ref (transport_source) : NULL;
7d1446
+}
7d1446
+
7d1446
+static void
7d1446
 mail_config_defaults_page_set_session (EMailConfigDefaultsPage *page,
7d1446
                                        EMailSession *session)
7d1446
 {
7d1446
@@ -412,12 +553,30 @@ mail_config_defaults_page_set_property (
7d1446
 				g_value_get_object (value));
7d1446
 			return;
7d1446
 
7d1446
+		case PROP_COLLECTION_SOURCE:
7d1446
+			mail_config_defaults_page_set_collection_source (
7d1446
+				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
7d1446
+				g_value_get_object (value));
7d1446
+			return;
7d1446
+
7d1446
 		case PROP_IDENTITY_SOURCE:
7d1446
 			mail_config_defaults_page_set_identity_source (
7d1446
 				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
7d1446
 				g_value_get_object (value));
7d1446
 			return;
7d1446
 
7d1446
+		case PROP_ORIGINAL_SOURCE:
7d1446
+			mail_config_defaults_page_set_original_source (
7d1446
+				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
7d1446
+				g_value_get_object (value));
7d1446
+			return;
7d1446
+
7d1446
+		case PROP_TRANSPORT_SOURCE:
7d1446
+			mail_config_defaults_page_set_transport_source (
7d1446
+				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
7d1446
+				g_value_get_object (value));
7d1446
+			return;
7d1446
+
7d1446
 		case PROP_SESSION:
7d1446
 			mail_config_defaults_page_set_session (
7d1446
 				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
7d1446
@@ -442,6 +601,13 @@ mail_config_defaults_page_get_property (
7d1446
 				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
7d1446
 			return;
7d1446
 
7d1446
+		case PROP_COLLECTION_SOURCE:
7d1446
+			g_value_set_object (
7d1446
+				value,
7d1446
+				e_mail_config_defaults_page_get_collection_source (
7d1446
+				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
7d1446
+			return;
7d1446
+
7d1446
 		case PROP_IDENTITY_SOURCE:
7d1446
 			g_value_set_object (
7d1446
 				value,
7d1446
@@ -449,6 +615,20 @@ mail_config_defaults_page_get_property (
7d1446
 				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
7d1446
 			return;
7d1446
 
7d1446
+		case PROP_ORIGINAL_SOURCE:
7d1446
+			g_value_set_object (
7d1446
+				value,
7d1446
+				e_mail_config_defaults_page_get_original_source (
7d1446
+				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
7d1446
+			return;
7d1446
+
7d1446
+		case PROP_TRANSPORT_SOURCE:
7d1446
+			g_value_set_object (
7d1446
+				value,
7d1446
+				e_mail_config_defaults_page_get_transport_source (
7d1446
+				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
7d1446
+			return;
7d1446
+
7d1446
 		case PROP_SESSION:
7d1446
 			g_value_set_object (
7d1446
 				value,
7d1446
@@ -467,15 +647,11 @@ mail_config_defaults_page_dispose (GObje
7d1446
 
7d1446
 	priv = E_MAIL_CONFIG_DEFAULTS_PAGE_GET_PRIVATE (object);
7d1446
 
7d1446
-	if (priv->identity_source != NULL) {
7d1446
-		g_object_unref (priv->identity_source);
7d1446
-		priv->identity_source = NULL;
7d1446
-	}
7d1446
-
7d1446
-	if (priv->session != NULL) {
7d1446
-		g_object_unref (priv->session);
7d1446
-		priv->session = NULL;
7d1446
-	}
7d1446
+	g_clear_object (&priv->account_source);
7d1446
+	g_clear_object (&priv->collection_source);
7d1446
+	g_clear_object (&priv->identity_source);
7d1446
+	g_clear_object (&priv->transport_source);
7d1446
+	g_clear_object (&priv->session);
7d1446
 
7d1446
 	/* Chain up to parent's dispose() method. */
7d1446
 	G_OBJECT_CLASS (e_mail_config_defaults_page_parent_class)->
7d1446
@@ -496,6 +672,7 @@ mail_config_defaults_page_constructed (G
7d1446
 	GtkButton *button;
7d1446
 	GtkWidget *widget;
7d1446
 	GtkWidget *container;
7d1446
+	GtkWidget *hbox;
7d1446
 	GtkSizeGroup *size_group;
7d1446
 	GEnumClass *enum_class;
7d1446
 	GEnumValue *enum_value;
7d1446
@@ -624,9 +801,13 @@ mail_config_defaults_page_constructed (G
7d1446
 		G_BINDING_BIDIRECTIONAL |
7d1446
 		G_BINDING_SYNC_CREATE);
7d1446
 
7d1446
+	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
7d1446
+	gtk_grid_attach (GTK_GRID (container), hbox, 1, 6, 1, 1);
7d1446
+	gtk_widget_show (hbox);
7d1446
+
7d1446
 	widget = gtk_button_new_with_mnemonic (_("_Restore Defaults"));
7d1446
 	gtk_widget_set_halign (widget, GTK_ALIGN_START);
7d1446
-	gtk_grid_attach (GTK_GRID (container), widget, 1, 6, 1, 1);
7d1446
+	gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
7d1446
 	gtk_widget_show (widget);
7d1446
 
7d1446
 	g_signal_connect_swapped (
7d1446
@@ -634,6 +815,27 @@ mail_config_defaults_page_constructed (G
7d1446
 		G_CALLBACK (mail_config_defaults_page_restore_folders),
7d1446
 		page);
7d1446
 
7d1446
+	if (page->priv->original_source) {
7d1446
+		CamelService *service;
7d1446
+
7d1446
+		service = camel_session_ref_service (CAMEL_SESSION (session), e_source_get_uid (page->priv->original_source));
7d1446
+
7d1446
+		if (service && CAMEL_IS_STORE (service) &&
7d1446
+		    (CAMEL_STORE (service)->flags & CAMEL_STORE_SUPPORTS_INITIAL_SETUP) != 0) {
7d1446
+			widget = gtk_button_new_with_mnemonic (_("_Lookup Folders"));
7d1446
+			gtk_widget_set_halign (widget, GTK_ALIGN_START);
7d1446
+			gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
7d1446
+			gtk_widget_show (widget);
7d1446
+
7d1446
+			g_signal_connect_swapped (
7d1446
+				widget, "clicked",
7d1446
+				G_CALLBACK (mail_config_defaults_page_autodetect_folders_cb),
7d1446
+				page);
7d1446
+		}
7d1446
+
7d1446
+		g_clear_object (&service);
7d1446
+	}
7d1446
+
7d1446
 	button = GTK_BUTTON (widget);
7d1446
 
7d1446
 	widget = mail_config_defaults_page_add_real_folder (
7d1446
@@ -826,6 +1028,18 @@ e_mail_config_defaults_page_class_init (
7d1446
 
7d1446
 	g_object_class_install_property (
7d1446
 		object_class,
7d1446
+		PROP_COLLECTION_SOURCE,
7d1446
+		g_param_spec_object (
7d1446
+			"collection-source",
7d1446
+			"Collection Source",
7d1446
+			"Collection source being edited",
7d1446
+			E_TYPE_SOURCE,
7d1446
+			G_PARAM_READWRITE |
7d1446
+			G_PARAM_CONSTRUCT_ONLY |
7d1446
+			G_PARAM_STATIC_STRINGS));
7d1446
+
7d1446
+	g_object_class_install_property (
7d1446
+		object_class,
7d1446
 		PROP_IDENTITY_SOURCE,
7d1446
 		g_param_spec_object (
7d1446
 			"identity-source",
7d1446
@@ -838,6 +1052,30 @@ e_mail_config_defaults_page_class_init (
7d1446
 
7d1446
 	g_object_class_install_property (
7d1446
 		object_class,
7d1446
+		PROP_ORIGINAL_SOURCE,
7d1446
+		g_param_spec_object (
7d1446
+			"original-source",
7d1446
+			"Original Source",
7d1446
+			"Mail account original source being edited",
7d1446
+			E_TYPE_SOURCE,
7d1446
+			G_PARAM_READWRITE |
7d1446
+			G_PARAM_CONSTRUCT_ONLY |
7d1446
+			G_PARAM_STATIC_STRINGS));
7d1446
+
7d1446
+	g_object_class_install_property (
7d1446
+		object_class,
7d1446
+		PROP_TRANSPORT_SOURCE,
7d1446
+		g_param_spec_object (
7d1446
+			"transport-source",
7d1446
+			"Transport Source",
7d1446
+			"Mail transport source being edited",
7d1446
+			E_TYPE_SOURCE,
7d1446
+			G_PARAM_READWRITE |
7d1446
+			G_PARAM_CONSTRUCT_ONLY |
7d1446
+			G_PARAM_STATIC_STRINGS));
7d1446
+
7d1446
+	g_object_class_install_property (
7d1446
+		object_class,
7d1446
 		PROP_SESSION,
7d1446
 		g_param_spec_object (
7d1446
 			"session",
7d1446
@@ -864,17 +1102,24 @@ e_mail_config_defaults_page_init (EMailC
7d1446
 
7d1446
 EMailConfigPage *
7d1446
 e_mail_config_defaults_page_new (EMailSession *session,
7d1446
+				 ESource *original_source,
7d1446
+				 ESource *collection_source,
7d1446
                                  ESource *account_source,
7d1446
-                                 ESource *identity_source)
7d1446
+                                 ESource *identity_source,
7d1446
+				 ESource *transport_source)
7d1446
 {
7d1446
+	/* original, collection and transport sources are optional */
7d1446
 	g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
7d1446
 	g_return_val_if_fail (E_IS_SOURCE (account_source), NULL);
7d1446
 	g_return_val_if_fail (E_IS_SOURCE (identity_source), NULL);
7d1446
 
7d1446
 	return g_object_new (
7d1446
 		E_TYPE_MAIL_CONFIG_DEFAULTS_PAGE,
7d1446
+		"collection-source", collection_source,
7d1446
 		"account-source", account_source,
7d1446
 		"identity-source", identity_source,
7d1446
+		"original-source", original_source,
7d1446
+		"transport-source", transport_source,
7d1446
 		"session", session, NULL);
7d1446
 }
7d1446
 
7d1446
@@ -895,6 +1140,14 @@ e_mail_config_defaults_page_get_account_
7d1446
 }
7d1446
 
7d1446
 ESource *
7d1446
+e_mail_config_defaults_page_get_collection_source (EMailConfigDefaultsPage *page)
7d1446
+{
7d1446
+	g_return_val_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page), NULL);
7d1446
+
7d1446
+	return page->priv->collection_source;
7d1446
+}
7d1446
+
7d1446
+ESource *
7d1446
 e_mail_config_defaults_page_get_identity_source (EMailConfigDefaultsPage *page)
7d1446
 {
7d1446
 	g_return_val_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page), NULL);
7d1446
@@ -902,3 +1155,18 @@ e_mail_config_defaults_page_get_identity
7d1446
 	return page->priv->identity_source;
7d1446
 }
7d1446
 
7d1446
+ESource *
7d1446
+e_mail_config_defaults_page_get_original_source (EMailConfigDefaultsPage *page)
7d1446
+{
7d1446
+	g_return_val_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page), NULL);
7d1446
+
7d1446
+	return page->priv->original_source;
7d1446
+}
7d1446
+
7d1446
+ESource *
7d1446
+e_mail_config_defaults_page_get_transport_source (EMailConfigDefaultsPage *page)
7d1446
+{
7d1446
+	g_return_val_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page), NULL);
7d1446
+
7d1446
+	return page->priv->transport_source;
7d1446
+}
7d1446
diff -up evolution-3.12.11/mail/e-mail-config-defaults-page.h.initial-setup-mail-remote-folders evolution-3.12.11/mail/e-mail-config-defaults-page.h
7d1446
--- evolution-3.12.11/mail/e-mail-config-defaults-page.h.initial-setup-mail-remote-folders	2014-03-24 10:25:23.000000000 +0100
7d1446
+++ evolution-3.12.11/mail/e-mail-config-defaults-page.h	2016-03-21 13:36:48.177689307 +0100
7d1446
@@ -22,6 +22,7 @@
7d1446
 #include <libemail-engine/libemail-engine.h>
7d1446
 
7d1446
 #include <mail/e-mail-config-page.h>
7d1446
+#include <mail/e-mail-config-activity-page.h>
7d1446
 
7d1446
 /* Standard GObject macros */
7d1446
 #define E_TYPE_MAIL_CONFIG_DEFAULTS_PAGE \
7d1446
@@ -51,26 +52,35 @@ typedef struct _EMailConfigDefaultsPageC
7d1446
 typedef struct _EMailConfigDefaultsPagePrivate EMailConfigDefaultsPagePrivate;
7d1446
 
7d1446
 struct _EMailConfigDefaultsPage {
7d1446
-	GtkBox parent;
7d1446
+	EMailConfigActivityPage parent;
7d1446
 	EMailConfigDefaultsPagePrivate *priv;
7d1446
 };
7d1446
 
7d1446
 struct _EMailConfigDefaultsPageClass {
7d1446
-	GtkBoxClass parent_class;
7d1446
+	EMailConfigActivityPageClass parent_class;
7d1446
 };
7d1446
 
7d1446
 GType		e_mail_config_defaults_page_get_type
7d1446
 						(void) G_GNUC_CONST;
7d1446
 EMailConfigPage *
7d1446
 		e_mail_config_defaults_page_new	(EMailSession *session,
7d1446
+						 ESource *original_source,
7d1446
+						 ESource *collection_source,
7d1446
 						 ESource *account_source,
7d1446
-						 ESource *identity_source);
7d1446
+						 ESource *identity_source,
7d1446
+						 ESource *transport_source);
7d1446
 EMailSession *	e_mail_config_defaults_page_get_session
7d1446
 						(EMailConfigDefaultsPage *page);
7d1446
 ESource *	e_mail_config_defaults_page_get_account_source
7d1446
 						(EMailConfigDefaultsPage *page);
7d1446
+ESource *	e_mail_config_defaults_page_get_collection_source
7d1446
+						(EMailConfigDefaultsPage *page);
7d1446
 ESource *	e_mail_config_defaults_page_get_identity_source
7d1446
 						(EMailConfigDefaultsPage *page);
7d1446
+ESource *	e_mail_config_defaults_page_get_original_source
7d1446
+						(EMailConfigDefaultsPage *page);
7d1446
+ESource *	e_mail_config_defaults_page_get_transport_source
7d1446
+						(EMailConfigDefaultsPage *page);
7d1446
 
7d1446
 G_END_DECLS
7d1446
 
7d1446
diff -up evolution-3.12.11/mail/e-mail-config-notebook.c.initial-setup-mail-remote-folders evolution-3.12.11/mail/e-mail-config-notebook.c
7d1446
--- evolution-3.12.11/mail/e-mail-config-notebook.c.initial-setup-mail-remote-folders	2014-07-17 12:48:14.000000000 +0200
7d1446
+++ evolution-3.12.11/mail/e-mail-config-notebook.c	2016-03-21 13:36:48.178689299 +0100
7d1446
@@ -34,6 +34,7 @@ typedef struct _AsyncContext AsyncContex
7d1446
 
7d1446
 struct _EMailConfigNotebookPrivate {
7d1446
 	EMailSession *session;
7d1446
+	ESource *original_source;
7d1446
 	ESource *account_source;
7d1446
 	ESource *identity_source;
7d1446
 	ESource *transport_source;
7d1446
@@ -53,6 +54,7 @@ enum {
7d1446
 	PROP_COLLECTION_SOURCE,
7d1446
 	PROP_COMPLETE,
7d1446
 	PROP_IDENTITY_SOURCE,
7d1446
+	PROP_ORIGINAL_SOURCE,
7d1446
 	PROP_SESSION,
7d1446
 	PROP_TRANSPORT_SOURCE
7d1446
 };
7d1446
@@ -144,6 +146,20 @@ mail_config_notebook_set_identity_source
7d1446
 }
7d1446
 
7d1446
 static void
7d1446
+mail_config_notebook_set_original_source (EMailConfigNotebook *notebook,
7d1446
+					  ESource *original_source)
7d1446
+{
7d1446
+	g_return_if_fail (notebook->priv->original_source == NULL);
7d1446
+
7d1446
+	if (original_source != NULL) {
7d1446
+		g_return_if_fail (E_IS_SOURCE (original_source));
7d1446
+		g_object_ref (original_source);
7d1446
+	}
7d1446
+
7d1446
+	notebook->priv->original_source = original_source;
7d1446
+}
7d1446
+
7d1446
+static void
7d1446
 mail_config_notebook_set_session (EMailConfigNotebook *notebook,
7d1446
                                   EMailSession *session)
7d1446
 {
7d1446
@@ -188,6 +204,12 @@ mail_config_notebook_set_property (GObje
7d1446
 				g_value_get_object (value));
7d1446
 			return;
7d1446
 
7d1446
+		case PROP_ORIGINAL_SOURCE:
7d1446
+			mail_config_notebook_set_original_source (
7d1446
+				E_MAIL_CONFIG_NOTEBOOK (object),
7d1446
+				g_value_get_object (value));
7d1446
+			return;
7d1446
+
7d1446
 		case PROP_SESSION:
7d1446
 			mail_config_notebook_set_session (
7d1446
 				E_MAIL_CONFIG_NOTEBOOK (object),
7d1446
@@ -239,6 +261,13 @@ mail_config_notebook_get_property (GObje
7d1446
 				E_MAIL_CONFIG_NOTEBOOK (object)));
7d1446
 			return;
7d1446
 
7d1446
+		case PROP_ORIGINAL_SOURCE:
7d1446
+			g_value_set_object (
7d1446
+				value,
7d1446
+				e_mail_config_notebook_get_original_source (
7d1446
+				E_MAIL_CONFIG_NOTEBOOK (object)));
7d1446
+			return;
7d1446
+
7d1446
 		case PROP_SESSION:
7d1446
 			g_value_set_object (
7d1446
 				value,
7d1446
@@ -264,30 +293,12 @@ mail_config_notebook_dispose (GObject *o
7d1446
 
7d1446
 	priv = E_MAIL_CONFIG_NOTEBOOK_GET_PRIVATE (object);
7d1446
 
7d1446
-	if (priv->session != NULL) {
7d1446
-		g_object_ref (priv->session);
7d1446
-		priv->session = NULL;
7d1446
-	}
7d1446
-
7d1446
-	if (priv->account_source != NULL) {
7d1446
-		g_object_ref (priv->account_source);
7d1446
-		priv->account_source = NULL;
7d1446
-	}
7d1446
-
7d1446
-	if (priv->identity_source != NULL) {
7d1446
-		g_object_ref (priv->identity_source);
7d1446
-		priv->identity_source = NULL;
7d1446
-	}
7d1446
-
7d1446
-	if (priv->transport_source != NULL) {
7d1446
-		g_object_ref (priv->transport_source);
7d1446
-		priv->transport_source = NULL;
7d1446
-	}
7d1446
-
7d1446
-	if (priv->collection_source != NULL) {
7d1446
-		g_object_ref (priv->collection_source);
7d1446
-		priv->collection_source = NULL;
7d1446
-	}
7d1446
+	g_clear_object (&priv->session);
7d1446
+	g_clear_object (&priv->account_source);
7d1446
+	g_clear_object (&priv->identity_source);
7d1446
+	g_clear_object (&priv->transport_source);
7d1446
+	g_clear_object (&priv->collection_source);
7d1446
+	g_clear_object (&priv->original_source);
7d1446
 
7d1446
 	/* Chain up to parent's dispose() method. */
7d1446
 	G_OBJECT_CLASS (e_mail_config_notebook_parent_class)->
7d1446
@@ -438,8 +449,11 @@ mail_config_notebook_constructed (GObjec
7d1446
 
7d1446
 	page = e_mail_config_defaults_page_new (
7d1446
 		session,
7d1446
+		notebook->priv->original_source,
7d1446
+		notebook->priv->collection_source,
7d1446
 		notebook->priv->account_source,
7d1446
-		notebook->priv->identity_source);
7d1446
+		notebook->priv->identity_source,
7d1446
+		notebook->priv->transport_source);
7d1446
 	e_mail_config_notebook_add_page (notebook, page);
7d1446
 
7d1446
 	/*** Security Page ***/
7d1446
@@ -545,6 +559,18 @@ e_mail_config_notebook_class_init (EMail
7d1446
 
7d1446
 	g_object_class_install_property (
7d1446
 		object_class,
7d1446
+		PROP_ORIGINAL_SOURCE,
7d1446
+		g_param_spec_object (
7d1446
+			"original-source",
7d1446
+			"Original Source",
7d1446
+			"Mail account original source being edited",
7d1446
+			E_TYPE_SOURCE,
7d1446
+			G_PARAM_READWRITE |
7d1446
+			G_PARAM_CONSTRUCT_ONLY |
7d1446
+			G_PARAM_STATIC_STRINGS));
7d1446
+
7d1446
+	g_object_class_install_property (
7d1446
+		object_class,
7d1446
 		PROP_SESSION,
7d1446
 		g_param_spec_object (
7d1446
 			"session",
7d1446
@@ -576,6 +602,7 @@ e_mail_config_notebook_init (EMailConfig
7d1446
 
7d1446
 GtkWidget *
7d1446
 e_mail_config_notebook_new (EMailSession *session,
7d1446
+                            ESource *original_source,
7d1446
                             ESource *account_source,
7d1446
                             ESource *identity_source,
7d1446
                             ESource *transport_source,
7d1446
@@ -593,6 +620,7 @@ e_mail_config_notebook_new (EMailSession
7d1446
 	return g_object_new (
7d1446
 		E_TYPE_MAIL_CONFIG_NOTEBOOK,
7d1446
 		"session", session,
7d1446
+		"original-source", original_source,
7d1446
 		"account-source", account_source,
7d1446
 		"identity-source", identity_source,
7d1446
 		"transport-source", transport_source,
7d1446
@@ -609,6 +637,14 @@ e_mail_config_notebook_get_session (EMai
7d1446
 }
7d1446
 
7d1446
 ESource *
7d1446
+e_mail_config_notebook_get_original_source (EMailConfigNotebook *notebook)
7d1446
+{
7d1446
+	g_return_val_if_fail (E_IS_MAIL_CONFIG_NOTEBOOK (notebook), NULL);
7d1446
+
7d1446
+	return notebook->priv->original_source;
7d1446
+}
7d1446
+
7d1446
+ESource *
7d1446
 e_mail_config_notebook_get_account_source (EMailConfigNotebook *notebook)
7d1446
 {
7d1446
 	g_return_val_if_fail (E_IS_MAIL_CONFIG_NOTEBOOK (notebook), NULL);
7d1446
diff -up evolution-3.12.11/mail/e-mail-config-notebook.h.initial-setup-mail-remote-folders evolution-3.12.11/mail/e-mail-config-notebook.h
7d1446
--- evolution-3.12.11/mail/e-mail-config-notebook.h.initial-setup-mail-remote-folders	2014-03-24 10:25:23.000000000 +0100
7d1446
+++ evolution-3.12.11/mail/e-mail-config-notebook.h	2016-03-21 13:36:48.178689299 +0100
7d1446
@@ -61,12 +61,15 @@ GType		e_mail_config_notebook_get_type
7d1446
 					(void) G_GNUC_CONST;
7d1446
 GtkWidget *	e_mail_config_notebook_new
7d1446
 					(EMailSession *session,
7d1446
+					 ESource *original_source,
7d1446
 					 ESource *account_source,
7d1446
 					 ESource *identity_source,
7d1446
 					 ESource *transport_source,
7d1446
 					 ESource *collection_source);
7d1446
 EMailSession *	e_mail_config_notebook_get_session
7d1446
 					(EMailConfigNotebook *notebook);
7d1446
+ESource *	e_mail_config_notebook_get_original_source
7d1446
+					(EMailConfigNotebook *notebook);
7d1446
 ESource *	e_mail_config_notebook_get_account_source
7d1446
 					(EMailConfigNotebook *notebook);
7d1446
 ESource *	e_mail_config_notebook_get_identity_source
7d1446
diff -up evolution-3.12.11/mail/e-mail-config-window.c.initial-setup-mail-remote-folders evolution-3.12.11/mail/e-mail-config-window.c
7d1446
--- evolution-3.12.11/mail/e-mail-config-window.c.initial-setup-mail-remote-folders	2014-07-17 12:48:14.000000000 +0200
7d1446
+++ evolution-3.12.11/mail/e-mail-config-window.c	2016-03-21 13:36:48.178689299 +0100
7d1446
@@ -356,6 +356,7 @@ mail_config_window_constructed (GObject
7d1446
 	 */
7d1446
 	widget = e_mail_config_notebook_new (
7d1446
 		window->priv->session,
7d1446
+		window->priv->original_source,
7d1446
 		window->priv->account_source,
7d1446
 		window->priv->identity_source,
7d1446
 		window->priv->transport_source,
7d1446
diff -up evolution-3.12.11/mail/e-mail-migrate.c.initial-setup-mail-remote-folders evolution-3.12.11/mail/e-mail-migrate.c
7d1446
--- evolution-3.12.11/mail/e-mail-migrate.c.initial-setup-mail-remote-folders	2014-07-10 21:06:12.000000000 +0200
7d1446
+++ evolution-3.12.11/mail/e-mail-migrate.c	2016-03-21 13:36:48.178689299 +0100
7d1446
@@ -312,6 +312,53 @@ em_rename_folder_views (EShellBackend *s
7d1446
 	g_free (views_dir);
7d1446
 }
7d1446
 
7d1446
+static void
7d1446
+unset_initial_setup_write_finished_cb (GObject *source_object,
7d1446
+				       GAsyncResult *result,
7d1446
+				       gpointer user_data)
7d1446
+{
7d1446
+	ESource *source;
7d1446
+	GError *local_error = NULL;
7d1446
+
7d1446
+	g_return_if_fail (E_IS_SOURCE (source_object));
7d1446
+	g_return_if_fail (result != NULL);
7d1446
+
7d1446
+	source = E_SOURCE (source_object);
7d1446
+
7d1446
+	if (!e_source_write_finish (source, result, &local_error)) {
7d1446
+		g_warning ("%s: Failed to save source '%s' (%s): %s", G_STRFUNC, e_source_get_uid (source),
7d1446
+			e_source_get_display_name (source), local_error ? local_error->message : "Unknown error");
7d1446
+	}
7d1446
+
7d1446
+	g_clear_error (&local_error);
7d1446
+}
7d1446
+
7d1446
+static void
7d1446
+em_unset_initial_setup_for_accounts (EShellBackend *shell_backend)
7d1446
+{
7d1446
+	ESourceRegistry *registry;
7d1446
+	GList *sources, *link;
7d1446
+
7d1446
+	g_return_if_fail (E_IS_SHELL_BACKEND (shell_backend));
7d1446
+
7d1446
+	registry = e_shell_get_registry (e_shell_backend_get_shell (shell_backend));
7d1446
+	sources = e_source_registry_list_sources (registry, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
7d1446
+
7d1446
+	for (link = sources; link; link = g_list_next (link)) {
7d1446
+		ESource *source = link->data;
7d1446
+		ESourceMailAccount *mail_account;
7d1446
+
7d1446
+		mail_account = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
7d1446
+		if (e_source_mail_account_get_needs_initial_setup (mail_account)) {
7d1446
+			e_source_mail_account_set_needs_initial_setup (mail_account, FALSE);
7d1446
+
7d1446
+			e_source_write (source, NULL, unset_initial_setup_write_finished_cb, NULL);
7d1446
+		}
7d1446
+	}
7d1446
+
7d1446
+	g_list_free_full (sources, g_object_unref);
7d1446
+}
7d1446
+
7d1446
 gboolean
7d1446
 e_mail_migrate (EShellBackend *shell_backend,
7d1446
                 gint major,
7d1446
@@ -329,5 +376,8 @@ e_mail_migrate (EShellBackend *shell_bac
7d1446
 	if (major <= 2 || (major == 3 && minor < 4))
7d1446
 		em_rename_folder_views (shell_backend);
7d1446
 
7d1446
+	if (major <= 2 || (major == 3 && minor < 19) || (major == 3 && minor == 19 && micro < 90))
7d1446
+		em_unset_initial_setup_for_accounts (shell_backend);
7d1446
+
7d1446
 	return TRUE;
7d1446
 }
7d1446
diff -up evolution-3.12.11/mail/mail.error.xml.initial-setup-mail-remote-folders evolution-3.12.11/mail/mail.error.xml
7d1446
--- evolution-3.12.11/mail/mail.error.xml.initial-setup-mail-remote-folders	2014-03-24 10:25:23.000000000 +0100
7d1446
+++ evolution-3.12.11/mail/mail.error.xml	2016-03-21 13:36:48.178689299 +0100
7d1446
@@ -371,6 +371,11 @@ An mbox account will be created to prese
7d1446
     <secondary xml:space="preserve">{0}</secondary>
7d1446
   </error>
7d1446
 
7d1446
+  <error id="initial-setup-error" type="error">
7d1446
+    <_primary>Failed to get server setup.</_primary>
7d1446
+    <secondary xml:space="preserve">{0}</secondary>
7d1446
+  </error>
7d1446
+
7d1446
   <error id="ask-quick-offline" type="question" default="GTK_RESPONSE_NO">
7d1446
     <_primary>Synchronize folders locally for offline usage?</_primary>
7d1446
     <_secondary xml:space="preserve">Do you want to locally synchronize the folders that are marked for offline usage?</_secondary>