From 68c38e2b5c0958a4ec96b56c2e0c16948fa73307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20S=C3=A1ez?= Date: Tue, 29 Jul 2014 18:51:37 +0200 Subject: [PATCH] openchange: return proper url for folders with non-ascii chars toManyRelationshipKeysWithNamespaces applies asCSSIdentifier function to the names which are already "Imap4Encoded". So we need to remove the CSSIdentifier function first and then "Imap4Decode" to get the real name. Once we have the real name, to create the url we have to use the same logic as the function that creates the folder and creates this url for the first time (this function is createRootSecondaryFolderWithFID) which is to apply, in this order: - asCSSIdentifier - stringByEncodingImap4FolderName - stringByAddingPercentEscapesUsingEncoding --- OpenChange/MAPIStoreMailContext.m | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/OpenChange/MAPIStoreMailContext.m b/OpenChange/MAPIStoreMailContext.m index 24d974e5a..0cddee582 100644 --- a/OpenChange/MAPIStoreMailContext.m +++ b/OpenChange/MAPIStoreMailContext.m @@ -87,7 +87,7 @@ MakeDisplayFolderName (NSString *folderName) inMemCtx: (TALLOC_CTX *) memCtx { struct mapistore_contexts_list *firstContext = NULL, *context; - NSString *urlBase, *stringData, *currentName, *inboxName, *draftsName, *sentName, *trashName; + NSString *urlBase, *stringData, *currentName, *realName, *inboxName, *draftsName, *sentName, *trashName; NSArray *unprefixedFolders; NSMutableArray *secondaryFolders; enum mapistore_context_role role[] = {MAPISTORE_MAIL_ROLE, @@ -153,12 +153,23 @@ MakeDisplayFolderName (NSString *folderName) for (count = 0; count < max; count++) { context = talloc_zero (memCtx, struct mapistore_contexts_list); + // secondaryFolders has the names (1) Imap4Encoded and (2) asCSSIdentifier + // e.g.: Probl&AOg-mes_SP_de_SP_synchronisation currentName = [secondaryFolders objectAtIndex: count]; - stringData = [NSString stringWithFormat: @"%@%@", - urlBase, [currentName stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; - context->url = [stringData asUnicodeInMemCtx: context]; - stringData = [[[currentName substringFromIndex: 6] fromCSSIdentifier] stringByDecodingImap4FolderName]; - context->name = [stringData asUnicodeInMemCtx: context]; + // To get the real name we have to revert that (applying the decode functions) + // in reverse order + // e.g.: Problèmes de synchronisation + realName = [[currentName fromCSSIdentifier] + stringByDecodingImap4FolderName]; + // And finally to represent that as URI we have to (1) asCSSIdentifier, + // (2) Imap4Encode and (3) AddPercentEscapes + // e.g.: Probl&AOg-mes_SP_de_SP_synchronisation + // In the example there are no percent escapes added because is already ok + stringData = [[[realName asCSSIdentifier] + stringByEncodingImap4FolderName] + stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; + context->url = [[NSString stringWithFormat: @"%@%@", urlBase, stringData] asUnicodeInMemCtx: context]; + context->name = [[realName substringFromIndex: 6] asUnicodeInMemCtx: context]; context->main_folder = false; context->role = MAPISTORE_MAIL_ROLE; context->tag = "tag";