diff --git a/OpenChange/MAPIStoreAttachment.h b/OpenChange/MAPIStoreAttachment.h index c859e7c8a..bfa779b85 100644 --- a/OpenChange/MAPIStoreAttachment.h +++ b/OpenChange/MAPIStoreAttachment.h @@ -48,7 +48,7 @@ - (NSData *) mimeAttachTag; /* move & copy operations */ -- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment; +- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment inMemCtx: (TALLOC_CTX *) memCtx; /* subclasses */ - (MAPIStoreEmbeddedMessage *) openEmbeddedMessage; diff --git a/OpenChange/MAPIStoreAttachment.m b/OpenChange/MAPIStoreAttachment.m index 5e7c69180..cb85911e3 100644 --- a/OpenChange/MAPIStoreAttachment.m +++ b/OpenChange/MAPIStoreAttachment.m @@ -152,13 +152,13 @@ return ULLONG_MAX; } -- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment +- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment inMemCtx: (TALLOC_CTX *) memCtx { void *attachMethod; enum mapistore_error error; MAPIStoreEmbeddedMessage *embeddedMessage, *newEmbeddedMessage; - [self copyPropertiesToObject: newAttachment]; + [self copyPropertiesToObject: newAttachment inMemCtx: memCtx]; attachMethod = NULL; error = [self getProperty: &attachMethod @@ -170,7 +170,7 @@ { embeddedMessage = [self openEmbeddedMessage]; newEmbeddedMessage = [newAttachment createEmbeddedMessage]; - [embeddedMessage copyToMessage: newEmbeddedMessage]; + [embeddedMessage copyToMessage: newEmbeddedMessage inMemCtx: memCtx]; } talloc_free (attachMethod); } diff --git a/OpenChange/MAPIStoreCalendarFolder.m b/OpenChange/MAPIStoreCalendarFolder.m index eeb5bb81e..5cab28712 100644 --- a/OpenChange/MAPIStoreCalendarFolder.m +++ b/OpenChange/MAPIStoreCalendarFolder.m @@ -63,6 +63,8 @@ SOGoAppointmentObject *newEntry; NSString *name; + [self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__]; + name = [NSString stringWithFormat: @"%@.ics", [SOGoObject globallyUniqueObjectId]]; newEntry = [SOGoAppointmentObject objectWithName: name diff --git a/OpenChange/MAPIStoreFolder.h b/OpenChange/MAPIStoreFolder.h index c5a7bd72e..7b769ac5f 100644 --- a/OpenChange/MAPIStoreFolder.h +++ b/OpenChange/MAPIStoreFolder.h @@ -123,7 +123,8 @@ fromFolder: (MAPIStoreFolder *) sourceFolder withMIDs: (uint64_t *) targetMids andChangeKeys: (struct Binary_r **) targetChangeKeys - wantCopy: (uint8_t) want_copy; + wantCopy: (uint8_t) want_copy + inMemCtx: (TALLOC_CTX *) memCtx; - (enum mapistore_error) moveCopyToFolder: (MAPIStoreFolder *) targetFolder withNewName: (NSString *) newFolderName diff --git a/OpenChange/MAPIStoreFolder.m b/OpenChange/MAPIStoreFolder.m index e3ec06976..64a388fcb 100644 --- a/OpenChange/MAPIStoreFolder.m +++ b/OpenChange/MAPIStoreFolder.m @@ -180,6 +180,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe - (void) dealloc { + [self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__]; + // [messageKeys release]; // [faiMessageKeys release]; // [folderKeys release]; @@ -656,19 +658,23 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe return rc; } -- (int) moveCopyMessageWithMID: (uint64_t) srcMid - fromFolder: (MAPIStoreFolder *) sourceFolder - withMID: (uint64_t) targetMid - andChangeKey: (struct Binary_r *) targetChangeKey - wantCopy: (uint8_t) wantCopy +// private method +- (int) _moveCopyMessageWithMID: (uint64_t) srcMid + fromFolder: (MAPIStoreFolder *) sourceFolder + withMID: (uint64_t) targetMid + andChangeKey: (struct Binary_r *) targetChangeKey + wantCopy: (uint8_t) wantCopy + inMemCtx: (TALLOC_CTX *) memCtx { int rc; MAPIStoreMessage *sourceMsg, *destMsg; - TALLOC_CTX *memCtx; + //TALLOC_CTX *memCtx; struct SRow aRow; struct SPropValue property; - memCtx = talloc_zero (NULL, TALLOC_CTX); + [self logWithFormat: @"-moveCopyMessageWithMID: 0x%.16llx .. withMID: 0x%.16llx .. wantCopy: %d", srcMid, targetMid, wantCopy]; + + //memCtx = talloc_zero (NULL, TALLOC_CTX); rc = [sourceFolder openMessage: &sourceMsg withMID: srcMid forWriting: NO @@ -681,7 +687,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe if (rc != MAPISTORE_SUCCESS) goto end; - [sourceMsg copyToMessage: destMsg]; + [sourceMsg copyToMessage: destMsg inMemCtx: memCtx]; if (targetChangeKey) { @@ -698,7 +704,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe rc = [sourceFolder deleteMessageWithMID: srcMid andFlags: 0]; end: - talloc_free (memCtx); + //talloc_free (memCtx); return rc; } @@ -709,6 +715,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe withMIDs: (uint64_t *) targetMids andChangeKeys: (struct Binary_r **) targetChangeKeys wantCopy: (uint8_t) wantCopy + inMemCtx: (TALLOC_CTX *) memCtx { int rc = MAPISTORE_SUCCESS; NSUInteger count; @@ -717,6 +724,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe MAPIStoreMapping *mapping; SOGoUser *ownerUser; struct Binary_r *targetChangeKey; + //TALLOC_CTX *memCtx; + + //memCtx = talloc_zero (NULL, TALLOC_CTX); ownerUser = [[self userContext] sogoUser]; @@ -738,11 +748,12 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe targetChangeKey = targetChangeKeys[count]; else targetChangeKey = NULL; - rc = [self moveCopyMessageWithMID: srcMids[count] - fromFolder: sourceFolder - withMID: targetMids[count] - andChangeKey: targetChangeKey - wantCopy: wantCopy]; + rc = [self _moveCopyMessageWithMID: srcMids[count] + fromFolder: sourceFolder + withMID: targetMids[count] + andChangeKey: targetChangeKey + wantCopy: wantCopy + inMemCtx: memCtx]; } else rc = MAPISTORE_ERR_NOT_FOUND; @@ -765,7 +776,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe } else rc = MAPISTORE_ERR_DENIED; - + + //talloc_free (memCtx); + return rc; } @@ -785,6 +798,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe NSUInteger count, max; NSString *childKey; uint64_t fmid; + TALLOC_CTX *memCtx; + + memCtx = talloc_zero (NULL, TALLOC_CTX); /* TODO: one possible issue with this algorithm is that moved messages will lack a version number and will all be assigned a new one, even though @@ -807,7 +823,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe if (rc == MAPISTORE_SUCCESS) { newFolder = [targetFolder lookupFolder: childKey]; - [self copyPropertiesToObject: newFolder]; + [self copyPropertiesToObject: newFolder inMemCtx: memCtx]; pool = [NSAutoreleasePool new]; children = [self messageKeys]; @@ -818,7 +834,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe message = [self lookupMessage: childKey]; targetMessage = [newFolder createMessage: NO]; [targetMessage setIsNew: YES]; - [message copyToMessage: targetMessage]; + [message copyToMessage: targetMessage inMemCtx: memCtx]; if (isMove) { fmid = [mapping idFromURL: [message url]]; @@ -839,7 +855,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe message = [self lookupFAIMessage: childKey]; targetMessage = [newFolder createMessage: YES]; [targetMessage setIsNew: YES]; - [message copyToMessage: targetMessage]; + [message copyToMessage: targetMessage inMemCtx: memCtx]; if (isMove) { fmid = [mapping idFromURL: [message url]]; @@ -882,6 +898,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe else rc = MAPISTORE_ERR_DENIED; + talloc_free (memCtx); + return rc; } diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 9271751a2..3a2d2bb2f 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -929,6 +929,8 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) withMIDs: (uint64_t *) targetMids andChangeKeys: (struct Binary_r **) targetChangeKeys wantCopy: (uint8_t) wantCopy + inMemCtx: (TALLOC_CTX *) memCtx + { NGImap4Connection *connection; NGImap4Client *client; @@ -946,7 +948,8 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) return [super moveCopyMessagesWithMIDs: srcMids andCount: midCount fromFolder: sourceFolder withMIDs: targetMids andChangeKeys: targetChangeKeys - wantCopy: wantCopy]; + wantCopy: wantCopy + inMemCtx: memCtx]; /* Conversion of mids to IMAP uids */ mapping = [self mapping]; diff --git a/OpenChange/MAPIStoreMessage.h b/OpenChange/MAPIStoreMessage.h index c782cb0d6..06ca45436 100644 --- a/OpenChange/MAPIStoreMessage.h +++ b/OpenChange/MAPIStoreMessage.h @@ -71,7 +71,7 @@ - (NSArray *) activeUserRoles; /* move & copy internal ops */ -- (void) copyToMessage: (MAPIStoreMessage *) newMessage; +- (void) copyToMessage: (MAPIStoreMessage *) newMessage inMemCtx: (TALLOC_CTX *) memCtx; /* subclasses */ - (void) save; diff --git a/OpenChange/MAPIStoreMessage.m b/OpenChange/MAPIStoreMessage.m index c1445f6c2..0751c993d 100644 --- a/OpenChange/MAPIStoreMessage.m +++ b/OpenChange/MAPIStoreMessage.m @@ -139,6 +139,8 @@ rtf2html (NSData *compressedRTF) - (id) init { + [self logWithFormat: @"METHOD '%s' (%d) (%d)", __FUNCTION__, __LINE__, self]; + if ((self = [super init])) { attachmentParts = [NSMutableDictionary new]; @@ -151,6 +153,7 @@ rtf2html (NSData *compressedRTF) - (void) dealloc { + [self logWithFormat: @"METHOD '%s' (%d) (%d)", __FUNCTION__, __LINE__, self]; [activeUserRoles release]; [attachmentKeys release]; [attachmentParts release]; @@ -437,17 +440,19 @@ rtf2html (NSData *compressedRTF) andType: MAPISTORE_MESSAGE_TABLE]; } -- (void) copyToMessage: (MAPIStoreMessage *) newMessage +- (void) copyToMessage: (MAPIStoreMessage *) newMessage inMemCtx: (TALLOC_CTX *) memCtx; { - TALLOC_CTX *memCtx; + //TALLOC_CTX *memCtx; struct mapistore_message *messageData; NSArray *keys; NSUInteger count, max; NSString *key; MAPIStoreAttachment *attachment, *newAttachment; - memCtx = talloc_zero (NULL, TALLOC_CTX); + [self logWithFormat: @"METHOD '%s' (%d) (%d)", __FUNCTION__, __LINE__, self]; + + //memCtx = talloc_zero (NULL, TALLOC_CTX); /* message headers and recipients */ [self getMessageData: &messageData inMemCtx: memCtx]; @@ -456,7 +461,7 @@ rtf2html (NSData *compressedRTF) andColumns: messageData->columns]; /* properties */ - [self copyPropertiesToObject: newMessage]; + [self copyPropertiesToObject: newMessage inMemCtx: memCtx]; /* attachments */ keys = [self attachmentKeys]; @@ -466,10 +471,10 @@ rtf2html (NSData *compressedRTF) key = [keys objectAtIndex: count]; attachment = [self lookupAttachment: key]; newAttachment = [newMessage createAttachment]; - [attachment copyToAttachment: newAttachment]; + [attachment copyToAttachment: newAttachment inMemCtx: memCtx]; } - talloc_free (memCtx); + //talloc_free (memCtx); } - (enum mapistore_error) saveMessage @@ -485,6 +490,8 @@ rtf2html (NSData *compressedRTF) BOOL userIsOwner; MAPIStoreMessage *mainMessage; + [self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__]; + context = [self context]; ownerUser = [[self userContext] sogoUser]; userIsOwner = [[context activeUser] isEqual: ownerUser]; diff --git a/OpenChange/MAPIStoreObject.h b/OpenChange/MAPIStoreObject.h index d7aa989de..c5a466ac3 100644 --- a/OpenChange/MAPIStoreObject.h +++ b/OpenChange/MAPIStoreObject.h @@ -91,7 +91,7 @@ inMemCtx: (TALLOC_CTX *) memCtx; /* move and copy operations */ -- (void) copyPropertiesToObject: (MAPIStoreObject *) newObject; +- (void) copyPropertiesToObject: (MAPIStoreObject *) newObject inMemCtx: (TALLOC_CTX *) memCtx; /* subclasses */ - (NSString *) nameInContainer; diff --git a/OpenChange/MAPIStoreObject.m b/OpenChange/MAPIStoreObject.m index 24310a926..7d4bb3219 100644 --- a/OpenChange/MAPIStoreObject.m +++ b/OpenChange/MAPIStoreObject.m @@ -317,9 +317,9 @@ static Class NSExceptionK, MAPIStoreFolderK; } /* move and copy operations */ -- (void) copyPropertiesToObject: (MAPIStoreObject *) newObject +- (void) copyPropertiesToObject: (MAPIStoreObject *) newObject inMemCtx: (TALLOC_CTX *) memCtx { - TALLOC_CTX *memCtx; + //TALLOC_CTX *memCtx; struct SPropTagArray *availableProps; struct SRow row; enum MAPITAGS propTag; @@ -328,7 +328,7 @@ static Class NSExceptionK, MAPIStoreFolderK; enum mapistore_error error; void *data; - memCtx = talloc_zero (NULL, TALLOC_CTX); + //memCtx = talloc_zero (NULL, TALLOC_CTX); [self getAvailableProperties: &availableProps inMemCtx: memCtx]; @@ -369,8 +369,7 @@ static Class NSExceptionK, MAPIStoreFolderK; } [newObject addPropertiesFromRow: &row]; - talloc_free (memCtx); - + //talloc_free (memCtx); } /* subclasses */ diff --git a/OpenChange/MAPIStoreSOGo.m b/OpenChange/MAPIStoreSOGo.m index 7e219fe03..2c96bea78 100644 --- a/OpenChange/MAPIStoreSOGo.m +++ b/OpenChange/MAPIStoreSOGo.m @@ -95,6 +95,7 @@ sogo_backend_init (void) defaults using the system encoding rather than honouring the encoding specified in the file. */ putenv ("GNUSTEP_STRING_ENCODING=NSUTF8StringEncoding"); + //putenv ("NSZombieEnabled=YES"); [NSProcessInfo initializeWithArguments: argv count: 1 @@ -565,7 +566,8 @@ sogo_folder_delete_message(void *folder_object, uint64_t mid, uint8_t flags) } static enum mapistore_error -sogo_folder_move_copy_messages(void *folder_object, +sogo_folder_move_copy_messages(TALLOC_CTX *mem_ctx, + void *folder_object, void *source_folder_object, uint32_t mid_count, uint64_t *src_mids, uint64_t *t_mids, @@ -594,7 +596,8 @@ sogo_folder_move_copy_messages(void *folder_object, fromFolder: sourceFolder withMIDs: t_mids andChangeKeys: target_change_keys - wantCopy: want_copy]; + wantCopy: want_copy + inMemCtx: mem_ctx]; [pool release]; GSUnregisterCurrentThread (); } diff --git a/OpenChange/NSObject+MAPIStore.m b/OpenChange/NSObject+MAPIStore.m index 930b13f11..958fb9208 100644 --- a/OpenChange/NSObject+MAPIStore.m +++ b/OpenChange/NSObject+MAPIStore.m @@ -50,7 +50,8 @@ MAPIStoreTallocWrapperDestroy (void *data) GSRegisterCurrentThread (); pool = [NSAutoreleasePool new]; wrapper = data; - // NSLog (@"destroying wrapped object (wrapper: %p; object: %p)...\n", wrapper, wrapper->MAPIStoreSOGoObject); + //NSLog (@"destroying wrapped object (wrapper: %p; object: %p)...\n", wrapper, wrapper->MAPIStoreSOGoObject); + NSLog (@"destroying wrapped object (wrapper: %p)", wrapper); [wrapper->instance release]; [pool release]; GSUnregisterCurrentThread (); @@ -66,7 +67,7 @@ MAPIStoreTallocWrapperDestroy (void *data) talloc_set_destructor ((void *) wrapper, MAPIStoreTallocWrapperDestroy); wrapper->instance = self; [self retain]; - // NSLog (@"returning wrapper: %p; object: %p", wrapper, self); + NSLog (@"returning wrapper: %p; object: %p", wrapper, self); return wrapper; }