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

pull/207/head
Ludovic Marcotte 2016-05-03 09:04:36 -04:00
parent 8853bc4977
commit bb34a22578
1 changed files with 30 additions and 28 deletions

View File

@ -528,22 +528,23 @@ _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]; {
error = [NSException exceptionWithHTTPStatus: 500 [self errorWithFormat: @"spool directory '%@' doesn't exist", spoolPath];
reason: @"spool directory does not exist"]; error = [NSException exceptionWithHTTPStatus: 500
return (WOResponse *)error; reason: @"spool directory does not exist"];
return (WOResponse *)error;
} }
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 {
reason: @"zip not available"]; error = [NSException exceptionWithHTTPStatus: 500
return (WOResponse *)error; reason: @"zip not available"];
} return (WOResponse *)error;
}
zipTask = [[NSTask alloc] init]; zipTask = [[NSTask alloc] init];
[zipTask setCurrentDirectoryPath: spoolPath]; [zipTask setCurrentDirectoryPath: spoolPath];
@ -556,14 +557,15 @@ _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"]; {
fileName = [NSString stringWithFormat:@"%@/%@.eml", spoolPath, [uids objectAtIndex: i]];; content = [[[messages objectAtIndex: i] objectForKey: @"body[]"] objectForKey: @"data"];
[content writeToFile: fileName atomically: YES]; fileName = [NSString stringWithFormat:@"%@/%@.eml", spoolPath, [uids objectAtIndex: i]];;
[content writeToFile: fileName atomically: YES];
[zipTaskArguments addObject: [zipTaskArguments addObject:
[NSString stringWithFormat:@"%@.eml", [uids objectAtIndex: i]]]; [NSString stringWithFormat:@"%@.eml", [uids objectAtIndex: i]]];
} }
[zipTask setArguments: zipTaskArguments]; [zipTask setArguments: zipTaskArguments];
[zipTask launch]; [zipTask launch];
@ -572,16 +574,16 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
[zipTask release]; [zipTask release];
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]; {
[fm removeFileAtPath: fileName = [zipTaskArguments objectAtIndex: i];
[NSString stringWithFormat: @"%@/%@", spoolPath, fileName] handler: nil]; [fm removeFileAtPath:
} [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)
@ -595,14 +597,14 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
[response setHeader: [NSString stringWithFormat: @"application/zip;" [response setHeader: [NSString stringWithFormat: @"application/zip;"
@" name=\"%@\"", @" name=\"%@\"",
qpFileName] qpFileName]
forKey:@"content-type"]; forKey: @"content-type"];
[response setHeader: [NSString stringWithFormat: @"attachment; filename=\"%@\"", [response setHeader: [NSString stringWithFormat: @"attachment; filename=\"%@\"",
qpFileName] qpFileName]
forKey: @"Content-Disposition"]; forKey: @"Content-Disposition"];
[response setContent: zipContent]; [response setContent: zipContent];
[zipContent release]; [zipContent release];
return response; return response;
} }