[evolution/wip/gsettings] e_get_account_by_uid(): Also handle CamelTransport UIDs.



commit c54a329d969f632a739b6fe76a78db7cc15bbd66
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon May 2 12:24:12 2011 -0400

    e_get_account_by_uid(): Also handle CamelTransport UIDs.
    
    Enhance e_get_account_by_uid() to also accept CamelTransport UIDs.
    
    The convention we use to distinguish them is simple:
    
       Given an EAccount UID:
    
       - The CamelStore UID is the EAccount UID verbatim.
    
       - The CamelTransport UID is the EAccount UID + "-transport".
    
    So just check for a "-transport" suffix and truncate it.

 e-util/e-account-utils.c |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/e-util/e-account-utils.c b/e-util/e-account-utils.c
index d6dfa7a..aedf4f1 100644
--- a/e-util/e-account-utils.c
+++ b/e-util/e-account-utils.c
@@ -22,6 +22,7 @@
 
 #include "e-account-utils.h"
 
+#include <string.h>
 #include <gconf/gconf-client.h>
 
 static EAccountList *global_account_list;
@@ -136,10 +137,11 @@ e_get_account_by_name (const gchar *name)
  * e_get_account_by_uid:
  * @uid: a mail account UID
  *
- * Returns the #EAccount with the given unique ID, or %NULL if no such
- * account exists.
+ * Returns the #EAccount corresponding to the given unique identity (UID),
+ * or %NULL if no such account exists.  The @uid can refer to an #EAccount
+ * UID, a #CamelStore UID, or even a #CamelTransport UID.
  *
- * Returns: an #EAccount having the given unique ID, or %NULL
+ * Returns: the corresponding #EAccount, or %NULL
  **/
 EAccount *
 e_get_account_by_uid (const gchar *uid)
@@ -147,12 +149,27 @@ e_get_account_by_uid (const gchar *uid)
 	EAccountList *account_list;
 	const EAccount *account;
 	e_account_find_t find;
+	gchar *account_uid;
 
 	g_return_val_if_fail (uid != NULL, NULL);
 
+	/* EAccounts have the following invariant:
+	 *
+	 *       CamelStore UID == EAccount UID
+	 *   CamelTransport UID == EAccount UID + "-transport"
+	 *
+	 * Therefore we can detect CamelTransport UIDs and convert them.
+	 */
+	if (g_str_has_suffix (uid, "-transport"))
+		account_uid = g_strndup (uid, strlen (uid) - 10);
+	else
+		account_uid = g_strdup (uid);
+
 	find = E_ACCOUNT_FIND_UID;
 	account_list = e_get_account_list ();
-	account = e_account_list_find (account_list, find, uid);
+	account = e_account_list_find (account_list, find, account_uid);
+
+	g_free (account_uid);
 
 	/* XXX EAccountList misuses const. */
 	return (EAccount *) account;



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