From a09cf589153dd12bb8f740b966051fc4854d8c7a Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 7 Feb 2022 15:00:22 -0500 Subject: [PATCH] fix(mail): ensure is at the end of the document prior parsing Fixes #5477 --- SoObjects/Mailer/NSData+Mail.m | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/SoObjects/Mailer/NSData+Mail.m b/SoObjects/Mailer/NSData+Mail.m index c5b7061fd..9c1fc81ac 100644 --- a/SoObjects/Mailer/NSData+Mail.m +++ b/SoObjects/Mailer/NSData+Mail.m @@ -250,7 +250,7 @@ const char *bytes; char *buf; int i, j, len; - BOOL found_delimiter, in_meta; + BOOL found_delimiter, in_meta, delete_html_end_tag; d = [NSMutableData dataWithData: self]; bytes = [d bytes]; @@ -258,6 +258,7 @@ i = 0; in_meta = NO; + delete_html_end_tag = NO; while (i < len) { @@ -388,6 +389,20 @@ } tag = [tags nextObject]; } + + if ([@"html" caseInsensitiveCompare: found_tag] == NSOrderedSame) + { + // Remove + delete_html_end_tag = YES; + i -= 2; + [d replaceBytesInRange: NSMakeRange(i, 7) + withBytes: NULL + length: 0]; + bytes = [d bytes]; + bytes += i; + len = [d length]; + } + free(buf); // Continue the parsing after end tag @@ -401,6 +416,9 @@ i++; } + if (delete_html_end_tag) + [d appendBytes: "" length: 7]; + return d; }