X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-account-mgr-priv.c;h=d0c80f6e3cdc48c64dd489fc5e9910b06666a74c;hb=9d8de13bc46137931a2790969dcb1fb932c7bcc6;hp=653149ec625f6d2902b4911173c8ff2d3e3f0dfa;hpb=5024de84b7959b0b3373176d8c1f91a73427ff88;p=modest diff --git a/src/modest-account-mgr-priv.c b/src/modest-account-mgr-priv.c index 653149e..d0c80f6 100644 --- a/src/modest-account-mgr-priv.c +++ b/src/modest-account-mgr-priv.c @@ -32,10 +32,18 @@ #include #include #include +#include gchar* _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account) { + /* Initialize input parameters: */ + if (is_account_key) + *is_account_key = FALSE; + + if (is_server_account) + *is_server_account = FALSE; + const gchar* account_ns = MODEST_ACCOUNT_NAMESPACE "/"; const gchar* server_account_ns = MODEST_SERVER_ACCOUNT_NAMESPACE "/"; gchar *cursor; @@ -71,7 +79,13 @@ _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key if (cursor) *cursor = '\0'; - return account; + if (account) { + /* The key is an escaped string, so unescape it to get the actual account name: */ + gchar *unescaped_name = modest_conf_key_unescape (account); + g_free (account); + return unescaped_name; + } else + return NULL; } @@ -80,32 +94,31 @@ _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key gchar * _modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account) { - gchar *namespace; - gchar *retval; + gchar *retval = NULL; - namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE; + gchar *namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE; if (!account_name) return g_strdup (namespace); - if (name) - retval = g_strconcat (namespace, "/", account_name, "/", name, NULL); - else - retval = g_strconcat (namespace, "/", account_name, NULL); + /* Always escape the conf keys, so that it is acceptable to gconf: */ + gchar *escaped_account_name = account_name ? modest_conf_key_escape (account_name) : NULL; + gchar *escaped_name = name ? modest_conf_key_escape (name) : NULL; - /* special case: the key has some weird characters */ - if (!modest_conf_key_is_valid (retval)) { + if (escaped_account_name && escaped_name) + retval = g_strconcat (namespace, "/", escaped_account_name, "/", escaped_name, NULL); + else if (escaped_account_name) + retval = g_strconcat (namespace, "/", escaped_account_name, NULL); - gchar *account_name_esc, *name_esc; + /* Sanity check: */ + if (!modest_conf_key_is_valid (retval)) { + g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__, retval); g_free (retval); - - account_name_esc = account_name ? modest_conf_key_escape (account_name) : NULL; - name_esc = name ? modest_conf_key_escape (name) : NULL; - - retval = _modest_account_mgr_get_account_keyname (account_name_esc, name_esc, server_account); - - g_free (account_name_esc); - g_free (name_esc); + retval = NULL; } + + g_free (escaped_name); + g_free (escaped_account_name); + return retval; }