From eaf0a19002dafaa74e268f9a0f758e62dcac1e02 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 18 Oct 2016 19:41:47 -0400 Subject: [PATCH] (fix) improve handling of email folders without a parent --- ActiveSync/SOGoActiveSyncDispatcher.m | 56 +++++++++++++++++++++++++-- NEWS | 1 + 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 07213f209..f6e1014f0 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -738,6 +738,55 @@ void handle_eas_terminate(int signum) [theResponse setContent: d]; } +// +// +// +- (void) _fixMissingParent: (NSArray *) theFolders + into: (NSMutableArray *) theTarget +{ + NSString *folderPath; + NSMutableDictionary *folder; + int i, ii, iii; + BOOL found; + + for (i = 0; i < [theFolders count]; i++) + { + folder = [[theFolders objectAtIndex: i] mutableCopy]; + + if (![folder objectForKey: @"parent"] && [[[folder objectForKey: @"path"] pathComponents] count] > 2) + { + found = NO; + folderPath = [folder objectForKey: @"path"]; + + for (ii = 0; ii < [[folderPath pathComponents] count] && !found; ii++) + { + folderPath = [folderPath stringByDeletingLastPathComponent]; + + for (iii = 0; iii < [theFolders count]; iii++) + { + if ([[[theFolders objectAtIndex: iii] objectForKey: @"path"] isEqualToString: folderPath]) + { + [folder setObject: [[[folder objectForKey: @"displayName"] substringFromIndex: + [[[theFolders objectAtIndex: iii] objectForKey: @"displayName"] length]+1] + stringByReplacingString:@"/" withString:@"."] forKey: @"displayName"]; + + [folder setObject: folderPath forKey: @"parent"]; + + found = YES; + + break; + } + } + } + + if (!found ) + [folder setObject: [[[folder objectForKey: @"displayName"] substringFromIndex: 1] + stringByReplacingString:@"/" withString:@"."] forKey: @"displayName"]; + } + + [theTarget addObject: folder]; + } +} // // @@ -751,9 +800,9 @@ void handle_eas_terminate(int signum) { NSString *key, *cKey, *nkey, *name, *serverId, *parentId, *nameInCache, *personalFolderName, *syncKey, *folderType, *operation; NSMutableDictionary *cachedGUIDs, *metadata; - NSMutableArray *folders, *processedFolders; + NSMutableArray *folders, *processedFolders, *allFoldersMetadata; NSDictionary *folderMetadata, *imapGUIDs; - NSArray *allFoldersMetadata, *allKeys; + NSArray *allKeys; SOGoMailAccounts *accountsFolder; SOGoMailAccount *accountFolder; NSMutableString *s, *commands; @@ -808,7 +857,8 @@ void handle_eas_terminate(int signum) [self _ensureFolder: (SOGoMailFolder *)[accountFolder trashFolderInContext: context]]; } - allFoldersMetadata = [accountFolder allFoldersMetadata]; + allFoldersMetadata = [NSMutableArray array]; + [self _fixMissingParent: [accountFolder allFoldersMetadata] into: allFoldersMetadata]; // Get GUIDs of folder (IMAP) // e.g. {folderINBOX = folder6b93c528176f1151c7260000aef6df92} diff --git a/NEWS b/NEWS index 8cc661a5d..707c9d30b 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Enhancements Bug fixes - [eas] make sure we don't sleep for too long when EAS processes need interruption - [eas] fixed recurring events with timezones for EAS (#3822) + - [eas] improve handling of email folders without a parent - [core] only consider SMTP addresses for AD's proxyAddresses (#3842) 2.3.16 (2016-09-28)