Monotone-Parent: c09f18aa20f8387df37e9fa0055f49ea9670e4e5

Monotone-Revision: c9dd4206ad3d7a913acb09680d854a19153d46a7

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-07-27T19:58:30
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2007-07-27 19:58:30 +00:00
parent fb3cf6f519
commit a450325cb7
3 changed files with 56 additions and 14 deletions

View File

@@ -1,5 +1,15 @@
2007-07-27 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/Mailer/SOGoDraftObject.m ([SOGoDraftObject
-saveAttachment:_attachwithMetadata:metadata]): new method
replacing -saveAttachment:withName: and which takes a dictionary
as parameter with the filename and the mime type of the
attachment.
The mimetype is then saved in a hidden text file.
([SOGoDraftObject -contentTypeForAttachmentWithName:]): if exists,
take the mime type from the hidden text file related to the
attachment.
* SoObjects/Contacts/SOGoContactGCSFolder.m ()
([SOGoContactGCSFolder
-lookupContactsWithFilter:filtersortBy:sortKeyordering:sortOrdering]):

View File

@@ -55,7 +55,8 @@
- (NSArray *)fetchAttachmentNames;
- (BOOL)isValidAttachmentName:(NSString *)_name;
- (NSException *)saveAttachment:(NSData *)_attach withName:(NSString *)_name;
- (NSException *) saveAttachment: (NSData *)_attach
withMetadata: (NSDictionary *) metadata;
- (NSException *)deleteAttachmentWithName:(NSString *)_name;
/* NGMime representations */

View File

@@ -257,8 +257,10 @@ static BOOL showTextAttachmentsInline = NO;
reason:@"Invalid attachment name!"];
}
- (NSException *)saveAttachment:(NSData *)_attach withName:(NSString *)_name {
NSString *p;
- (NSException *) saveAttachment: (NSData *) _attach
withMetadata: (NSDictionary *) metadata
{
NSString *p, *name, *mimeType;
if (![_attach isNotNull]) {
return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
@@ -269,14 +271,29 @@ static BOOL showTextAttachmentsInline = NO;
return [NSException exceptionWithHTTPStatus:500 /* Server Error */
reason:@"Could not create folder for draft!"];
}
if (![self isValidAttachmentName:_name])
return [self invalidAttachmentNameError:_name];
name = [metadata objectForKey: @"filename"];
if (![self isValidAttachmentName: name])
return [self invalidAttachmentNameError: name];
p = [self pathToAttachmentWithName:_name];
if (![_attach writeToFile:p atomically:YES]) {
return [NSException exceptionWithHTTPStatus:500 /* Server Error */
reason:@"Could not write attachment to draft!"];
}
p = [self pathToAttachmentWithName: name];
if (![_attach writeToFile: p atomically: YES])
{
return [NSException exceptionWithHTTPStatus:500 /* Server Error */
reason:@"Could not write attachment to draft!"];
}
mimeType = [metadata objectForKey: @"mime-type"];
if ([mimeType length] > 0)
{
p = [self pathToAttachmentWithName:
[NSString stringWithFormat: @".%@.mime", name]];
if (![[mimeType dataUsingEncoding: NSUTF8StringEncoding]
writeToFile: p atomically: YES])
{
return [NSException exceptionWithHTTPStatus:500 /* Server Error */
reason:@"Could not write attachment to draft!"];
}
}
return nil; /* everything OK */
}
@@ -383,14 +400,28 @@ static BOOL showTextAttachmentsInline = NO;
}
- (NSString *)contentTypeForAttachmentWithName:(NSString *)_name {
NSString *s;
NSString *s, *p;
NSData *mimeData;
s = [self mimeTypeForExtension:[_name pathExtension]];
if ([_name length] > 0)
s = [s stringByAppendingFormat:@"; name=\"%@\"", _name];
p = [self pathToAttachmentWithName:
[NSString stringWithFormat: @".%@.mime", _name]];
mimeData = [NSData dataWithContentsOfFile: p];
if (mimeData)
{
s = [[NSString alloc] initWithData: mimeData
encoding: NSUTF8StringEncoding];
[s autorelease];
}
else
{
s = [self mimeTypeForExtension:[_name pathExtension]];
if ([_name length] > 0)
s = [s stringByAppendingFormat:@"; name=\"%@\"", _name];
}
return s;
}
- (NSString *)contentDispositionForAttachmentWithName:(NSString *)_name {
NSString *type;
NSString *cdtype;