From 47afdfcd40899a7203df7ccc1d1a2d4c9b4e27bf Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 15 Aug 2012 13:13:15 +0000 Subject: [PATCH] Monotone-Parent: de4fcfa81509a5dd3cc5acd2a1c6ba7c97653649 Monotone-Revision: 85e37dbc7e87a173193494e6234f460788904318 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-08-15T13:13:15 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 ++ OpenChange/MAPIStoreDBFolder.m | 2 + OpenChange/MAPIStoreFolder.h | 3 - OpenChange/MAPIStoreFolder.m | 9 +-- OpenChange/MAPIStoreMailFolder.m | 106 +++++++++++++++++++++++++------ OpenChange/MAPIStoreSOGo.m | 7 +- 6 files changed, 99 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e5b86f9e..bfa5a5120 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-08-15 Wolfgang Sourdeau + + * OpenChange/MAPIStoreMailFolder.m + (-moveCopyToFolder:withNewName:isMove:isRecursive:): implemented + IMAP-based copy operation, for speed. + 2012-08-14 Wolfgang Sourdeau * OpenChange/MAPIStoreFolder.m (-moveToFolder:withNewName:): diff --git a/OpenChange/MAPIStoreDBFolder.m b/OpenChange/MAPIStoreDBFolder.m index 8b89202f4..0306c2012 100644 --- a/OpenChange/MAPIStoreDBFolder.m +++ b/OpenChange/MAPIStoreDBFolder.m @@ -157,6 +157,8 @@ static NSString *MAPIStoreRightFolderContact = @"RightsFolderContact"; [mapping updateID: [self objectId] withURL: newURL]; + [targetFolder cleanupCaches]; + rc = MAPISTORE_SUCCESS; } else diff --git a/OpenChange/MAPIStoreFolder.h b/OpenChange/MAPIStoreFolder.h index b31f8ce49..ccf3c800c 100644 --- a/OpenChange/MAPIStoreFolder.h +++ b/OpenChange/MAPIStoreFolder.h @@ -127,9 +127,6 @@ withNewName: (NSString *) newFolderName isMove: (BOOL) isMove isRecursive: (BOOL) isRecursive; -- (enum mapistore_error) copyToFolder: (MAPIStoreFolder *) targetFolder - recursive: (BOOL) resursive - withNewName: (NSString *) newFolderName; - (int) getDeletedFMIDs: (struct I8Array_r **) fmidsPtr andCN: (uint64_t *) cnPtr diff --git a/OpenChange/MAPIStoreFolder.m b/OpenChange/MAPIStoreFolder.m index 606c4a7cd..5d5da9a07 100644 --- a/OpenChange/MAPIStoreFolder.m +++ b/OpenChange/MAPIStoreFolder.m @@ -806,6 +806,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe childKey = [children objectAtIndex: count]; message = [self lookupMessage: childKey]; targetMessage = [newFolder createMessage: NO]; + [targetMessage setIsNew: YES]; [message copyToMessage: targetMessage]; if (isMove) { @@ -826,6 +827,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe childKey = [children objectAtIndex: count]; message = [self lookupFAIMessage: childKey]; targetMessage = [newFolder createMessage: YES]; + [targetMessage setIsNew: YES]; [message copyToMessage: targetMessage]; if (isMove) { @@ -872,13 +874,6 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe return rc; } -- (enum mapistore_error) copyToFolder: (MAPIStoreFolder *) targetFolder - recursive: (BOOL) resursive - withNewName: (NSString *) newFolderName -{ - return MAPISTORE_ERR_DENIED; -} - - (SOGoFolder *) aclFolder { [self subclassResponsibility: _cmd]; diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 787d1db45..deaef0c15 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -1019,12 +1019,21 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) { enum mapistore_error rc; NSURL *folderURL, *newFolderURL; + struct SRow folderRow; + struct SPropValue nameProperty; + MAPIStoreMailFolder *newFolder; SOGoMailFolder *targetSOGoFolder; - NSString *newURL, *parentDBFolderPath; + NSMutableArray *uids; + NSArray *childKeys; + NSUInteger count, max; + NGImap4Connection *connection; + NGImap4Client *client; + NSString *newURL, *parentDBFolderPath, *childKey, *folderIMAPName, *newFolderIMAPName; NSException *error; MAPIStoreMapping *mapping; + NSDictionary *result; - if (isMove && [targetFolder isKindOfClass: MAPIStoreMailFolderK]) + if ([targetFolder isKindOfClass: MAPIStoreMailFolderK]) { folderURL = [sogoObject imap4URL]; if (!newFolderName) @@ -1033,29 +1042,84 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) targetSOGoFolder = [targetFolder sogoObject]; newFolderURL = [NSURL URLWithString: newFolderName relativeToURL: [targetSOGoFolder imap4URL]]; - error = [[sogoObject imap4Connection] - moveMailboxAtURL: folderURL - toURL: newFolderURL]; - if (error) - rc = MAPISTORE_ERR_DENIED; + if (isMove) + { + error = [[sogoObject imap4Connection] + moveMailboxAtURL: folderURL + toURL: newFolderURL]; + if (error) + rc = MAPISTORE_ERR_DENIED; + else + { + rc = MAPISTORE_SUCCESS; + mapping = [self mapping]; + newURL = [NSString stringWithFormat: @"%@folder%@/", + [targetFolder url], newFolderName]; + [mapping updateID: [self objectId] + withURL: newURL]; + parentDBFolderPath = [[targetFolder dbFolder] path]; + if (!parentDBFolderPath) + parentDBFolderPath = @""; + [dbFolder changePathTo: [NSString stringWithFormat: + @"%@/folder%@", + parentDBFolderPath, + newFolderName]]; + } + } else { - rc = MAPISTORE_SUCCESS; - mapping = [self mapping]; - newURL = [NSString stringWithFormat: @"%@folder%@/", - [targetFolder url], newFolderName]; - [mapping updateID: [self objectId] - withURL: newURL]; - parentDBFolderPath = [[targetFolder dbFolder] path]; - if (!parentDBFolderPath) - parentDBFolderPath = @""; - [dbFolder changePathTo: [NSString stringWithFormat: - @"%@/folder%@", - parentDBFolderPath, - newFolderName]]; + nameProperty.ulPropTag = PidTagDisplayName; + nameProperty.value.lpszW = [newFolderName UTF8String]; + folderRow.lpProps = &nameProperty; + folderRow.cValues = 1; + rc = [targetFolder createFolder: &folderRow + withFID: -1 + andKey: &childKey]; + if (rc == MAPISTORE_SUCCESS) + { + newFolder = [targetFolder lookupFolder: childKey]; + + connection = [sogoObject imap4Connection]; + folderIMAPName = [connection + imap4FolderNameForURL: [sogoObject imap4URL]]; + newFolderIMAPName = [connection + imap4FolderNameForURL: [[newFolder sogoObject] imap4URL]]; + client = [connection client]; + [client select: folderIMAPName]; + + childKeys = [self messageKeys]; + max = [childKeys count]; + uids = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + childKey = [childKeys objectAtIndex: count]; + [uids addObject: [self messageUIDFromMessageKey: childKey]]; + } + + result = [client copyUids: uids + toFolder: newFolderIMAPName]; + if ([[result objectForKey: @"result"] boolValue]) + { + if (isRecursive) + { + childKeys = [self folderKeys]; + max = [childKeys count]; + for (count = 0; count < max; count++) + { + childKey = [childKeys objectAtIndex: count]; + [[self lookupFolder: childKey] + moveCopyToFolder: newFolder + withNewName: nil + isMove: NO + isRecursive: YES]; + } + } + } + else + rc = MAPISTORE_ERROR; + } } [targetFolder cleanupCaches]; - [self cleanupCaches]; } else rc = [super moveCopyToFolder: targetFolder withNewName: newFolderName diff --git a/OpenChange/MAPIStoreSOGo.m b/OpenChange/MAPIStoreSOGo.m index 2d4e11dec..22abf4e68 100644 --- a/OpenChange/MAPIStoreSOGo.m +++ b/OpenChange/MAPIStoreSOGo.m @@ -679,9 +679,10 @@ sogo_folder_copy_folder(void *folder_object, void *target_folder_object, newFolderName = [NSString stringWithUTF8String: new_folder_name]; - rc = [copyFolder copyToFolder: targetFolder - recursive: recursive - withNewName: newFolderName]; + rc = [copyFolder moveCopyToFolder: targetFolder + withNewName: newFolderName + isMove: NO + isRecursive: recursive]; [pool release]; GSUnregisterCurrentThread (); }