(fix) correctly write the content on disk before zipping it
This commit is contained in:
parent
c1c44b8996
commit
da489c6499
|
@ -537,22 +537,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];
|
||||||
|
@ -565,14 +566,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];
|
||||||
|
@ -581,16 +583,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)
|
||||||
|
@ -604,7 +606,7 @@ _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"];
|
||||||
|
|
Loading…
Reference in a new issue