From 08cd080d47f4ef0d0d262021e173b5d6c6519276 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 21 Jul 2014 15:34:56 -0400 Subject: [PATCH] Fixed charset substitution in meta tags --- NEWS | 1 + UI/MailPartViewers/UIxMailPartHTMLViewer.m | 36 ++++++++++++---------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index fee5437c5..4d0c02d78 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Bug fixes - fixed rename of calendars - we now correctly add the "METHOD:REPLY" when sending out ITIP messages from DAV clients - fixed refresh of message headers when forwarding a message (#2818) + - we now correctly escape all charset= in tags, not only in the 2.2.6 (2014-07-02) ------------------ diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.m b/UI/MailPartViewers/UIxMailPartHTMLViewer.m index 7160f6ba2..09d48ae5a 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.m +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.m @@ -146,34 +146,34 @@ static NSData* _sanitizeContent(NSData *theData) const char *bytes; char *buf; int i, j, len; - BOOL found_delimiter; + BOOL found_delimiter, in_meta; d = [NSMutableData dataWithData: theData]; bytes = [d bytes]; len = [d length]; i = 0; + in_meta = NO; + while (i < len) { - // We check if we see in which case, we don't do any kind - // of substitution there after. - if (i < len-6) + // We check if we see in which case, we substitute de charset= stuff. + if (i < len-5) { if ((*bytes == '<') && - (*(bytes+1) == '/') && - (*(bytes+2) == 'h' || *(bytes+2) == 'H') && - (*(bytes+3) == 'e' || *(bytes+3) == 'E') && - (*(bytes+4) == 'a' || *(bytes+4) == 'A') && - (*(bytes+5) == 'd' || *(bytes+5) == 'D') && - (*(bytes+6) == '>')) - break; + (*(bytes+1) == 'm' || *(bytes+2) == 'M') && + (*(bytes+2) == 'e' || *(bytes+3) == 'E') && + (*(bytes+3) == 't' || *(bytes+4) == 'T') && + (*(bytes+4) == 'a' || *(bytes+5) == 'A') && + (*(bytes+5) == ' ')) + in_meta = YES; } // We search for something like : // // // - if (i < len-9) + if (in_meta && i < len-9) { if ((*bytes == 'c' || *bytes == 'C') && (*(bytes+1) == 'h' || *(bytes+1) == 'H') && @@ -195,16 +195,18 @@ static NSData* _sanitizeContent(NSData *theData) // We haven't found anything, let's return the data untouched if ((i+j) >= len) { - found_delimiter = NO; + in_meta = found_delimiter = NO; break; } } if (found_delimiter) - [d replaceBytesInRange: NSMakeRange(i, j) - withBytes: NULL - length: 0]; - break; + { + [d replaceBytesInRange: NSMakeRange(i, j) + withBytes: NULL + length: 0]; + in_meta = found_delimiter = NO; + } } }