(fix) correctly write the content on disk before zipping it

This commit is contained in:
Ludovic Marcotte 2016-05-03 09:04:36 -04:00
parent c1c44b8996
commit da489c6499

View file

@ -537,9 +537,9 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
if (!archiveName) if (!archiveName)
archiveName = @"SavedMessages.zip"; archiveName = @"SavedMessages.zip";
#warning this method should be rewritten according to our coding styles
spoolPath = [self userSpoolFolderPath]; spoolPath = [self userSpoolFolderPath];
if (![self ensureSpoolFolderPath]) { if (![self ensureSpoolFolderPath])
{
[self errorWithFormat: @"spool directory '%@' doesn't exist", spoolPath]; [self errorWithFormat: @"spool directory '%@' doesn't exist", spoolPath];
error = [NSException exceptionWithHTTPStatus: 500 error = [NSException exceptionWithHTTPStatus: 500
reason: @"spool directory does not exist"]; reason: @"spool directory does not exist"];
@ -548,7 +548,8 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
zipPath = [[SOGoSystemDefaults sharedSystemDefaults] zipPath]; zipPath = [[SOGoSystemDefaults sharedSystemDefaults] zipPath];
fm = [NSFileManager defaultManager]; fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath: zipPath]) { if (![fm fileExistsAtPath: zipPath])
{
error = [NSException exceptionWithHTTPStatus: 500 error = [NSException exceptionWithHTTPStatus: 500
reason: @"zip not available"]; reason: @"zip not available"];
return (WOResponse *)error; return (WOResponse *)error;
@ -565,8 +566,9 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
parts: [NSArray arrayWithObject: @"BODY.PEEK[]"]]; parts: [NSArray arrayWithObject: @"BODY.PEEK[]"]];
messages = [msgs objectForKey: @"fetch"]; messages = [msgs objectForKey: @"fetch"];
for (i = 0; i < [messages count]; i++) { for (i = 0; i < [messages count]; i++)
content = [[messages objectAtIndex: i] objectForKey: @"message"]; {
content = [[[messages objectAtIndex: i] objectForKey: @"body[]"] objectForKey: @"data"];
fileName = [NSString stringWithFormat:@"%@/%@.eml", spoolPath, [uids objectAtIndex: i]];; fileName = [NSString stringWithFormat:@"%@/%@.eml", spoolPath, [uids objectAtIndex: i]];;
[content writeToFile: fileName atomically: YES]; [content writeToFile: fileName atomically: YES];
@ -583,14 +585,14 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
zipContent = [[NSData alloc] initWithContentsOfFile: zipContent = [[NSData alloc] initWithContentsOfFile:
[NSString stringWithFormat: @"%@/SavedMessages.zip", spoolPath]]; [NSString stringWithFormat: @"%@/SavedMessages.zip", spoolPath]];
for(i = 0; i < [zipTaskArguments count]; i++) { for (i = 0; i < [zipTaskArguments count]; i++)
{
fileName = [zipTaskArguments objectAtIndex: i]; fileName = [zipTaskArguments objectAtIndex: i];
[fm removeFileAtPath: [fm removeFileAtPath:
[NSString stringWithFormat: @"%@/%@", spoolPath, fileName] handler: nil]; [NSString stringWithFormat: @"%@/%@", spoolPath, fileName] handler: nil];
} }
response = [context response]; response = [context response];
baseName = [archiveName stringByDeletingPathExtension]; baseName = [archiveName stringByDeletingPathExtension];
extension = [archiveName pathExtension]; extension = [archiveName pathExtension];
if ([extension length] > 0) if ([extension length] > 0)