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
@@ -179,8 +179,9 @@
id info, viewer;
NSArray *parts;
NSMutableArray *renderedParts;
NSString *preferredType;
NSString *preferredType, *htmlNoTags;
NSUInteger i, max;
BOOL fallbackNeeded, hasTextPlain;
if ([self decodedFlatContent])
parts = [[self decodedFlatContent] parts];
@@ -214,6 +215,27 @@
[[self childInfo] objectForKey: @"type"],
[[self childInfo] objectForKey: @"subtype"]];
// Check if the HTML part is good
// If no, try to fallback on text/plain
fallbackNeeded = NO;
hasTextPlain = NO;
for (i = 0 ; i < [renderedParts length] ; i++) {
if ([[[[renderedParts objectAtIndex: i] objectForKey: @"contentType"] lowercaseString] isEqualToString: @"text/html"]
&& [[preferredType lowercaseString] isEqualToString: @"text/html"]) {
if ([[renderedParts objectAtIndex: i] objectForKey:@"exception"]) {
fallbackNeeded = YES;
}
}
if ([[[[renderedParts objectAtIndex: i] objectForKey: @"contentType"] lowercaseString] isEqualToString: @"text/plain"]) {
hasTextPlain = YES;
}
}
if (fallbackNeeded && hasTextPlain) {
preferredType = @"text/plain";
}
return [NSDictionary dictionaryWithObjectsAndKeys:
[self className], @"type",
preferredType, @"preferredPart",