Skip to content

Commit

Permalink
fix(mail): Fix invalid content when forwarding a text/plain mail. Fix…
Browse files Browse the repository at this point in the history
…es #5983.
  • Loading branch information
WoodySlum committed Jun 24, 2024
1 parent eee160e commit 43388ac
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions SoObjects/Mailer/SOGoMailObject+Draft.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ - (NSString *) _contentForEditingFromKeys: (NSArray *) keys
NSData *data;

BOOL htmlComposition, htmlContent;
NSUInteger index;
NSUInteger index, indexTextPlain;

content = @"";

Expand All @@ -129,8 +129,16 @@ - (NSString *) _contentForEditingFromKeys: (NSArray *) keys
if (htmlComposition)
{
// Prefer HTML content
indexTextPlain = [types indexOfObject: @"text/plain"];
index = [types indexOfObject: @"text/html"];
if (index == NSNotFound)
// 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)
index = indexTextPlain;
else if (index == NSNotFound)
index = [types indexOfObject: @"text/plain"];
else
htmlContent = YES;
Expand Down

0 comments on commit 43388ac

Please sign in to comment.