[evolution/email-factory-3-4: 13/19] Ported 56ebfe2f3f1bbcd05c2ac78821edd06c986b40e6



commit 33bc475426873d96b9a8c37ce5f1bd444fa04b45
Author: Srinivasa Ragavan <sragavan gnome org>
Date:   Mon Oct 31 12:48:24 2011 +0530

    Ported 56ebfe2f3f1bbcd05c2ac78821edd06c986b40e6

 libemail-engine/e-mail-local.c   |   23 ++++-----
 libemail-engine/e-mail-session.c |   72 ++++++++++++++++++++++++------
 libemail-engine/e-mail-store.c   |   91 ++++++++++++++++++++++++--------------
 libemail-engine/mail-ops.c       |   13 ++++--
 libemail-engine/mail-tools.c     |   20 ++++++--
 5 files changed, 149 insertions(+), 70 deletions(-)
---
diff --git a/libemail-engine/e-mail-local.c b/libemail-engine/e-mail-local.c
index 1f33c08..28d174e 100644
--- a/libemail-engine/e-mail-local.c
+++ b/libemail-engine/e-mail-local.c
@@ -53,9 +53,9 @@ void
 e_mail_local_init (EMailSession *session,
                    const gchar *data_dir)
 {
+	CamelSettings *settings;
 	CamelService *service;
-	CamelURL *url;
-	gchar *temp;
+	gchar *path;
 	gint ii;
 	GError *error = NULL;
 
@@ -67,19 +67,19 @@ e_mail_local_init (EMailSession *session,
 
 	mail_local_initialized = TRUE;
 
-	url = camel_url_new ("maildir:", NULL);
-	temp = g_build_filename (data_dir, "local", NULL);
-	camel_url_set_path (url, temp);
-	g_free (temp);
-
-	temp = camel_url_to_string (url, 0);
 	service = camel_session_add_service (
-		CAMEL_SESSION (session), "local", temp,
+		CAMEL_SESSION (session),
+		"local", "maildir",
 		CAMEL_PROVIDER_STORE, &error);
-	g_free (temp);
 
 	camel_service_set_display_name (service, _("On This Computer"));
 
+	settings = camel_service_get_settings (service);
+
+	path = g_build_filename (data_dir, "local", NULL);
+	g_object_set (settings, "path", path, NULL);
+	g_free (path);
+
 	/* Shouldn't need to worry about other mail applications
 	 * altering files in our local mail store. */
 	g_object_set (service, "need-summary-check", FALSE, NULL);
@@ -114,8 +114,6 @@ e_mail_local_init (EMailSession *session,
 		}
 	}
 
-	camel_url_free (url);
-
 	local_store = g_object_ref (service);
 
 	return;
@@ -126,7 +124,6 @@ fail:
 		error->message);
 
 	g_error_free (error);
-	camel_url_free (url);
 }
 
 CamelFolder *
