From fb297c913c11347b2b9719119c710022ad7d086d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 17 Aug 2012 17:56:25 +0000 Subject: [PATCH] Monotone-Parent: 1fb3121c84e0bb2773973fcfde109c7b26530951 Monotone-Revision: e2f910a1982b774a3f5dfd586d968821441f2076 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-08-17T17:56:25 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 ++++++ OpenChange/MAPIStoreContext.m | 14 +++++++++----- OpenChange/MAPIStoreFolder.m | 9 ++++++--- OpenChange/MAPIStoreMailContext.m | 7 +++++-- OpenChange/MAPIStoreMailFolder.m | 13 ++++++------- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1401d6101..0750a45db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-08-17 Wolfgang Sourdeau + + * OpenChange/MAPIStoreContext.m (-getPath:ofFMID:inMemCtx:): + properly escape urls containing non-ascii chars. + (-getRootFoldeR:withFID:): idem. + 2012-08-16 Wolfgang Sourdeau * OpenChange/MAPIStoreCalendarMessage.m diff --git a/OpenChange/MAPIStoreContext.m b/OpenChange/MAPIStoreContext.m index a3704289b..6899aa202 100644 --- a/OpenChange/MAPIStoreContext.m +++ b/OpenChange/MAPIStoreContext.m @@ -366,7 +366,8 @@ static inline NSURL *CompleteURLFromMapistoreURI (const char *uri) NSString *objectURL, *url; // TDB_DATA key, dbuf; - url = [contextUrl absoluteString]; + url = [[contextUrl absoluteString] + stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; objectURL = [[userContext mapping] urlFromID: fmid]; if (objectURL) { @@ -417,15 +418,18 @@ static inline NSURL *CompleteURLFromMapistoreURI (const char *uri) MAPIStoreFolder *baseFolder; SOGoFolder *currentFolder; WOContext *woContext; - NSString *path; + NSString *path, *urlString; NSArray *pathComponents; NSUInteger count, max; mapping = [userContext mapping]; if (![mapping urlFromID: newFid]) - [mapping registerURL: [contextUrl absoluteString] - withID: newFid]; - + { + urlString = [[contextUrl absoluteString] + stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; + [mapping registerURL: urlString + withID: newFid]; + } [userContext activateWithUser: activeUser]; woContext = [userContext woContext]; diff --git a/OpenChange/MAPIStoreFolder.m b/OpenChange/MAPIStoreFolder.m index 5d5da9a07..5cf2bf834 100644 --- a/OpenChange/MAPIStoreFolder.m +++ b/OpenChange/MAPIStoreFolder.m @@ -94,12 +94,14 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe { NSURL *folderURL; NSMutableString *pathPrefix; - NSString *path, *folderName; + NSString *path, *escapedURL, *folderName; NSArray *parts; NSUInteger lastPartIdx; MAPIStoreUserContext *userContext; - folderURL = [NSURL URLWithString: [self url]]; + escapedURL = [[self url] + stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; + folderURL = [NSURL URLWithString: escapedURL]; path = [folderURL path]; path = [path substringFromIndex: 1]; if ([path length] > 0) @@ -1495,7 +1497,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe url = [NSString stringWithFormat: @"%@/", [super url]]; else { - url = [[context url] absoluteString]; + url = [[[context url] absoluteString] + stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; if (![url hasSuffix: @"/"]) url = [NSString stringWithFormat: @"%@/", url]; } diff --git a/OpenChange/MAPIStoreMailContext.m b/OpenChange/MAPIStoreMailContext.m index 8046c994c..e687a02b8 100644 --- a/OpenChange/MAPIStoreMailContext.m +++ b/OpenChange/MAPIStoreMailContext.m @@ -206,12 +206,14 @@ MakeDisplayFolderName (NSString *folderName) - (void) updateURLWithFolderName: (NSString *) newFolderName { - NSString *urlString; + NSString *urlString, *escapedName; NSMutableArray *pathComponents; BOOL hasSlash; NSUInteger max, folderNameIdx; NSURL *newURL; + /* we do not need to unescape the url here as it will be reassembled later + in the method */ urlString = [contextUrl absoluteString]; hasSlash = [urlString hasSuffix: @"/"]; pathComponents = [[urlString componentsSeparatedByString: @"/"] @@ -222,8 +224,9 @@ MakeDisplayFolderName (NSString *folderName) folderNameIdx = max - 2; else folderNameIdx = max - 1; + escapedName = [newFolderName stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; [pathComponents replaceObjectAtIndex: folderNameIdx - withObject: [newFolderName stringByEscapingURL]]; + withObject: escapedName]; urlString = [pathComponents componentsJoinedByString: @"/"]; newURL = [NSURL URLWithString: urlString]; ASSIGN (contextUrl, newURL); diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 45e3c7c91..fc1a4278d 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -1046,15 +1046,15 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) folderURL = [sogoObject imap4URL]; if (!newFolderName) newFolderName = [sogoObject displayName]; - newFolderName = [newFolderName stringByEscapingURL]; targetSOGoFolder = [targetFolder sogoObject]; - newFolderURL = [NSURL URLWithString: newFolderName - relativeToURL: [targetSOGoFolder imap4URL]]; if (isMove) { + newFolderURL = [NSURL + URLWithString: [newFolderName stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding] + relativeToURL: [targetSOGoFolder imap4URL]]; error = [[sogoObject imap4Connection] - moveMailboxAtURL: folderURL - toURL: newFolderURL]; + moveMailboxAtURL: folderURL + toURL: newFolderURL]; if (error) rc = MAPISTORE_ERR_DENIED; else @@ -1063,8 +1063,7 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) mapping = [self mapping]; newURL = [NSString stringWithFormat: @"%@folder%@/", [targetFolder url], newFolderName]; - [mapping updateID: [self objectId] - withURL: newURL]; + [mapping updateID: [self objectId] withURL: newURL]; parentDBFolderPath = [[targetFolder dbFolder] path]; if (!parentDBFolderPath) parentDBFolderPath = @"";