From 2ee09159a2977ce9facc9013111eecc99d78eb62 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 20 Oct 2015 15:33:18 -0400 Subject: [PATCH] (feat) now possible to choose which folders to sync over EAS --- ActiveSync/SOGoActiveSyncDispatcher.m | 62 ++++++++++++++------------- NEWS | 1 + 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 5f41249b5..31b7cb300 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -707,22 +707,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - (void) processFolderSync: (id ) theDocumentElement inResponse: (WOResponse *) theResponse { - NSString *key, *cKey, *nkey, *name, *serverId, *parentId, *nameInCache, *personalFolderName, *syncKey, *folderType; + NSString *key, *cKey, *nkey, *name, *serverId, *parentId, *nameInCache, *personalFolderName, *syncKey, *folderType, *operation; + NSMutableDictionary *cachedGUIDs, *metadata; + NSMutableArray *folders, *processedFolders; NSDictionary *folderMetadata, *imapGUIDs; NSArray *allFoldersMetadata, *allKeys; - NSMutableDictionary *cachedGUIDs, *metadata; SOGoMailAccounts *accountsFolder; SOGoMailAccount *accountFolder; NSMutableString *s, *commands; SOGoUserFolder *userFolder; - NSMutableArray *folders, *processedFolders; SoSecurityManager *sm; SOGoCacheGCSObject *o; id currentFolder; NSData *d; int status, command_count, i, type, fi, count; - BOOL first_sync; sm = [SoSecurityManager sharedSecurityManager]; @@ -840,32 +839,33 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } else { - if ([cKey rangeOfString: @"vevent" options: NSCaseInsensitiveSearch].location != NSNotFound || - [cKey rangeOfString: @"vtodo" options: NSCaseInsensitiveSearch].location != NSNotFound) - folderType = @"Calendar"; - else - folderType = @"Contacts"; + if ([cKey rangeOfString: @"vevent" options: NSCaseInsensitiveSearch].location != NSNotFound || + [cKey rangeOfString: @"vtodo" options: NSCaseInsensitiveSearch].location != NSNotFound) + folderType = @"Calendar"; + else + folderType = @"Contacts"; - if ([ cKey rangeOfString: @"/"].location != NSNotFound) - currentFolder = [[[[context activeUser] homeFolderInContext: context] lookupName: folderType inContext: context acquire: NO] + if ([ cKey rangeOfString: @"/"].location != NSNotFound) + currentFolder = [[[[context activeUser] homeFolderInContext: context] lookupName: folderType inContext: context acquire: NO] lookupName: [cKey substringFromIndex: [cKey rangeOfString: @"/"].location+1] inContext: context acquire: NO]; - // remove the folder from device if it doesn't exists or it has not the proper permissions - if (!currentFolder || - [sm validatePermission: SoPerm_DeleteObjects - onObject: currentFolder - inContext: context] || - [sm validatePermission: SoPerm_AddDocumentsImagesAndFiles - onObject: currentFolder - inContext: context]) - { - [commands appendFormat: @"%@", [cKey stringByEscapingURL] ]; - command_count++; - [o destroy]; - } - } - } - } + // Remove the folder from device if it doesn't exist, we don't want to sync it, or it doesn't have the proper permissions + if (!currentFolder || + ![currentFolder synchronize] || + [sm validatePermission: SoPerm_DeleteObjects + onObject: currentFolder + inContext: context] || + [sm validatePermission: SoPerm_AddDocumentsImagesAndFiles + onObject: currentFolder + inContext: context]) + { + [commands appendFormat: @"%@", [cKey stringByEscapingURL] ]; + command_count++; + [o destroy]; + } + } + } + } // Handle addition and changes for (i = 0; i < [allFoldersMetadata count]; i++) @@ -965,11 +965,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. folders = [[[[[context activeUser] homeFolderInContext: context] lookupName: @"Calendar" inContext: context acquire: NO] subFolders] mutableCopy]; [folders addObjectsFromArray: [[[[context activeUser] homeFolderInContext: context] lookupName: @"Contacts" inContext: context acquire: NO] subFolders]]; - // Inside this loop we remove all the folder without write/delete permissions + // We remove all the folders that aren't GCS-ones, that we don't want to synchronize and + // the ones without write/delete permissions count = [folders count]-1; for (; count >= 0; count--) { - if ([sm validatePermission: SoPerm_DeleteObjects + if (![[folders objectAtIndex: count] isKindOfClass: [SOGoGCSFolder class]] || + ![[folders objectAtIndex: count] synchronize] || + [sm validatePermission: SoPerm_DeleteObjects onObject: [folders objectAtIndex: count] inContext: context] || [sm validatePermission: SoPerm_AddDocumentsImagesAndFiles @@ -981,7 +984,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } count = [folders count]-1; - NSString *operation; for (fi = 0; fi <= count ; fi++) { diff --git a/NEWS b/NEWS index 2ad60b0da..8a7a7aa20 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ New features - initial S/MIME support for EAS (#3327) + - now possible to choose which folders to sync over EAS Enhancements - we no longer always entirely rewrite messages for Outlook 2013 when using EAS