From dff907a158f9b8d7d2ca69e2ad33c7a4dd562abf Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Nov 2022 11:05:33 +0100 Subject: [PATCH] fix(eas) ensure correct encoding of attachments(fixes #5330) --- ActiveSync/SOGoActiveSyncDispatcher.m | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 1eb82cd55..03b378690 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -63,6 +63,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import #import +#import #import #import #import @@ -4027,6 +4028,7 @@ void handle_eas_terminate(int signum) for (j = 0; j < [aparts count]; j++) { apart = [aparts objectAtIndex: j]; + if ([[[apart contentType] type] isEqualToString: @"text"] && [[[apart contentType] subType] isEqualToString: @"html"]) htmlPart = apart; if ([[[apart contentType] type] isEqualToString: @"text"] && [[[apart contentType] subType] isEqualToString: @"plain"]) @@ -4035,12 +4037,23 @@ void handle_eas_terminate(int signum) } else { - if ([[[part contentType] type] isEqualToString: @"text"] && [[[part contentType] subType] isEqualToString: @"html"]) + if ([[(NGMimeContentDispositionHeaderField *)[part headerForKey: @"content-disposition"] type] hasPrefix: @"attachment"]) + { + if ([[part body] isKindOfClass: [NSData class]] && ! [[[part contentType] type] isEqualToString: @"text"]) + { + // Ensure base64 encoding of non-text parts - text parts are encoded individually. + [part setHeader: @"base64" forKey: @"content-transfer-encoding"]; + [part setBody: [[part body] dataByEncodingBase64]]; + [part setHeader: [NSString stringWithFormat:@"%d", (int)[[part body] length]] + forKey: @"content-length"]; + } + + [attachments addObject: part]; + } + else if ([[[part contentType] type] isEqualToString: @"text"] && [[[part contentType] subType] isEqualToString: @"html"]) htmlPart = part; else if ([[[part contentType] type] isEqualToString: @"text"] && [[[part contentType] subType] isEqualToString: @"plain"]) textPart = part; - else - [attachments addObject: part]; } } }