diff --git a/ActiveSync/SOGoMailObject+ActiveSync.m b/ActiveSync/SOGoMailObject+ActiveSync.m index 58dca5cf1..e5f349092 100644 --- a/ActiveSync/SOGoMailObject+ActiveSync.m +++ b/ActiveSync/SOGoMailObject+ActiveSync.m @@ -238,6 +238,8 @@ struct GlobalObjectId { if (key) { + NSString *s, *charset; + d = [[self fetchPlainTextParts] objectForKey: key]; encoding = [[self lookupInfoForBodyPart: key] objectForKey: @"encoding"]; @@ -246,6 +248,14 @@ struct GlobalObjectId { d = [d dataByDecodingBase64]; else if ([encoding caseInsensitiveCompare: @"quoted-printable"] == NSOrderedSame) d = [d dataByDecodingQuotedPrintableTransferEncoding]; + + charset = [[[self lookupInfoForBodyPart: key] objectForKey: @"parameterList"] objectForKey: @"charset"]; + + if (![charset length]) + charset = @"us-ascii"; + + s = [NSString stringWithData: d usingEncodingNamed: charset]; + d = [s dataUsingEncoding: NSUTF8StringEncoding]; } return d; @@ -296,13 +306,13 @@ struct GlobalObjectId { if ([body isKindOfClass: [NSData class]]) { NSString *charset; - int encoding; - + charset = [[thePart contentType] valueOfParameter: @"charset"]; - encoding = [NGMimeType stringEncodingForCharset: charset]; + + if (![charset length]) + charset = @"us-ascii"; - s = [[NSString alloc] initWithData: body encoding: encoding]; - AUTORELEASE(s); + s = [NSString stringWithData: body usingEncodingNamed: charset]; } else { @@ -396,6 +406,13 @@ struct GlobalObjectId { { if ([type isEqualToString: @"text"]) { + NSString *s, *charset; + + charset = [[[self lookupInfoForBodyPart: @""] objectForKey: @"parameterList"] objectForKey: @"charset"]; + + if (![charset length]) + charset = @"us-ascii"; + d = [[self fetchPlainTextParts] objectForKey: @""]; // We check if we have base64 encoded parts. If so, we just @@ -407,17 +424,15 @@ struct GlobalObjectId { else if ([encoding caseInsensitiveCompare: @"quoted-printable"] == NSOrderedSame) d = [d dataByDecodingQuotedPrintableTransferEncoding]; + s = [NSString stringWithData: d usingEncodingNamed: charset]; + // Check if we must convert html->plain if (theType == 1 && [subtype isEqualToString: @"html"]) { - NSString *s; - - s = [[NSString alloc] initWithData: d encoding: NSUTF8StringEncoding]; - AUTORELEASE(s); - s = [s htmlToText]; - d = [s dataUsingEncoding: NSUTF8StringEncoding]; } + + d = [s dataUsingEncoding: NSUTF8StringEncoding]; } else if ([type isEqualToString: @"multipart"]) { diff --git a/NEWS b/NEWS index 46be9433c..d83925097 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,7 @@ Bug fixes - avoid raising exceptions when the db is down and we try to access the preferences module (#2813) - we now ignore the SCHEDULE-AGENT property when Thunderbird/Ligthning sends it to avoid not-generating invitation responses for externally received IMIP messages + - improved charset handling over ActiveSync (#2810) 2.2.5 (2014-06-05) ------------------