diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 7d99cebc5..d2509bae2 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -212,11 +212,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO]; currentFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO]; - - newFolder = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@", [displayName stringByEncodingImap4FolderName]] - inContext: context - acquire: NO]; - + + // If the parrent is 0 -> ok ; otherwise need to build the foldername based on parentId + displayName + if ([parentId isEqualToString: @"0"]) + newFolder = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@", [displayName stringByEncodingImap4FolderName]] + inContext: context + acquire: NO]; + else + newFolder = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@/%@", [[parentId stringByUnescapingURL] substringFromIndex: 5], + [displayName stringByEncodingImap4FolderName]] + inContext: context + acquire: NO]; + // FIXME // handle exists (status == 2) // handle right synckey @@ -380,7 +387,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. inContext: context acquire: NO]; - error = [folderToUpdate renameTo: displayName]; + // If parent is 0 or displayname is not changed it is either a rename of a folder in 0 or a move to 0 + if ([parentId isEqualToString: @"0"] || + ([serverId hasSuffix: [NSString stringWithFormat: @"/%@", displayName]] && [parentId isEqualToString: @"0"])) + { + error = [folderToUpdate renameTo: [NSString stringWithFormat: @"/%@", [displayName stringByEncodingImap4FolderName]]]; + } + else + { + error = [folderToUpdate renameTo: [NSString stringWithFormat: @"%@/%@", [[parentId stringByUnescapingURL] substringFromIndex: 5], + [displayName stringByEncodingImap4FolderName]]]; + } // Handle new name exist if (!error) diff --git a/NEWS b/NEWS index c4138d3d1..962e44763 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ Bug fixes - fixed iCal7 delegation issue with the "inbox" folder (#2489) - fixed birth date validity checks (#1636) - fixed URL handling (#2616) + - improved folder rename operations using ActiveSync (#2700) 2.2.3 (2014-04-03) ------------------ diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 7f45ec814..64088280c 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -291,10 +291,18 @@ static NSString *defaultUserID = @"anyone"; path = [[imap4URL path] stringByDeletingLastPathComponent]; if (![path hasSuffix: @"/"]) path = [path stringByAppendingString: @"/"]; - destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme] - host: [imap4URL host] - path: [NSString stringWithFormat: @"%@%@", - path, [newName stringByEncodingImap4FolderName]]]; + + // If new name contains the path - dont't need to add + if ([newName rangeOfString: @"/"].location == NSNotFound) + destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme] + host: [imap4URL host] + path: [NSString stringWithFormat: @"%@%@", + path, [newName stringByEncodingImap4FolderName]]]; + else + destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme] + host: [imap4URL host] + path: [NSString stringWithFormat: @"%@", + [newName stringByEncodingImap4FolderName]]]; [destURL autorelease]; error = [imap4 moveMailboxAtURL: imap4URL toURL: destURL];