From 0edd3f757fc07aabd4270b393677cea6ff4a8ed6 Mon Sep 17 00:00:00 2001 From: smizrahi Date: Mon, 3 Apr 2023 19:11:53 +0200 Subject: [PATCH] fix(mail): Removed attachements of images when replying to a mail. As the image is inline, the attachement shall be removed. --- UI/MailerUI/UIxMailEditor.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/UI/MailerUI/UIxMailEditor.m b/UI/MailerUI/UIxMailEditor.m index bb5c175d0..4464ab403 100644 --- a/UI/MailerUI/UIxMailEditor.m +++ b/UI/MailerUI/UIxMailEditor.m @@ -721,11 +721,20 @@ static NSArray *infoKeys = nil; contentId = [contentId stringByReplacingOccurrencesOfString: @">" withString: @""]; if ([[mime encoding] isEqualToString: @"base64"] && contentId) { - lText = [text stringByReplacingOccurrencesOfString: contentId - withString: [NSString stringWithFormat: @"data:%@;base64,%@", - [[mime contentType] stringValue], - [NSString stringWithUTF8String: [[mime body] bytes]]]]; - [self setText: lText]; + if ([text rangeOfString: contentId].location != NSNotFound) { + lText = [text stringByReplacingOccurrencesOfString: contentId + withString: [NSString stringWithFormat: @"data:%@;base64,%@", + [[mime contentType] stringValue], + [NSString stringWithUTF8String: [[mime body] bytes]]]]; + [self setText: lText]; + [draft deleteAttachmentWithName: [draftFileAttachement objectForKey:@"filename"]]; + } else { + // This is an attachment with no CID in message body + if ([draft inReplyTo]) { + // If the image has no CID and the draft is a reply (not forward, the images in attachement should be removed) + [draft deleteAttachmentWithName: [draftFileAttachement objectForKey:@"filename"]]; + } + } } else { [self warnWithFormat: @"Empty content id [1] : %@", contentId]; }