From 12875539bbbd94987fbf4f37beea9f3e3a5c94a8 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 23 Jul 2015 10:22:36 -0400 Subject: [PATCH] (fix) fallback to utf-8/latin1 in rare decoding error cases - this is ugly --- UI/MailPartViewers/UIxMailPartHTMLViewer.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.m b/UI/MailPartViewers/UIxMailPartHTMLViewer.m index ca41c7f62..f1ead5ffd 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.m +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.m @@ -872,6 +872,19 @@ static NSData* _sanitizeContent(NSData *theData) usingEncodingNamed: [[bodyInfo objectForKey:@"parameterList"] objectForKey: @"charset"]]; + // In some rare cases (like #3276), we can get utterly broken email messages where + // HTML parts are wrongly encoded. We try to fall back to UTF-8 if that happens and + // if it still happens, we fall back to ISO-Latin-1. + if (!s) + { + s = [[NSString alloc] initWithData: preparsedContent encoding: NSUTF8StringEncoding]; + + if (!s) + s = [[NSString alloc] initWithData: preparsedContent encoding: NSISOLatin1StringEncoding]; + + AUTORELEASE(s); + } + #if BYTE_ORDER == BIG_ENDIAN preparsedContent = [s dataUsingEncoding: NSUTF16BigEndianStringEncoding]; enc = XML_CHAR_ENCODING_UTF16BE;