}
- (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;
NSData *content;
BOOL attachAsString;
NSString *p;
+ id body;
if (_name == nil) return nil;
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;
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?
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;
}
- (NGImap4Envelope *)envelope {
NSDictionary *lInfo;
- NSString *tmp;
if (self->envelope != nil)
return self->envelope;