diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index 0faa6a20c..705248cb2 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -1388,7 +1388,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. changeDetected: (BOOL *) changeDetected maxSyncResponseSize: (int) theMaxSyncResponseSize { - NSString *collectionId, *realCollectionId, *syncKey, *davCollectionTag, *bodyPreferenceType, *mimeSupport, *lastServerKey, *syncKeyInCache, *folderKey; + NSString *collectionId, *realCollectionId, *syncKey, *davCollectionTag, *bodyPreferenceType, *mimeSupport, *mimeTruncation, *lastServerKey, *syncKeyInCache, *folderKey; NSMutableDictionary *folderMetadata, *folderOptions; NSMutableArray *supportedElements, *supportedElementNames; NSMutableString *changeBuffer, *commandsBuffer; @@ -1500,48 +1500,60 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. bodyPreferenceType = [[(id)[[(id)[theDocumentElement getElementsByTagName: @"BodyPreference"] lastObject] getElementsByTagName: @"Type"] lastObject] textValue]; if (!bodyPreferenceType) - { - bodyPreferenceType = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"BodyPreferenceType"]; + { + bodyPreferenceType = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"BodyPreferenceType"]; - // By default, send MIME mails. See #3146 for details. - if (!bodyPreferenceType) - bodyPreferenceType = @"4"; + // By default, send MIME mails. See #3146 for details. + if (!bodyPreferenceType) + bodyPreferenceType = @"4"; - mimeSupport = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMESupport"]; + mimeSupport = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMESupport"]; + mimeTruncation = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMETruncation"]; - if (!mimeSupport) - mimeSupport = @"1"; - } + if (!mimeSupport) + mimeSupport = @"1"; + + if (!mimeTruncation) + mimeTruncation = @"8"; + } else - { - mimeSupport = [[(id)[theDocumentElement getElementsByTagName: @"MIMESupport"] lastObject] textValue]; + { + mimeSupport = [[(id)[theDocumentElement getElementsByTagName: @"MIMESupport"] lastObject] textValue]; + mimeTruncation = [[(id)[theDocumentElement getElementsByTagName: @"MIMETruncation"] lastObject] textValue]; - if (!mimeSupport) + if (!mimeSupport) mimeSupport = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMESupport"]; - if (!mimeSupport) + if (!mimeSupport) mimeSupport = @"0"; - if ([mimeSupport isEqualToString: @"1"] && [bodyPreferenceType isEqualToString: @"4"]) + if (!mimeTruncation) + mimeTruncation = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMETruncation"]; + + if (!mimeTruncation) + mimeTruncation = @"8"; + + if ([mimeSupport isEqualToString: @"1"] && [bodyPreferenceType isEqualToString: @"4"]) bodyPreferenceType = @"2"; - else if ([mimeSupport isEqualToString: @"2"] && [bodyPreferenceType isEqualToString: @"4"]) + else if ([mimeSupport isEqualToString: @"2"] && [bodyPreferenceType isEqualToString: @"4"]) bodyPreferenceType = @"4"; - else if ([mimeSupport isEqualToString: @"0"] && [bodyPreferenceType isEqualToString: @"4"]) + else if ([mimeSupport isEqualToString: @"0"] && [bodyPreferenceType isEqualToString: @"4"]) bodyPreferenceType = @"2"; - - // Avoid writing to cache if there is nothing to change. - if (![[[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"BodyPreferenceType"] isEqualToString: bodyPreferenceType] || - ![[[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMESupport"] isEqualToString: mimeSupport]) - { - folderOptions = [[NSDictionary alloc] initWithObjectsAndKeys: mimeSupport, @"MIMESupport", bodyPreferenceType, @"BodyPreferenceType", nil]; - [folderMetadata setObject: folderOptions forKey: @"FolderOptions"]; - [self _setFolderMetadata: folderMetadata forKey: folderKey]; - } - } + // Avoid writing to cache if there is nothing to change. + if (![[[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"BodyPreferenceType"] isEqualToString: bodyPreferenceType] || + ![[[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMESupport"] isEqualToString: mimeSupport] || + ![[[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMETruncation"] isEqualToString: mimeTruncation]) + { + folderOptions = [[NSDictionary alloc] initWithObjectsAndKeys: mimeSupport, @"MIMESupport", mimeTruncation, @"MIMETruncation", bodyPreferenceType, @"BodyPreferenceType", nil]; + [folderMetadata setObject: folderOptions forKey: @"FolderOptions"]; + [self _setFolderMetadata: folderMetadata forKey: folderKey]; + } + } [context setObject: bodyPreferenceType forKey: @"BodyPreferenceType"]; [context setObject: mimeSupport forKey: @"MIMESupport"]; + [context setObject: mimeTruncation forKey: @"MIMETruncation"]; [context setObject: [folderMetadata objectForKey: @"SupportedElements"] forKey: @"SupportedElements"]; // diff --git a/ActiveSync/SOGoMailObject+ActiveSync.m b/ActiveSync/SOGoMailObject+ActiveSync.m index 78391f2b5..b23416604 100644 --- a/ActiveSync/SOGoMailObject+ActiveSync.m +++ b/ActiveSync/SOGoMailObject+ActiveSync.m @@ -695,13 +695,14 @@ struct GlobalObjectId { NSMutableString *s; id value; - int preferredBodyType, mimeSupport, nativeBodyType; + int preferredBodyType, mimeSupport, mimeTruncation, nativeBodyType; uint32_t v; subtype = [[[self bodyStructure] valueForKey: @"subtype"] lowercaseString]; preferredBodyType = [[context objectForKey: @"BodyPreferenceType"] intValue]; mimeSupport = [[context objectForKey: @"MIMESupport"] intValue]; + mimeTruncation = [[context objectForKey: @"MIMETruncation"] intValue]; s = [NSMutableString string]; @@ -1007,9 +1008,64 @@ struct GlobalObjectId { AUTORELEASE(content); content = [content activeSyncRepresentationInContext: context]; - truncated = 0; - len = [content length]; + truncated = 1; + + // We handle MIMETruncation + switch (mimeTruncation) + { + case 0: + { + content = @""; + len = 0; + } + break; + case 1: + { + content = [content substringToIndex: 4096]; + len = 4096; + } + break; + case 2: + { + content = [content substringToIndex: 5120]; + len = 5120; + } + break; + case 3: + { + content = [content substringToIndex: 7168]; + len = 7168; + } + break; + case 4: + { + content = [content substringToIndex: 10240]; + len = 10240; + } + break; + case 5: + { + content = [content substringToIndex: 20480]; + len = 20480; + } + break; + case 6: + { + content = [content substringToIndex: 51200]; + len = 51200; + } + break; + case 7: + { + content = [content substringToIndex: 102400]; + len = 102400; + } + break; + case 8: + default: + truncated = 0; + } if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) { @@ -1017,7 +1073,7 @@ struct GlobalObjectId { [s appendFormat: @"%d", truncated]; } else - { + { [s appendString: @""]; // Set the correct type if client requested text/html but we got text/plain. @@ -1031,16 +1087,12 @@ struct GlobalObjectId { [s appendFormat: @"%d", truncated]; [s appendFormat: @""]; - - if (!truncated) - { - [s appendFormat: @"%@", content]; - [s appendFormat: @"%d", len]; - } + [s appendFormat: @"%@", content]; + [s appendFormat: @"%d", len]; [s appendString: @""]; } } - + // Attachments -namespace 16 attachmentKeys = [self fetchFileAttachmentKeys];