Skip to content

Commit

Permalink
Fix for bug #2217
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Sep 19, 2013
1 parent 5b77c2b commit 91f1ab6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 36 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -9,6 +9,7 @@ Enhancements
- Added support for LDAP password change against AD/Samba4
- Added apache configuration for Apple autoconfiguration (#2248)
- The init scripts now start 3 sogod processes by default instead of 1
- SOGo now also sends a plain/text parts when sending HTML mails (#2217)

Bug fixes
- Fixed Finnish mail reply/forward templates (#2401)
Expand All @@ -23,6 +24,7 @@ Bug fixes
- Worked around an issue with chunked encoding of CAS replies (#2408)
- Avoid crash when handling malformed or non-ASCII http credentials (#2358)
- Fixed crontab error (#2372)
- Fixed OpenChange corruption issue regarding predecessors change list

2.0.7 (2013-07-19)
------------------
Expand Down
119 changes: 84 additions & 35 deletions SoObjects/Mailer/SOGoDraftObject.m
Expand Up @@ -171,12 +171,17 @@ -(NSRange) rangeOfCString: (const char *) theCString
@implementation SOGoDraftObject

static NGMimeType *MultiMixedType = nil;
static NGMimeType *MultiAlternativeType = nil;
static NSString *userAgent = nil;

+ (void) initialize
{
MultiMixedType = [NGMimeType mimeType: @"multipart" subType: @"mixed"];
[MultiMixedType retain];

MultiAlternativeType = [NGMimeType mimeType: @"multipart" subType: @"alternative"];
[MultiAlternativeType retain];

userAgent = [NSString stringWithFormat: @"SOGoMail %@",
SOGoVersion];
[userAgent retain];
Expand Down Expand Up @@ -981,8 +986,33 @@ - (NSException *) deleteAttachmentWithName: (NSString *) _name
return error;
}

/* NGMime representations */
//
// Only called when converting text/html to text/plain parts
//
- (NGMimeBodyPart *) plainTextBodyPartForText
{
NGMutableHashMap *map;
NGMimeBodyPart *bodyPart;
NSString *plainText;

/* prepare header of body part */
map = [[[NGMutableHashMap alloc] initWithCapacity: 1] autorelease];

[map setObject: contentTypeValue forKey: @"content-type"];

/* prepare body content */
bodyPart = [[[NGMimeBodyPart alloc] initWithHeader:map] autorelease];

plainText = [text htmlToText];
[bodyPart setBody: plainText];

return bodyPart;
}


//
//
//
- (NGMimeBodyPart *) bodyPartForText
{
/*
Expand All @@ -992,25 +1022,14 @@ This add the text typed by the user (the primary plain/text part).
NGMimeBodyPart *bodyPart;

/* prepare header of body part */

map = [[[NGMutableHashMap alloc] initWithCapacity: 1] autorelease];

// TODO: set charset in header!
[map setObject: @"text/plain" forKey: @"content-type"];
if (text)
[map setObject: (isHTML ? htmlContentTypeValue : contentTypeValue)
forKey: @"content-type"];

// if ((body = text) != nil) {
// if ([body isKindOfClass: [NSString class]]) {
// [map setObject: contentTypeValue
// forKey: @"content-type"];
// // body = [body dataUsingEncoding:NSUTF8StringEncoding];
// }
// }

/* prepare body content */

bodyPart = [[[NGMimeBodyPart alloc] initWithHeader:map] autorelease];
[bodyPart setBody: text];

Expand All @@ -1020,32 +1039,29 @@ This add the text typed by the user (the primary plain/text part).
- (NGMimeMessage *) mimeMessageForContentWithHeaderMap: (NGMutableHashMap *) map
{
NGMimeMessage *message;
// BOOL addSuffix;
id body;
id body;

[map setObject: @"text/plain" forKey: @"content-type"];
body = text;
if (body)
message = [[[NGMimeMessage alloc] initWithHeader:map] autorelease];

if (!isHTML)
{
// if ([body isKindOfClass:[NSString class]])
/* Note: just 'utf8' is displayed wrong in Mail.app */
[map setObject: (isHTML ? htmlContentTypeValue : contentTypeValue)
forKey: @"content-type"];
// body = [body dataUsingEncoding:NSUTF8StringEncoding];
// else if ([body isKindOfClass:[NSData class]] && addSuffix) {
// body = [[body mutableCopy] autorelease];
// }
// else if (addSuffix) {
// [self warnWithFormat: @"Note: cannot add Internet marker to body: %@",
// NSStringFromClass([body class])];
// }

message = [[[NGMimeMessage alloc] initWithHeader:map] autorelease];
[message setBody: body];
[map setObject: contentTypeValue forKey: @"content-type"];
body = text;
}
else
message = nil;
{
body = [[[NGMimeMultipartBody alloc] initWithPart: message] autorelease];
[map addObject: MultiAlternativeType forKey: @"content-type"];

// Add the HTML part
[body addBodyPart: [self bodyPartForText]];

// Get the text part from it and add it too
[body addBodyPart: [self plainTextBodyPartForText]];
}

[message setBody: body];

return message;
}

Expand Down Expand Up @@ -1232,21 +1248,54 @@ - (NSArray *) bodyPartsForAllAttachments
return bodyParts;
}

- (NGMimeBodyPart *) mimeMultipartAlternative
{
NGMimeMultipartBody *textParts;
NGMutableHashMap *header;
NGMimeBodyPart *part;

header = [NGMutableHashMap hashMap];
[header addObject: MultiAlternativeType forKey: @"content-type"];

part = [NGMimeBodyPart bodyPartWithHeader: header];

textParts = [[NGMimeMultipartBody alloc] initWithPart: part];

// Add the HTML part
[textParts addBodyPart: [self bodyPartForText]];

// Get the text part from it and add it too
[textParts addBodyPart: [self plainTextBodyPartForText]];

[part setBody: textParts];
RELEASE(textParts);

return part;
}

- (NGMimeMessage *) mimeMultiPartMessageWithHeaderMap: (NGMutableHashMap *) map
andBodyParts: (NSArray *) _bodyParts
{
NGMimeMessage *message;
NGMimeMultipartBody *mBody;
NGMimeBodyPart *part;
NSEnumerator *e;
id part;

[map addObject: MultiMixedType forKey: @"content-type"];

message = [[NGMimeMessage alloc] initWithHeader: map];
[message autorelease];
mBody = [[NGMimeMultipartBody alloc] initWithPart: message];

if (!isHTML)
{
part = [self bodyPartForText];
}
else
{
part = [self mimeMultipartAlternative];
}

part = [self bodyPartForText];
[mBody addBodyPart: part];

e = [_bodyParts objectEnumerator];
Expand Down
2 changes: 1 addition & 1 deletion UI/MailerUI/UIxMailEditor.m
Expand Up @@ -567,8 +567,8 @@ - (BOOL) _saveFormInfo
{
info = [self storeInfo];
[co setHeaders: info];
[co setText: text];
[co setIsHTML: isHTML];
[co setText: (isHTML ? [NSString stringWithFormat: @"<html>%@</html>", text] : text)];;
error = [co storeInfo];
if (error)
{
Expand Down

0 comments on commit 91f1ab6

Please sign in to comment.