fix(mail): Fix images not displayed when forward / reply to a mail. Fixes #3981

This commit is contained in:
smizrahi committed 2023-03-07 10:17:02 +01:00
1 parent 0d2f6d8c2a
commit 4dc8ef946d
5 files changed
+193 -17

No files matched your search

+33 -1
View File
@@ -42,6 +42,7 @@
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/WOResourceManager+SOGo.h>
#import <SOGo/NGMimeBodyPart+SOGo.h>
#import <SOGoUI/UIxComponent.h>
#import <Mailer/SOGoDraftObject.h>
#import <Mailer/SOGoMailObject+Draft.h>
@@ -702,6 +703,34 @@ static NSArray *infoKeys = nil;
return [[self attachmentAttrs] count] > 0 ? YES : NO;
}
/*
* This method replace cid images in body with base64 inline image data
*/
- (void) setBase64ImagesInText:(SOGoDraftObject *) draft
{
NSString *contentId, *lText;
NGMimeBodyPart *mime;
if ([self isHTML] && [[draft fetchAttachmentAttrs] count] > 0) {
for (NSDictionary *draftFileAttachement in [draft fetchAttachmentAttrs]) {
mime = [draftFileAttachement objectForKey: @"part"];
if ([mime isImage]) {
contentId = [mime contentId];
contentId = [contentId stringByReplacingOccurrencesOfString: @"<" withString: @"cid:"];
contentId = [contentId stringByReplacingOccurrencesOfString: @">" withString: @""];
if ([[mime encoding] isEqualToString: @"base64"]) {
lText = [text stringByReplacingOccurrencesOfString: contentId
withString: [NSString stringWithFormat: @"data:%@;base64,%@",
[[mime contentType] stringValue],
[NSString stringWithUTF8String: [[mime body] bytes]]]];
[self setText: lText];
}
}
}
}
}
- (id <WOActionResults>) editAction
{
id <WOActionResults> response;
@@ -720,7 +749,6 @@ static NSArray *infoKeys = nil;
data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[self localeCode], @"locale",
[NSNumber numberWithBool: [self isHTML]], @"isHTML",
text, @"text",
nil];
if ((value = [self from]))
[data setObject: value forKey: @"from"];
@@ -737,6 +765,10 @@ static NSArray *infoKeys = nil;
if ((value = [self attachmentAttrs]))
[data setObject: value forKey: @"attachmentAttrs"];
[self setBase64ImagesInText: co];
[data setObject: text forKey: @"text"];
response = [self responseWithStatus: 200
andString: [data jsonRepresentation]];