(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,9 +528,9 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
if (!archiveName)
archiveName = @"SavedMessages.zip";
#warning this method should be rewritten according to our coding styles
spoolPath = [self userSpoolFolderPath];
if (![self ensureSpoolFolderPath]) {
if (![self ensureSpoolFolderPath])
{
[self errorWithFormat: @"spool directory '%@' doesn't exist", spoolPath];
error = [NSException exceptionWithHTTPStatus: 500
reason: @"spool directory does not exist"];
@ -539,7 +539,8 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
zipPath = [[SOGoSystemDefaults sharedSystemDefaults] zipPath];
fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath: zipPath]) {
if (![fm fileExistsAtPath: zipPath])
{
error = [NSException exceptionWithHTTPStatus: 500
reason: @"zip not available"];
return (WOResponse *)error;
@ -556,8 +557,9 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
parts: [NSArray arrayWithObject: @"BODY.PEEK[]"]];
messages = [msgs objectForKey: @"fetch"];
for (i = 0; i < [messages count]; i++) {
content = [[messages objectAtIndex: i] objectForKey: @"message"];
for (i = 0; i < [messages count]; i++)
{
content = [[[messages objectAtIndex: i] objectForKey: @"body[]"] objectForKey: @"data"];
fileName = [NSString stringWithFormat:@"%@/%@.eml", spoolPath, [uids objectAtIndex: i]];;
[content writeToFile: fileName atomically: YES];
@ -574,14 +576,14 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
zipContent = [[NSData alloc] initWithContentsOfFile:
[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:
[NSString stringWithFormat: @"%@/%@", spoolPath, fileName] handler: nil];
}
response = [context response];
baseName = [archiveName stringByDeletingPathExtension];
extension = [archiveName pathExtension];
if ([extension length] > 0)
@ -595,7 +597,7 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
[response setHeader: [NSString stringWithFormat: @"application/zip;"
@" name=\"%@\"",
qpFileName]
forKey:@"content-type"];
forKey: @"content-type"];
[response setHeader: [NSString stringWithFormat: @"attachment; filename=\"%@\"",
qpFileName]
forKey: @"Content-Disposition"];