From e636fc143efca40a36e0925ac995d9a068ffebfa Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 20 Nov 2007 22:18:19 +0000 Subject: [PATCH] Monotone-Parent: 3188fd0271db42fb785221461e9a3655109f23a8 Monotone-Revision: 962a83d2b39bca57d666c58151e93ea62a7cd0d3 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-11-20T22:18:19 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 7 ++ UI/MailPartViewers/GNUmakefile | 2 +- UI/MailPartViewers/UIxMailPartHTMLViewer.m | 81 +++++++++++++++++++++- 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a4b1c0ac..2f24b0ec7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2007-11-20 Wolfgang Sourdeau + * UI/MailPartViewers/UIxMailPartHTMLViewer.m + ([_UIxHTMLMailContentHandler + -setContentEncoding:newContentEncoding]): new method that + specifies an xml charset to return to the parser. + ([UIxMailPartHTMLViewer -flatContentAsString]): specifies the + charset to the content handler before parsing. + * SoObjects/Appointments/SOGoAppointmentObject.m: don't take an empty c_name as a valid response when looking up an event. Create one in that case instead. diff --git a/UI/MailPartViewers/GNUmakefile b/UI/MailPartViewers/GNUmakefile index a86ea4560..8bbcc1c87 100644 --- a/UI/MailPartViewers/GNUmakefile +++ b/UI/MailPartViewers/GNUmakefile @@ -40,7 +40,7 @@ MailPartViewers_LOCALIZED_RESOURCE_FILES += \ # make -ADDITIONAL_INCLUDE_DIRS += -I../../SOPE/ +ADDITIONAL_INCLUDE_DIRS += $(shell xml2-config --cflags) ADDITIONAL_LIB_DIRS += -L../../SOPE/GDLContentStore/obj/ -include GNUmakefile.preamble diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.m b/UI/MailPartViewers/UIxMailPartHTMLViewer.m index 6be09e6dd..c93c83b26 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.m +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.m @@ -22,6 +22,9 @@ #import #import +#import +#import + #import #import #import @@ -30,6 +33,8 @@ #import #import +#include + #import "UIxMailPartHTMLViewer.h" #if 0 @@ -49,6 +54,7 @@ BOOL inCSSDeclaration; BOOL hasEmbeddedCSS; NSMutableArray *crumb; + xmlCharEncoding contentEncoding; } - (NSString *) result; @@ -65,6 +71,7 @@ css = nil; result = nil; attachmentIds = nil; + contentEncoding = XML_CHAR_ENCODING_UTF8; } return self; @@ -78,6 +85,16 @@ [super dealloc]; } +- (void) setContentEncoding: (xmlCharEncoding) newContentEncoding +{ + contentEncoding = newContentEncoding; +} + +- (xmlCharEncoding) contentEncoding +{ + return contentEncoding; +} + - (void) setAttachmentIds: (NSDictionary *) newAttachmentIds { attachmentIds = newAttachmentIds; @@ -463,17 +480,79 @@ return attachmentIds; } +- (xmlCharEncoding) _xmlCharsetForCharset: (NSString *) charset +{ + struct { NSString *name; xmlCharEncoding encoding; } xmlEncodings[] = { + { @"us-ascii", XML_CHAR_ENCODING_NONE}, + { @"utf-8", XML_CHAR_ENCODING_UTF8}, + { @"utf-16le", XML_CHAR_ENCODING_UTF16LE}, + { @"utf-16be", XML_CHAR_ENCODING_UTF16BE}, + { @"ucs-4le", XML_CHAR_ENCODING_UCS4LE}, + { @"ucs-4be", XML_CHAR_ENCODING_UCS4BE}, + { @"ebcdic", XML_CHAR_ENCODING_EBCDIC}, +// { @"iso-10646" , XML_CHAR_ENCODING_UCS4_2143}, +// { , XML_CHAR_ENCODING_UCS4_3412}, +// { @"ucs-2", XML_CHAR_ENCODING_UCS2}, + { @"iso8859_1", XML_CHAR_ENCODING_8859_1}, + { @"iso-8859-1", XML_CHAR_ENCODING_8859_1}, + { @"iso-8859-2", XML_CHAR_ENCODING_8859_2}, + { @"iso-8859-3", XML_CHAR_ENCODING_8859_3}, + { @"iso-8859-4", XML_CHAR_ENCODING_8859_4}, + { @"iso-8859-5", XML_CHAR_ENCODING_8859_5}, + { @"iso-8859-6", XML_CHAR_ENCODING_8859_6}, + { @"iso-8859-7", XML_CHAR_ENCODING_8859_7}, + { @"iso-8859-8", XML_CHAR_ENCODING_8859_8}, + { @"iso-8859-9", XML_CHAR_ENCODING_8859_9}, + { @"iso-2022-jp", XML_CHAR_ENCODING_2022_JP}, +// { @"iso-2022-jp", XML_CHAR_ENCODING_SHIFT_JIS}, + { @"euc-jp", XML_CHAR_ENCODING_EUC_JP}, + { @"us-ascii", XML_CHAR_ENCODING_ASCII}}; + unsigned count; + xmlCharEncoding encoding; + + encoding = XML_CHAR_ENCODING_NONE; + count = 0; + + while (encoding == XML_CHAR_ENCODING_NONE + && count < (sizeof (xmlEncodings) / sizeof (xmlEncodings[0]))) + if ([charset isEqualToString: xmlEncodings[count].name]) + encoding = xmlEncodings[count].encoding; + else + count++; + + if (encoding == XML_CHAR_ENCODING_NONE) + encoding = XML_CHAR_ENCODING_8859_1; + + return encoding; +} + +- (xmlCharEncoding) _xmlCharEncoding +{ + + NSString *charset; + + charset = [[bodyInfo objectForKey:@"parameterList"] + objectForKey: @"charset"]; + if (![charset length]) + charset = @"us-ascii"; + + return [self _xmlCharsetForCharset: [charset lowercaseString]]; +} + - (void) _parseContent { - id parser; + NSObject *parser; NSData *preparsedContent; preparsedContent = [super decodedFlatContent]; parser = [[SaxXMLReaderFactory standardXMLReaderFactory] createXMLReaderForMimeType: @"text/html"]; + [parser setValue: [NSNumber numberWithBool: NO] + forKey: @"encodeEntities"]; handler = [_UIxHTMLMailContentHandler new]; [handler setAttachmentIds: [self _attachmentIds]]; + [handler setContentEncoding: [self _xmlCharEncoding]]; [parser setContentHandler: handler]; [parser parseFromSource: preparsedContent]; }