diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index a2bcc852e..0a3846de3 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -2012,9 +2012,8 @@ FIXME { bodyPreferenceType = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"BodyPreferenceType"]; - // By default, send MIME mails. See #3146 for details. if (!bodyPreferenceType) - bodyPreferenceType = @"4"; + bodyPreferenceType = @"1"; mimeSupport = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMESupport"]; mimeTruncation = [[folderMetadata objectForKey: @"FolderOptions"] objectForKey: @"MIMETruncation"]; diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 8b680c08d..a6a8e260f 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -707,11 +707,13 @@ void handle_eas_terminate(int signum) inContext: context acquire: NO]; - // update the cache anyway regardless of any error; if the rename fails next folderSync will to the cleanup - [folderToUpdate renameTo: [NSString stringWithFormat: @"%@", [displayName stringByEncodingImap4FolderName]]]; - if (folderType == ActiveSyncEventFolder) - nameInCache = [NSString stringWithFormat: @"vevent/%@", serverId]; + { + nameInCache = [NSString stringWithFormat: @"vevent/%@", serverId]; + // We do the rename only for EventFolder. TaskFolder and EventFolder have the same target on server. + // In case of an error we expect the foldersync to do the cleanup. + [folderToUpdate renameTo: [NSString stringWithFormat: @"%@", [displayName stringByEncodingImap4FolderName]]]; + } else nameInCache = [NSString stringWithFormat: @"vtodo/%@",serverId]; @@ -1626,11 +1628,11 @@ void handle_eas_terminate(int signum) // ServerId might have been set if LongId was defined in the initial request. If not, it is // a normal ItemOperations (Fetch) to get a complete email if (!serverId) - serverId = [[(id)[theDocumentElement getElementsByTagName: @"ServerId"] lastObject] textValue]; + serverId = [[(id)[aFetch getElementsByTagName: @"ServerId"] lastObject] textValue]; - bodyPreferenceType = [[(id)[[(id)[theDocumentElement getElementsByTagName: @"BodyPreference"] lastObject] getElementsByTagName: @"Type"] lastObject] textValue]; + bodyPreferenceType = [[(id)[[(id)[aFetch getElementsByTagName: @"BodyPreference"] lastObject] getElementsByTagName: @"Type"] lastObject] textValue]; [context setObject: bodyPreferenceType forKey: @"BodyPreferenceType"]; - mimeSupport = [[(id)[theDocumentElement getElementsByTagName: @"MIMESupport"] lastObject] textValue]; + mimeSupport = [[(id)[aFetch getElementsByTagName: @"MIMESupport"] lastObject] textValue]; [context setObject: mimeSupport forKey: @"MIMESupport"]; // https://msdn.microsoft.com/en-us/library/gg675490%28v=exchg.80%29.aspx @@ -1644,10 +1646,10 @@ void handle_eas_terminate(int signum) [s appendString: @""]; [s appendString: @"1"]; - if ([[[(id)[theDocumentElement getElementsByTagName: @"LongId"] lastObject] textValue] length]) + if ([[[(id)[aFetch getElementsByTagName: @"LongId"] lastObject] textValue] length]) { [s appendString: @"Email"]; - [s appendFormat: @"%@", [[(id)[theDocumentElement getElementsByTagName: @"LongId"] lastObject] textValue]]; + [s appendFormat: @"%@", [[(id)[aFetch getElementsByTagName: @"LongId"] lastObject] textValue]]; } else { @@ -1671,8 +1673,75 @@ void handle_eas_terminate(int signum) } else { - [theResponse setStatus: 500]; - return; + NSMutableDictionary *uidCache, *folderMetadata; + NSString *easId; + id sogoObject, currentCollection, componentObject; + + // ServerId might have been set if LongId was defined in the initial request. If not, it is + // a normal ItemOperations (Fetch). + if (!serverId) + serverId = [[(id)[aFetch getElementsByTagName: @"ServerId"] lastObject] textValue]; + + currentCollection = [self collectionFromId: realCollectionId type: folderType]; + folderMetadata = [self _folderMetadataForKey: [self _getNameInCache: realCollectionId withType: folderType]]; + + uidCache = [folderMetadata objectForKey: @"UidCache"]; + if (uidCache) + { + easId = [[uidCache allKeysForObject: serverId] objectAtIndex: 0]; + + if (easId) + { + if (debugOn) + [self logWithFormat: @"EAS - Found easId: %@ for serverId: %@", easId, serverId]; + } + else + { + if (debugOn) + [self logWithFormat: @"EAS - Use original serverId: %@", serverId]; + + easId = serverId; + } + } + else + easId = serverId; + + + sogoObject = [currentCollection lookupName: [easId sanitizedServerIdWithType: folderType] + inContext: context + acquire: NO]; + + if (folderType == ActiveSyncContactFolder) + componentObject = [sogoObject vCard]; + else + componentObject = [sogoObject component: NO secure: YES]; + + [s appendString: @""]; + [s appendString: @"1"]; + + if ([[[(id)[aFetch getElementsByTagName: @"LongId"] lastObject] textValue] length]) + { + if (folderType == ActiveSyncContactFolder) + [s appendString: @"Contacts"]; + else if (folderType == ActiveSyncEventFolder) + [s appendString: @"Calendar"]; + else if (folderType == ActiveSyncTaskFolder) + [s appendString: @"Task"]; + + [s appendFormat: @"%@", [[(id)[aFetch getElementsByTagName: @"LongId"] lastObject] textValue]]; + } + else + { + [s appendFormat: @"%@", collectionId]; + [s appendFormat: @"%@", serverId]; + } + + [s appendString: @""]; + + [s appendString: [componentObject activeSyncRepresentationInContext: context]]; + + [s appendString: @""]; + [s appendString: @""]; } } @@ -2592,7 +2661,7 @@ void handle_eas_terminate(int signum) [s appendString: @""]; [s appendString: @""]; [s appendString: @""]; - [s appendString: @"1"]; + [s appendString: @"1MS-EAS-Provisioning-WBXML2"]; [s appendString: @""]; d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml]; diff --git a/NEWS b/NEWS index 0d18f87f5..d054ddf4f 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ Enhancements Bug fixes - [core] use the supplied Sieve creds to fetch the IMAP4 separator (#4846) - [core] fixed Apple Calendar creation (#4813) + - [eas] fixed EAS provisioning support for Outlook/iOS (#4853) 4.1.0 (2019-10-24)