From ef88039a4a3d590de09cf75da5668db9d6fd29f0 Mon Sep 17 00:00:00 2001 From: smizrahi Date: Thu, 11 Jul 2024 17:41:14 +0200 Subject: [PATCH] fix(mail): Fix invalid content when forwarding a text/plain mail. Fixes #5983. --- SoObjects/Mailer/SOGoMailObject+Draft.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SoObjects/Mailer/SOGoMailObject+Draft.m b/SoObjects/Mailer/SOGoMailObject+Draft.m index 1749564f1a..ffb3af3717 100644 --- a/SoObjects/Mailer/SOGoMailObject+Draft.m +++ b/SoObjects/Mailer/SOGoMailObject+Draft.m @@ -134,9 +134,13 @@ - (NSString *) _contentForEditingFromKeys: (NSArray *) keys // Ticket https://bugs.sogo.nu/view.php?id=5983 // In this case, the first HTML content is used, but it can be the previous forwarded mail // We check if there is a text/plain before text/html in the types array - // and if the key is not `body[1` (second part of the mail) // is this case, the text/plain is used prior to text/html. - if (index != NSNotFound && indexTextPlain != NSNotFound && indexTextPlain < index && [[[keys objectAtIndex: index] objectForKey:@"key"] rangeOfString:@"body[1"].location == NSNotFound) + if (index != NSNotFound // There is a text/html part + && indexTextPlain != NSNotFound // There is a text/plain part + && indexTextPlain < index // text/plain is before text/html + && (indexTextPlain + 1) < [keys count] // text/plain is not the last part of the mail + && [[[keys objectAtIndex: (indexTextPlain + 1)] objectForKey:@"mimeType"] rangeOfString:@"text/plain"].location != NSNotFound // The text/plain is followed up by another text/plain + ) index = indexTextPlain; else if (index == NSNotFound) index = [types indexOfObject: @"text/plain"];