From f52c1d20c671f438c05727cfcbf16f19c522d2f3 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 2 May 2011 12:24:12 -0400 Subject: 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 file changed, 21 insertions(+), 4 deletions(-) (limited to 'e-util') diff --git a/e-util/e-account-utils.c b/e-util/e-account-utils.c index d6dfa7aea3..aedf4f1c29 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 #include 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; -- cgit v1.2.3