From ca2c5c188ed980629f494e5b8e23ba42cdd54f58 Mon Sep 17 00:00:00 2001 From: smizrahi Date: Fri, 17 Nov 2023 10:46:12 +0100 Subject: [PATCH] feat(mail): Add SOGoMailHideInlineAttachments option to hide attachments when inline. Fixes #5490. Improve bracket icon. --- UI/MailerUI/UIxMailListActions.m | 54 +++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/UI/MailerUI/UIxMailListActions.m b/UI/MailerUI/UIxMailListActions.m index ff62f6d3c..719d326fd 100644 --- a/UI/MailerUI/UIxMailListActions.m +++ b/UI/MailerUI/UIxMailListActions.m @@ -314,24 +314,54 @@ return [[[self message] valueForKey:@"uid"] stringValue]; } +- (BOOL) parseParts: (NSArray *) parts hasAttachment:(BOOL) hasAttachment { + NSEnumerator *part; + NSDictionary *currentPart; + SOGoUserDefaults *ud; + BOOL isInline; + + ud = [[[self context] activeUser] userDefaults]; + + if ([parts count] > 1) + { + part = [parts objectEnumerator]; + while (!hasAttachment + && (currentPart = [part nextObject])) { + if ([currentPart objectForKey: @"type"] && ![[[currentPart objectForKey: @"type"] uppercaseString] hasPrefix: @"MULTIPART"]) { + isInline = currentPart && [currentPart objectForKey:@"disposition"] + && [[currentPart objectForKey:@"disposition"] objectForKey:@"type"] + && [[[[currentPart objectForKey:@"disposition"] objectForKey:@"type"] uppercaseString] isEqualToString:@"INLINE"]; + if (![ud hideInlineAttachments] || ([ud hideInlineAttachments] && !isInline)) { + hasAttachment = (([currentPart objectForKey:@"disposition"] + && [[[currentPart objectForKey:@"disposition"] allKeys] length] > 0) + || ([currentPart objectForKey:@"parameterList"] + && [[currentPart objectForKey:@"parameterList"] objectForKey:@"name"] + )); + } + } else if ([currentPart objectForKey:@"parts"]) { + hasAttachment = [self parseParts: [currentPart objectForKey:@"parts"] hasAttachment: hasAttachment]; + } + } + } + + return hasAttachment; +} + - (BOOL) hasMessageAttachment { - NSArray *parts; - NSEnumerator *dispositions; - NSDictionary *currentDisp; BOOL hasAttachment; hasAttachment = NO; - parts = [[message objectForKey: @"bodystructure"] objectForKey: @"parts"]; - if ([parts count] > 1) - { - dispositions = [[parts objectsForKey: @"disposition" - notFoundMarker: nil] objectEnumerator]; - while (!hasAttachment - && (currentDisp = [dispositions nextObject])) - hasAttachment = ([[currentDisp objectForKey: @"type"] length]); - } + NS_DURING + { + hasAttachment = [self parseParts: [[message objectForKey: @"bodystructure"] objectForKey: @"parts"] hasAttachment:hasAttachment]; + } + NS_HANDLER + { + [self logWithFormat: @"Error while parsing attachements for rendering bracket"]; + } + NS_ENDHANDLER; return hasAttachment; }