From c9e9bb19d8cef996f4c3fdb65e15268c2ed4e91d Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 11 Nov 2016 08:33:50 -0500 Subject: [PATCH] (fix) fix EAS download of attachments on iOS 10 --- ActiveSync/SOGoActiveSyncDispatcher.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 56f6b403f..1f995cbb9 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -1509,6 +1509,7 @@ void handle_eas_terminate(int signum) if ([[theResponse headerForKey: @"Content-Type"] isEqualToString:@"application/vnd.ms-sync.multipart"]) { NSData *d; + d = [currentBodyPart fetchBLOBWithPeek: YES]; [s appendFormat: @"%d", i+1]; @@ -1518,9 +1519,15 @@ void handle_eas_terminate(int signum) else { NSString *a; + a = [[currentBodyPart fetchBLOBWithPeek: YES] activeSyncRepresentationInContext: context]; - [s appendFormat: @"0-%d", [a length]-1]; + // Don't send Range when not included in the request. Sending it will cause issue on iOS 10 + // when downloading attachments. iOS 10 will first report an error upon the first download + // and then, it'll work. This makes it work the first time the attachment is downlaoded. + if ([[[(id)[aFetch getElementsByTagName: @"Range"] lastObject] textValue] length]) + [s appendFormat: @"0-%d", [a length]-1]; + [s appendFormat: @"%@", a]; } }