From 47075b40a2435b24ef00847c3901fe9d31ef9db9 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 4 Dec 2019 15:45:26 -0500 Subject: [PATCH] fix(mail): wrap HTML part with HTML tags to render all content --- UI/MailPartViewers/UIxMailPartHTMLViewer.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.m b/UI/MailPartViewers/UIxMailPartHTMLViewer.m index c339393de..187336d71 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.m +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.m @@ -1,6 +1,6 @@ /* UIxMailPartHTMLViewer.m - this file is part of SOGo * - * Copyright (C) 2007-2017 Inverse inc. + * Copyright (C) 2007-2019 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -795,6 +795,7 @@ _xmlCharsetForCharset (NSString *charset) { NSObject *parser; NSData *preparsedContent; + NSMutableData *htmlContent; NSString *s; xmlCharEncoding enc; @@ -858,10 +859,17 @@ _xmlCharsetForCharset (NSString *charset) RELEASE(s); } + // Some broken email messages have some additionnal content outside the main HTML tags which are + // ignored by libxml. + // We surround the whole part with additional HTML tags to render all content. + htmlContent = [NSMutableData dataWithBytes: "" length: 6]; + [htmlContent appendData: preparsedContent]; + [htmlContent appendBytes: "" length: 7]; + [handler setContentEncoding: enc]; [parser setContentHandler: handler]; - [parser parseFromSource: preparsedContent]; + [parser parseFromSource: htmlContent]; } - (NSString *) cssContent