From 9a12fb24a64fe50457c17f7608ba10e0763873bf Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 23 Nov 2015 18:07:50 -0500 Subject: [PATCH] (fix) EAS fix for wrong charset being used (#3392) --- ActiveSync/SOGoMailObject+ActiveSync.m | 36 ++++++++++++++++++++++---- NEWS | 1 + 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ActiveSync/SOGoMailObject+ActiveSync.m b/ActiveSync/SOGoMailObject+ActiveSync.m index 763ed20f2..434e6b9c9 100644 --- a/ActiveSync/SOGoMailObject+ActiveSync.m +++ b/ActiveSync/SOGoMailObject+ActiveSync.m @@ -472,6 +472,32 @@ struct GlobalObjectId { return d; } +// +// +// +- (BOOL) _sanitinizeNeeded: (NSArray *) theParts +{ + NSString *encoding, *charset; + int i; + + for (i = 0; i < [theParts count]; i++) + { + encoding = [[theParts objectAtIndex: i ] objectForKey: @"encoding"]; + charset = [[[theParts objectAtIndex: i ] objectForKey: @"parameterList"] objectForKey: @"charset"]; + if (encoding && [encoding caseInsensitiveCompare: @"8bit"] == NSOrderedSame && + charset && ![charset caseInsensitiveCompare: @"utf-8"] == NSOrderedSame + && ![charset caseInsensitiveCompare: @"us-ascii"] == NSOrderedSame) + { + return YES; + } + + if ([self _sanitinizeNeeded: [[theParts objectAtIndex: i ] objectForKey: @"parts"]]) + return YES; + } + + return NO; +} + // // // @@ -481,7 +507,7 @@ struct GlobalObjectId { { NSString *type, *subtype, *encoding; NSData *d; - BOOL isSMIME; + BOOL isSMIME, sanitinizeNeeded; type = [[[self bodyStructure] valueForKey: @"type"] lowercaseString]; subtype = [[[self bodyStructure] valueForKey: @"subtype"] lowercaseString]; @@ -546,10 +572,10 @@ struct GlobalObjectId { } else if (theType == 4 || isSMIME) { - // We sanitize the content *ONLY* for Outlook clients and if the content-transfer-encoding is 8bit. Outlook has strange issues - // with quoted-printable/base64 encoded text parts. It just doesn't decode them. - encoding = [[self lookupInfoForBodyPart: @""] objectForKey: @"encoding"]; - if ((encoding && ([encoding caseInsensitiveCompare: @"8bit"] == NSOrderedSame)) && !isSMIME) + // We sanitize the content if the content-transfer-encoding is 8bit and charset is not utf-8 or us-ascii. + sanitinizeNeeded = [self _sanitinizeNeeded: [NSArray arrayWithObject: [self bodyStructure]]]; + + if (sanitinizeNeeded && !isSMIME) d = [self _sanitizedMIMEMessage]; else d = [self content]; diff --git a/NEWS b/NEWS index 397c1c391..45bd8d075 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ Enhancements Bug fixes - JavaScript exception when printing events from calendars with no assigned color (#3203) + - EAS fix for wrong charset being used (#3392) 2.3.3a (2015-11-18) -------------------