fix(mail): Use text/plain fallback if an error occured while parsing html message

This commit is contained in:
smizrahi
2024-02-05 10:50:07 +01:00
parent ce0e650c62
commit f56910db1e
4 changed files with 112 additions and 5 deletions

View File

@@ -750,6 +750,7 @@ _xmlCharsetForCharset (NSString *charset)
if ((self = [super init]))
{
handler = nil;
ex = nil;
}
return self;
@@ -758,6 +759,9 @@ _xmlCharsetForCharset (NSString *charset)
- (void) dealloc
{
[handler release];
if (ex) {
[ex release];
}
[super dealloc];
}
@@ -782,6 +786,8 @@ _xmlCharsetForCharset (NSString *charset)
xmlCharEncoding enc;
[self cleanException];
if ([[self decodedFlatContent] isKindOfClass: [NGMimeBodyPart class]])
preparsedContent = [[[self decodedFlatContent] body] sanitizedContentUsingVoidTags: VoidTags];
else
@@ -852,9 +858,37 @@ _xmlCharsetForCharset (NSString *charset)
[handler setContentEncoding: enc];
[parser setContentHandler: handler];
[parser setErrorHandler: self];
[parser parseFromSource: preparsedContent];
}
- (void)cleanException
{
ex = nil;
}
- (void)warning:(SaxParseException *)_exception
{
}
- (void)error:(SaxParseException *)_exception
{
}
- (void)fatalError:(SaxParseException *)_exception
{
ex = [NSException exceptionWithName:[_exception name] reason: [_exception reason] userInfo: [_exception userInfo]];
[ex retain];
}
- (NSException *)getException
{
return ex;
}
- (NSString *) cssContent
{
NSString *cssContent, *css;
@@ -890,6 +924,7 @@ _xmlCharsetForCharset (NSString *charset)
if ((self = [super init]))
{
handler = nil;
ex = nil;
}
return self;
@@ -898,6 +933,9 @@ _xmlCharsetForCharset (NSString *charset)
- (void) dealloc
{
[handler release];
if (ex) {
[ex release];
}
[super dealloc];
}
@@ -921,6 +959,8 @@ _xmlCharsetForCharset (NSString *charset)
NSString *encoding;
xmlCharEncoding enc;
[self cleanException];
parser = [[SaxXMLReaderFactory standardXMLReaderFactory]
createXMLReaderForMimeType: @"text/html"];
@@ -966,9 +1006,36 @@ _xmlCharsetForCharset (NSString *charset)
[handler setContentEncoding: enc];
[parser setContentHandler: handler];
[parser setErrorHandler: self];
[parser parseFromSource: preparsedContent];
}
- (void)cleanException
{
ex = nil;
}
- (void)warning:(SaxParseException *)_exception
{
}
- (void)error:(SaxParseException *)_exception
{
}
- (void)fatalError:(SaxParseException *)_exception
{
ex = [NSException exceptionWithName:[_exception name] reason: [_exception reason] userInfo: [_exception userInfo]];
[ex retain];
}
- (NSException *)getException
{
return ex;
}
- (NSString *) filename
{
return [[self clientObject] filename];