[evolution] Simplify mail_session_get_password().



commit 7c8489e9d644c5e101a5c74bbc393868d957532a
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon May 2 15:54:54 2011 -0400

    Simplify mail_session_get_password().
    
    Utilizes the new capability in e_get_account_by_uid() to handle both
    CamelStore and CamelTransport UIDs.

 mail/e-mail-session.c |   29 +++++++++++++----------------
 1 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/mail/e-mail-session.c b/mail/e-mail-session.c
index 8f76506..1ceb98f 100644
--- a/mail/e-mail-session.c
+++ b/mail/e-mail-session.c
@@ -603,24 +603,23 @@ mail_session_get_password (CamelSession *session,
                            guint32 flags,
                            GError **error)
 {
-	gchar *url = NULL;
-	gchar *ret = NULL;
 	EAccount *account = NULL;
+	const gchar *uid = NULL;
+	gchar *ret = NULL;
 
-	if (service != NULL) {
-		CamelURL *service_url;
-
-		service_url = camel_service_get_camel_url (service);
-		url = camel_url_to_string (service_url, CAMEL_URL_HIDE_ALL);
+	if (CAMEL_IS_SERVICE (service)) {
+		uid = camel_service_get_uid (service);
+		account = e_get_account_by_uid (uid);
 	}
 
 	if (!strcmp(item, "popb4smtp_uid")) {
 		/* not 100% mt safe, but should be ok */
-		if (url
-		    && (account = e_get_account_by_transport_url (url)))
+		if (account != NULL)
 			ret = g_strdup (account->source->url);
-		else
-			ret = g_strdup (url);
+		else if (CAMEL_IS_SERVICE (service)) {
+			CamelURL *url = camel_service_get_camel_url (service);
+			ret = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
+		}
 	} else {
 		gchar *key = mail_session_make_key (service, item);
 		EAccountService *config_service = NULL;
@@ -635,10 +634,10 @@ mail_session_get_password (CamelSession *session,
 			g_free (ret);
 			ret = NULL;
 
-			if (url) {
-				if  ((account = e_get_account_by_source_url (url)))
+			if (account != NULL) {
+				if (CAMEL_IS_STORE (service))
 					config_service = account->source;
-				else if ((account = e_get_account_by_transport_url (url)))
+				if (CAMEL_IS_TRANSPORT (service))
 					config_service = account->transport;
 			}
 
@@ -704,8 +703,6 @@ mail_session_get_password (CamelSession *session,
 		g_free (key);
 	}
 
-	g_free (url);
-
 	if (ret == NULL)
 		g_set_error (
 			error, G_IO_ERROR,



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