Monotone-Parent: 3188fd0271db42fb785221461e9a3655109f23a8

Monotone-Revision: 962a83d2b39bca57d666c58151e93ea62a7cd0d3

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-11-20T22:18:19
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2007-11-20 22:18:19 +00:00
parent 4522bd5626
commit e636fc143e
3 changed files with 88 additions and 2 deletions

View File

@ -1,5 +1,12 @@
2007-11-20 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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.

View File

@ -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

View File

@ -22,6 +22,9 @@
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSValue.h>
#import <SaxObjC/SaxAttributes.h>
#import <SaxObjC/SaxContentHandler.h>
#import <SaxObjC/SaxLexicalHandler.h>
@ -30,6 +33,8 @@
#import <NGExtensions/NSString+misc.h>
#import <NGObjWeb/SoObjects.h>
#include <libxml/encoding.h>
#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 <NSObject, SaxXMLReader> parser;
NSObject <SaxXMLReader> *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];
}