From: helge Date: Fri, 29 Oct 2004 15:32:28 +0000 (+0000) Subject: fixed attachments X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4ca21e198e4f90bf15e51accae46fc4e18f1fb8;p=scalable-opengroupware.org fixed attachments git-svn-id: http://svn.opengroupware.org/SOGo/trunk@441 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index bc440db2..a3f9a319 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,8 @@ +2004-10-29 Helge Hess + + * SOGoDraftObject.m: add 'name' parameter to content-type, properly + encode binary attachments (v0.9.45) + 2004-10-28 Helge Hess * SOGoDraftObject.m: do not patch NGImap4Envelope ivars and use the new diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.m b/SOGo/SoObjects/Mailer/SOGoDraftObject.m index bf07045f..e72dfdd1 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.m +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.m @@ -270,7 +270,15 @@ static BOOL debugOn = NO; } - (NSString *)contentTypeForAttachmentWithName:(NSString *)_name { - return [self mimeTypeForExtension:[_name pathExtension]]; + NSString *s; + + s = [self mimeTypeForExtension:[_name pathExtension]]; + if ([_name length] > 0) { + s = [s stringByAppendingString:@"; name=\""]; + s = [s stringByAppendingString:_name]; + s = [s stringByAppendingString:@"\""]; + } + return s; } - (NSString *)contentDispositionForAttachmentWithName:(NSString *)_name { NSString *type; @@ -302,6 +310,7 @@ static BOOL debugOn = NO; NSData *content; BOOL attachAsString; NSString *p; + id body; if (_name == nil) return nil; @@ -319,7 +328,7 @@ static BOOL debugOn = NO; map = [[[NGMutableHashMap alloc] initWithCapacity:4] autorelease]; - if ((s = [self contentTypeForAttachmentWithName:_name])) { + if ((s = [self contentTypeForAttachmentWithName:_name]) != nil) { [map setObject:s forKey:@"content-type"]; if ([s hasPrefix:@"text/"]) attachAsString = YES; @@ -327,8 +336,6 @@ static BOOL debugOn = NO; if ((s = [self contentDispositionForAttachmentWithName:_name])) [map setObject:s forKey:@"content-disposition"]; - bodyPart = [[[NGMimeBodyPart alloc] initWithHeader:map] autorelease]; - /* prepare body content */ if (attachAsString) { // TODO: is this really necessary? @@ -339,22 +346,40 @@ static BOOL debugOn = NO; s = [[NSString alloc] initWithData:content encoding:[NSString defaultCStringEncoding]]; if (s != nil) { - [bodyPart setBody:s]; - [s release]; s = nil; + body = s; + [content release]; content = nil; } else { [self logWithFormat: @"WARNING: could not get text attachment as string: '%@'",_name]; - [bodyPart setBody:content]; + body = content; + content = nil; } } else { - content = [[NGMimeFileData alloc] initWithPath:p removeFile:NO]; - [bodyPart setBody:content]; + /* + Note: in OGo this is done in LSWImapMailEditor.m:2477. Apparently + NGMimeFileData objects are not processed by the MIME generator! + */ + NSData *encoded; + + content = [[NSData alloc] initWithContentsOfMappedFile:p]; + encoded = [content dataByEncodingBase64]; + [content release]; content = nil; + + [map setObject:@"base64" forKey:@"content-transfer-encoding"]; + [map setObject:[NSNumber numberWithInt:[encoded length]] + forKey:@"content-length"]; + + /* Note: the -init method will create a temporary file! */ + body = [[NGMimeFileData alloc] initWithBytes:[encoded bytes] + length:[encoded length]]; } - [content release]; content = nil; + bodyPart = [[[NGMimeBodyPart alloc] initWithHeader:map] autorelease]; + [bodyPart setBody:body]; + [body release]; body = nil; return bodyPart; } @@ -698,7 +723,6 @@ static BOOL debugOn = NO; - (NGImap4Envelope *)envelope { NSDictionary *lInfo; - NSString *tmp; if (self->envelope != nil) return self->envelope; diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 50b45e87..a02a1955 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=44 +SUBMINOR_VERSION:=45 # v0.9.44 requires NGMime v4.3.194 # v0.9.41 requires NGMime v4.3.190