From d436afb05433bde00040b8b9cdd7432bf5d00bb0 Mon Sep 17 00:00:00 2001 From: smizrahi Date: Mon, 22 May 2023 10:54:48 +0200 Subject: [PATCH] fix(mail): Signature images are not handled properly in forwarded or replied to messages. Save extracted body parts (for signature) into file system. Fixes #5768 --- SoObjects/Mailer/SOGoDraftObject.m | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index d5b723042..ce843cdc4 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -918,7 +918,7 @@ static NSString *userAgent = nil; currentInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: filename, @"filename", mimeType, @"mimetype", - bodyId, @"bodyid", + bodyId, @"bodyId", nil]; [self saveAttachment: body withMetadata: currentInfo]; @@ -1898,6 +1898,39 @@ static NSString *userAgent = nil; newText = [text htmlByExtractingImages: extractedBodyParts]; if ([extractedBodyParts count]) [self setText: newText]; + + int i; + for (i = 0 ; i < [extractedBodyParts count] ; i++) { + NSMutableDictionary *currentInfo; + NSString *filename, *mimeType, *bodyId, *encoding; + NSData *body; + NGMimeBodyPart *extractedBodyPart; + NGMimeContentDispositionHeaderField *contentDisposition; + + extractedBodyPart = [extractedBodyParts objectAtIndex:i]; + encoding = [extractedBodyPart encoding]; + contentDisposition = [[NGMimeContentDispositionHeaderField alloc] initWithString: [extractedBodyPart headerForKey: @"content-disposition"]]; + + mimeType = [[extractedBodyPart contentType] stringValue]; + bodyId = [[extractedBodyPart contentId] stringValue]; + filename = [contentDisposition filename]; + + [contentDisposition release]; + + currentInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: + filename, @"filename", + mimeType, @"mimetype", + bodyId, @"bodyId", + nil]; + // TODO REMOVE data-cke-saved-src ? + if (encoding && [encoding rangeOfString:@"base64"].location != NSNotFound) + body = [[[extractedBodyParts objectAtIndex:i] body] dataByDecodingBase64]; + else + body = [[extractedBodyParts objectAtIndex:i] body]; + + [self saveAttachment: body + withMetadata: currentInfo]; + } } map = [self mimeHeaderMapWithHeaders: _headers