(fix) correctly write the content on disk before zipping it
parent
8853bc4977
commit
bb34a22578
|
@ -528,22 +528,23 @@ _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]) {
|
||||
[self errorWithFormat: @"spool directory '%@' doesn't exist", spoolPath];
|
||||
error = [NSException exceptionWithHTTPStatus: 500
|
||||
reason: @"spool directory does not exist"];
|
||||
return (WOResponse *)error;
|
||||
if (![self ensureSpoolFolderPath])
|
||||
{
|
||||
[self errorWithFormat: @"spool directory '%@' doesn't exist", spoolPath];
|
||||
error = [NSException exceptionWithHTTPStatus: 500
|
||||
reason: @"spool directory does not exist"];
|
||||
return (WOResponse *)error;
|
||||
}
|
||||
|
||||
zipPath = [[SOGoSystemDefaults sharedSystemDefaults] zipPath];
|
||||
fm = [NSFileManager defaultManager];
|
||||
if (![fm fileExistsAtPath: zipPath]) {
|
||||
error = [NSException exceptionWithHTTPStatus: 500
|
||||
reason: @"zip not available"];
|
||||
return (WOResponse *)error;
|
||||
}
|
||||
if (![fm fileExistsAtPath: zipPath])
|
||||
{
|
||||
error = [NSException exceptionWithHTTPStatus: 500
|
||||
reason: @"zip not available"];
|
||||
return (WOResponse *)error;
|
||||
}
|
||||
|
||||
zipTask = [[NSTask alloc] init];
|
||||
[zipTask setCurrentDirectoryPath: spoolPath];
|
||||
|
@ -556,14 +557,15 @@ _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"];
|
||||
fileName = [NSString stringWithFormat:@"%@/%@.eml", spoolPath, [uids objectAtIndex: i]];;
|
||||
[content writeToFile: fileName atomically: YES];
|
||||
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];
|
||||
|
||||
[zipTaskArguments addObject:
|
||||
[NSString stringWithFormat:@"%@.eml", [uids objectAtIndex: i]]];
|
||||
}
|
||||
[zipTaskArguments addObject:
|
||||
[NSString stringWithFormat:@"%@.eml", [uids objectAtIndex: i]]];
|
||||
}
|
||||
|
||||
[zipTask setArguments: zipTaskArguments];
|
||||
[zipTask launch];
|
||||
|
@ -572,16 +574,16 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
|
|||
[zipTask release];
|
||||
|
||||
zipContent = [[NSData alloc] initWithContentsOfFile:
|
||||
[NSString stringWithFormat: @"%@/SavedMessages.zip", spoolPath]];
|
||||
[NSString stringWithFormat: @"%@/SavedMessages.zip", spoolPath]];
|
||||
|
||||
for(i = 0; i < [zipTaskArguments count]; i++) {
|
||||
fileName = [zipTaskArguments objectAtIndex: i];
|
||||
[fm removeFileAtPath:
|
||||
[NSString stringWithFormat: @"%@/%@", spoolPath, fileName] handler: nil];
|
||||
}
|
||||
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"];
|
||||
|
|
Loading…
Reference in New Issue