mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-02-27 04:06:23 +00:00
Monotone-Parent: 3188fd0271db42fb785221461e9a3655109f23a8
Monotone-Revision: 962a83d2b39bca57d666c58151e93ea62a7cd0d3 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-11-20T22:18:19 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user