diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-05-06 04:02:56 +0800 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2011-06-30 00:42:08 +0800 |
commit | ebf7390977a456a303e5a599e4a34755a42a4490 (patch) | |
tree | 4f898e5498515edc94a20c7abbd98cac62ae679e | |
parent | 0ef04d982b73248fa222035933164be55e8f48c0 (diff) | |
download | gsoc2013-evolution-ebf7390977a456a303e5a599e4a34755a42a4490.tar gsoc2013-evolution-ebf7390977a456a303e5a599e4a34755a42a4490.tar.gz gsoc2013-evolution-ebf7390977a456a303e5a599e4a34755a42a4490.tar.bz2 gsoc2013-evolution-ebf7390977a456a303e5a599e4a34755a42a4490.tar.lz gsoc2013-evolution-ebf7390977a456a303e5a599e4a34755a42a4490.tar.xz gsoc2013-evolution-ebf7390977a456a303e5a599e4a34755a42a4490.tar.zst gsoc2013-evolution-ebf7390977a456a303e5a599e4a34755a42a4490.zip |
Introduce a new, simpler folder URI format.
Folder URIs shall henceforth be exclusive to Evolution.
The new format is:
'folder://' CAMEL_STORE_UID '/' CAMEL_FOLDER_PATH
Add e_mail_folder_uri_build() to construct such a URI from a CamelStore
and folder path string, change e_mail_folder_uri_from_folder() to build
the new URI, and teach e_mail_folder_uri_parse() to parse it.
e_mail_folder_uri_parse() will continue to know how to parse the older
URI formats still present in config files and GConf keys. This captures
the legacy knowledge neatly into one function.
-rw-r--r-- | mail/e-mail-folder-utils.c | 71 | ||||
-rw-r--r-- | mail/e-mail-folder-utils.h | 2 |
2 files changed, 65 insertions, 8 deletions
diff --git a/mail/e-mail-folder-utils.c b/mail/e-mail-folder-utils.c index 3c87ca4de0..fbd2dd3055 100644 --- a/mail/e-mail-folder-utils.c +++ b/mail/e-mail-folder-utils.c @@ -163,6 +163,40 @@ e_mail_folder_append_message_finish (CamelFolder *folder, } /** + * e_mail_folder_uri_build: + * @store: a #CamelStore + * @folder_name: a folder name + * + * Builds a folder URI string from @store and @folder_name. + * + * Returns: a newly-allocated folder URI string + **/ +gchar * +e_mail_folder_uri_build (CamelStore *store, + const gchar *folder_name) +{ + const gchar *uid; + gchar *encoded_uid; + gchar *uri; + + g_return_val_if_fail (CAMEL_IS_STORE (store), NULL); + g_return_val_if_fail (folder_name != NULL, NULL); + + /* Skip the leading slash, if present. */ + if (*folder_name == '/') + folder_name++; + + uid = camel_service_get_uid (CAMEL_SERVICE (store)); + encoded_uid = camel_url_encode (uid, ":;@/"); + + uri = g_strdup_printf ("folder://%s/%s", encoded_uid, folder_name); + + g_free (encoded_uid); + + return uri; +} + +/** * e_mail_folder_uri_parse: * @session: a #CamelSession * @folder_uri: a folder URI @@ -170,16 +204,21 @@ e_mail_folder_append_message_finish (CamelFolder *folder, * @out_folder_name: return location for a folder name, or %NULL * @error: return location for a #GError, or %NULL * - * Parses a folder URI and returns the corresponding #CamelStore instance - * in @out_store and folder name string in @out_folder_name. If the URI - * is malformed or no corresponding store exists, the function sets @error - * and returns %FALSE. + * Parses a folder URI generated by e_mail_folder_uri_build() and + * returns the corresponding #CamelStore instance in @out_store and + * folder name string in @out_folder_name. If the URI is malformed + * or no corresponding store exists, the function sets @error and + * returns %FALSE. * * If the function is able to parse the URI, the #CamelStore instance * set in @out_store should be unreferenced with g_object_unref() when * done with it, and the folder name string set in @out_folder_name * should be freed with g_free(). * + * The function also handles older style URIs, such as ones where the + * #CamelStore's #CamelStore::uri string was embedded directly in the + * folder URI, and account-based URIs that used an "email://" prefix. + * * Returns: %TRUE if @folder_uri could be parsed, %FALSE otherwise **/ gboolean @@ -201,6 +240,19 @@ e_mail_folder_uri_parse (CamelSession *session, if (url == NULL) return FALSE; + /* Current URI Format: 'folder://' STORE_UID '/' FOLDER_PATH */ + if (g_strcmp0 (url->protocol, "folder") == 0) { + + if (url->host != NULL) { + gchar *uid = g_strdup (url->host); + camel_url_decode (uid); + service = camel_session_get_service (session, uid); + g_free (uid); + } + + if (url->path != NULL && *url->path == '/') + folder_name = url->path + 1; + /* This style was used to reference accounts by UID before * CamelServices themselves had UIDs. Some examples are: * @@ -217,7 +269,7 @@ e_mail_folder_uri_parse (CamelSession *session, * the STORE_UIDs for the special cases are 'local' * and 'vfolder'. */ - if (g_strcmp0 (url->protocol, "email") == 0) { + } else if (g_strcmp0 (url->protocol, "email") == 0) { gchar *uid = NULL; /* Handle the special cases. */ @@ -360,10 +412,13 @@ exit: gchar * e_mail_folder_uri_from_folder (CamelFolder *folder) { + CamelStore *store; + const gchar *folder_name; + g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL); - /* XXX This looks silly because it's just a temporary - * implementation. I have other plans in store. */ + store = camel_folder_get_parent_store (folder); + folder_name = camel_folder_get_full_name (folder); - return g_strdup (camel_folder_get_uri (folder)); + return e_mail_folder_uri_build (store, folder_name); } diff --git a/mail/e-mail-folder-utils.h b/mail/e-mail-folder-utils.h index 3187acfdf2..0d2f0ca0f9 100644 --- a/mail/e-mail-folder-utils.h +++ b/mail/e-mail-folder-utils.h @@ -45,6 +45,8 @@ gboolean e_mail_folder_append_message_finish gchar **appended_uid, GError **error); +gchar * e_mail_folder_uri_build (CamelStore *store, + const gchar *folder_name); gboolean e_mail_folder_uri_parse (CamelSession *session, const gchar *folder_uri, CamelStore **out_store, |