diff --git a/libemail-engine/e-mail-session.c b/libemail-engine/e-mail-session.c
index f4eab7e..7938230 100644
--- a/libemail-engine/e-mail-session.c
+++ b/libemail-engine/e-mail-session.c
@@ -332,11 +332,13 @@ mail_session_make_key (CamelService *service,
 {
 	gchar *key;
 
-	if (service != NULL)
-		key = camel_url_to_string (
-			camel_service_get_camel_url (service),
-			CAMEL_URL_HIDE_PARAMS);
-	else
+	if (service != NULL) {
+		CamelURL *url;
+
+		url = camel_service_new_camel_url (service);
+		key = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
+		camel_url_free (url);
+	} else
 		key = g_strdup (item);
 
 	return key;
@@ -593,7 +595,7 @@ mail_session_constructed (GObject *object)
 static CamelService *
 mail_session_add_service (CamelSession *session,
                           const gchar *uid,
-                          const gchar *url_string,
+                          const gchar *protocol,
                           CamelProviderType type,
                           GError **error)
 {
@@ -601,18 +603,51 @@ mail_session_add_service (CamelSession *session,
 
 	/* Chain up to parents add_service() method. */
 	service = CAMEL_SESSION_CLASS (e_mail_session_parent_class)->
-		add_service (session, uid, url_string, type, error);
+		add_service (session, uid, protocol, type, error);
 
 	/* Initialize the CamelSettings object from CamelURL parameters.
 	 * This is temporary; soon we'll read settings from key files. */
 
 	if (CAMEL_IS_SERVICE (service)) {
-		CamelSettings *settings;
-		CamelURL *url;
+		EAccount *account;
+		CamelURL *url = NULL;
 
-		settings = camel_service_get_settings (service);
-		url = camel_service_get_camel_url (service);
-		camel_settings_load_from_url (settings, url);
+		account = e_get_account_by_uid (uid);
+		if (account != NULL) {
+			const gchar *url_string = NULL;
+
+			switch (type) {
+				case CAMEL_PROVIDER_STORE:
+					url_string = account->source->url;
+					break;
+				case CAMEL_PROVIDER_TRANSPORT:
+					url_string = account->transport->url;
+					break;
+				default:
+					break;
+			}
+
+			if (url_string != NULL) {
+				url = camel_url_new (url_string, error);
+				if (url == NULL) {
+					g_object_unref (service);
+					service = NULL;
+				}
+			}
+		}
+
+		if (url != NULL) {
+			CamelSettings *settings;
+
+			settings = camel_service_get_settings (service);
+			camel_settings_load_from_url (settings, url);
+			camel_url_free (url);
+
+			/* Migrate files for this service from its old
+			 * URL-based directory to a UID-based directory
+			 * if necessary. */
+			camel_service_migrate_files (service);
+		}
 	}
 
 	return service;
@@ -979,7 +1014,7 @@ mail_session_authenticate_sync (CamelSession *session,
 	CamelServiceAuthType *authtype = NULL;
 	CamelAuthenticationResult result;
 	CamelProvider *provider;
-	CamelURL *url;
+	CamelSettings *settings;
 	const gchar *password;
 	guint32 password_flags;
 	GError *local_error = NULL;
@@ -987,8 +1022,8 @@ mail_session_authenticate_sync (CamelSession *session,
 	/* Do not chain up.  Camel's default method is only an example for
 	 * subclasses to follow.  Instead we mimic most of its logic here. */
 
-	url = camel_service_get_camel_url (service);
 	provider = camel_service_get_provider (service);
+	settings = camel_service_get_settings (service);
 
 	/* APOP is one case where a non-SASL mechanism name is passed, so
 	 * don't bail if the CamelServiceAuthType struct comes back NULL. */
@@ -1047,11 +1082,18 @@ retry:
 	password = camel_service_get_password (service);
 
 	if (password == NULL) {
+		CamelNetworkSettings *network_settings;
+		const gchar *host;
+		const gchar *user;
 		gchar *prompt;
 		gchar *new_passwd;
 
+		network_settings = CAMEL_NETWORK_SETTINGS (settings);
+		host = camel_network_settings_get_host (network_settings);
+		user = camel_network_settings_get_user (network_settings);
+
 		prompt = camel_session_build_password_prompt (
-			provider->name, url->user, url->host);
+			provider->name, user, host);
 
 		new_passwd = camel_session_get_password (
 			session, service, prompt, "password",
diff --git a/libemail-engine/e-mail-store.c b/libemail-engine/e-mail-store.c
index a3aeb82..e1a6148 100644
--- a/libemail-engine/e-mail-store.c
+++ b/libemail-engine/e-mail-store.c
@@ -299,52 +299,92 @@ e_mail_store_add_by_account (EMailSession *session,
 	CamelService *service = NULL;
 	CamelProvider *provider = NULL;
 	CamelURL *url;
-	gboolean skip = FALSE, transport_only;
+	gboolean transport_only;
+	gboolean service_is_local_delivery;
+	gboolean service_belongs_in_tree_model;
 	GError *error = NULL;
 
 	g_return_val_if_fail (E_IS_ACCOUNT (account), NULL);
 
 	/* check whether it's transport-only accounts */
-	transport_only = !account->source || !account->source->url || !*account->source->url;
+	transport_only =
+		(account->source == NULL) ||
+		(account->source->url == NULL) ||
+		(*account->source->url == '\0');
 	if (transport_only)
 		goto handle_transport;
 
 	/* Load the service, but don't connect.  Check its provider,
 	 * and if this belongs in the folder tree model, add it. */
 
-	provider = camel_provider_get (account->source->url, &error);
+	url = camel_url_new (account->source->url, NULL);
+	if (url != NULL) {
+		service_is_local_delivery =
+			em_utils_is_local_delivery_mbox_file (url);
+		provider = camel_provider_get (url->protocol, NULL);
+		camel_url_free (url);
+	} else {
+		service_is_local_delivery = FALSE;
+		provider = NULL;
+	}
+
 	if (provider == NULL) {
-	/* In case we do not have a provider here, we handle
-	 * the special case of having multiple mail identities
-	 * eg. a dummy account having just SMTP server defined */
+		/* In case we do not have a provider here, we handle
+		 * the special case of having multiple mail identities
+		 * eg. a dummy account having just SMTP server defined */
 		goto handle_transport;
 	}
 
 	service = camel_session_add_service (
 		CAMEL_SESSION (session),
-		account->uid, account->source->url,
+		account->uid, provider->protocol,
 		CAMEL_PROVIDER_STORE, &error);
 
+	if (!CAMEL_IS_STORE (service))
+		goto fail;
+
 	camel_service_set_display_name (service, account->name);
 
+	service_belongs_in_tree_model =
+		(provider->flags & CAMEL_PROVIDER_IS_STORAGE) &&
+		!service_is_local_delivery;
+
+	if (service_belongs_in_tree_model && store_table != NULL)
+		e_mail_store_add (backend, CAMEL_STORE (service));
+
 handle_transport:
 
+	/* While we're at it, add the account's transport (if it has one)
+	 * to the CamelSession.  The transport's UID is a kludge for now.
+	 * We take the EAccount's UID and tack on "-transport". */
+
 	if (account->transport) {
-		/* While we're at it, add the account's transport to the
-		 * CamelSession.  The transport's UID is a kludge for now.
-		 * We take the EAccount's UID and tack on "-transport". */
-		gchar *transport_uid;
 		GError *transport_error = NULL;
 
-		transport_uid = g_strconcat (
-			account->uid, "-transport", NULL);
+		url = camel_url_new (
+			account->transport->url,
+			&transport_error);
+
+		if (url != NULL) {
+			provider = camel_provider_get (
+				url->protocol, &transport_error);
+			camel_url_free (url);
+		} else
+			provider = NULL;
 
-		camel_session_add_service (
-			CAMEL_SESSION (session),
-			transport_uid, account->transport->url,
-			CAMEL_PROVIDER_TRANSPORT, &transport_error);
+		if (provider != NULL) {
+			gchar *transport_uid;
 
-		g_free (transport_uid);
+			transport_uid = g_strconcat (
+				account->uid, "-transport", NULL);
+
+			camel_session_add_service (
+				CAMEL_SESSION (session),
+				transport_uid, provider->protocol,
+				CAMEL_PROVIDER_TRANSPORT, &transport_error);
+
+			g_free (transport_uid);
+		}
 
 		if (transport_error) {
 			g_warning (
@@ -357,21 +397,6 @@ handle_transport:
 	if (transport_only)
 		return NULL;
 
-	if (!CAMEL_IS_STORE (service))
-		goto fail;
-
-	/* Do not add local-delivery files,
-	 * but make them ready for later use. */
-	url = camel_url_new (account->source->url, NULL);
-	if (url != NULL) {
-		skip = em_utils_is_local_delivery_mbox_file (url);
-		camel_url_free (url);
-	}
-
-	if (!skip && (provider->flags & CAMEL_PROVIDER_IS_STORAGE) != 0 && store_table != NULL)
-		
-		e_mail_store_add (session, CAMEL_STORE (service));
-
 	return CAMEL_STORE (service);
 
 fail:
diff --git a/libemail-engine/mail-ops.c b/libemail-engine/mail-ops.c
index 766c70e..6fac9cd 100644
--- a/libemail-engine/mail-ops.c
+++ b/libemail-engine/mail-ops.c
@@ -211,8 +211,8 @@ fetch_mail_exec (struct _fetch_mail_msg *m,
 	struct _filter_mail_msg *fm = (struct _filter_mail_msg *) m;
 	CamelFolder *folder = NULL;
 	CamelURL *url;
+	gboolean is_local_delivery;
 	const gchar *uid;
-	gboolean is_local_delivery = FALSE;
 	gint i;
 
 	fm->destination = e_mail_local_get_folder (
@@ -221,8 +221,9 @@ fetch_mail_exec (struct _fetch_mail_msg *m,
 		goto fail;
 	g_object_ref (fm->destination);
 
-	url = camel_service_get_camel_url (CAMEL_SERVICE (m->store));
+	url = camel_service_new_camel_url (CAMEL_SERVICE (m->store));
 	is_local_delivery = em_utils_is_local_delivery_mbox_file (url);
+
 	if (is_local_delivery) {
 		gchar *path;
 		gchar *url_string;
@@ -253,6 +254,8 @@ fetch_mail_exec (struct _fetch_mail_msg *m,
 				fm->session, uid, cancellable, error);
 	}
 
+	camel_url_free (url);
+
 	if (folder != NULL) {
 		/* This handles 'keep on server' stuff, if we have any new
 		 * uid's to copy across, we need to copy them to a new array
@@ -551,9 +554,10 @@ mail_send_message (struct _send_queue_msg *m,
 		gchar *url_string;
 		gchar *escaped;
 
-		url = camel_service_get_camel_url (CAMEL_SERVICE (transport));
+		url = camel_service_new_camel_url (CAMEL_SERVICE (transport));
 		url_string = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
 		escaped = escape_percent_sign (url_string);
+		camel_url_free (url);
 
 		/* Let the dialog know the right account it is using. */
 		report_status (m, CAMEL_FILTER_STATUS_ACTION, 0, escaped);
@@ -1192,8 +1196,9 @@ sync_store_desc (struct _sync_store_msg *m)
 	CamelURL *url;
 	gchar *uri, *res;
 
-	url = camel_service_get_camel_url (CAMEL_SERVICE (m->store));
+	url = camel_service_new_camel_url (CAMEL_SERVICE (m->store));
 	uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
+	camel_url_free (url);
 
 	res = g_strdup_printf (m->expunge
 			      ?_("Expunging and storing account '%s'")
diff --git a/libemail-engine/mail-tools.c b/libemail-engine/mail-tools.c
index 135df53..82b2146 100644
--- a/libemail-engine/mail-tools.c
+++ b/libemail-engine/mail-tools.c
@@ -88,16 +88,23 @@ mail_tool_do_movemail (CamelStore *store,
                        GError **error)
 {
 #ifndef G_OS_WIN32
+	CamelService *service;
+	CamelProvider *provider;
+	CamelSettings *settings;
+	const gchar *src_path;
 	gchar *dest_path;
 	struct stat sb;
-	CamelURL *url;
 	gboolean success;
 
 	g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
 
-	url = camel_service_get_camel_url (CAMEL_SERVICE (store));
+	service = CAMEL_SERVICE (store);
+	provider = camel_service_get_provider (service);
+	settings = camel_service_get_settings (service);
 
-	if (strcmp (url->protocol, "mbox") != 0) {
+	g_return_val_if_fail (provider != NULL, NULL);
+
+	if (g_strcmp0 (provider->protocol, "mbox") != 0) {
 		/* This is really only an internal error anyway */
 		g_set_error (
 			error, CAMEL_SERVICE_ERROR,
@@ -107,13 +114,16 @@ mail_tool_do_movemail (CamelStore *store,
 		return NULL;
 	}
 
+	src_path = camel_local_settings_get_path (
+		CAMEL_LOCAL_SETTINGS (settings));
+
 	/* Set up our destination. */
 	dest_path = mail_tool_get_local_movemail_path (store, error);
 	if (dest_path == NULL)
 		return NULL;
 
-	/* Movemail from source (source_url) to dest_path */
-	success = camel_movemail (url->path, dest_path, error) != -1;
+	/* Movemail from source to dest_path */
+	success = camel_movemail (src_path, dest_path, error) != -1;
 
 	if (g_stat (dest_path, &sb) < 0 || sb.st_size == 0) {
 		g_unlink (dest_path); /* Clean up the movemail.foo file. */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]