Skip to content

Commit

Permalink
Fix for bug #2688
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed May 27, 2014
1 parent 6bab4c9 commit d35c52b
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 74 deletions.
33 changes: 21 additions & 12 deletions ActiveSync/SOGoActiveSyncDispatcher+Sync.m
Expand Up @@ -123,7 +123,9 @@ - (void) _setFolderMetadata: (NSDictionary *) theFolderMetadata
[o setTableUrl: [self folderTableURL]];
[o reloadIfNeeded];

[[o properties] removeAllObjects];
[[o properties] removeObjectForKey: @"SyncCache"];
[[o properties] removeObjectForKey: @"DateCache"];

[[o properties] addEntriesFromDictionary: theFolderMetadata];
[o save];
}
Expand Down Expand Up @@ -627,21 +629,23 @@ - (void) processSyncGetChanges: (id <DOMElement>) theDocumentElement
sequence: [[[allMessages objectAtIndex: i] allValues] lastObject]]];
}

// If it's a new Sync operation, ignore anything we might have
// in our preferences.
// If it's a new Sync operation, DateCache and SyncCache need to be deleted
// but GUID stored by folderSync shouldn't be touched
folderMetadata = [self _folderMetadataForKey: [theCollection nameInContainer]];
if ([theSyncKey isEqualToString: @"-1"])
{
folderMetadata = [NSMutableDictionary dictionary];

[folderMetadata setObject: [NSMutableDictionary dictionary] forKey: @"SyncCache"];
[folderMetadata setObject: [NSMutableDictionary dictionary] forKey: @"DateCache"];

// TODO - Generate GUID
//[folderMetadata setObject: @"FOO-BAR-BAZ" forKey: @"GUID"];
}
else
folderMetadata = [self _folderMetadataForKey: [theCollection nameInContainer]];

// Check whether GUID in cache is equal to the GUID from imap - this is to avoid cache corruptions if a folder has been renamed and a new folder
// with the same name has been created but folderSync has not yet updated the cache
if (!([[theCollection nameInContainer] isEqualToString:
[NSString stringWithFormat: @"folder%@", [self globallyUniqueIDToIMAPFolderName: [folderMetadata objectForKey: @"GUID"] type: theFolderType]]]))
{
NSLog(@"GUID mismatch don't sync now!");
return;
}

syncCache = [folderMetadata objectForKey: @"SyncCache"];
dateCache = [folderMetadata objectForKey: @"DateCache"];

Expand Down Expand Up @@ -711,6 +715,7 @@ - (void) processSyncGetChanges: (id <DOMElement>) theDocumentElement
[s appendString: @"</Delete>"];

[syncCache removeObjectForKey: [aCacheObject uid]];
[dateCache removeObjectForKey: [aCacheObject uid]];
}
else
{
Expand Down Expand Up @@ -773,13 +778,15 @@ - (void) processSyncGetChanges: (id <DOMElement>) theDocumentElement
//NSLog(@"skipping old deleted UID: %@", [aCacheObject uid]);
}
}

}

if (more_available)
[folderMetadata setObject: [NSNumber numberWithBool: YES] forKey: @"MoreAvailable"];
else
[folderMetadata removeObjectForKey: @"MoreAvailable"];


[self _setFolderMetadata: folderMetadata
forKey: [theCollection nameInContainer]];
} // default:
Expand Down Expand Up @@ -890,6 +897,7 @@ - (void) processSyncCollection: (id <DOMElement>) theDocumentElement

collectionId = [[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue];
realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType];
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
collection = [self collectionFromId: realCollectionId type: folderType];

syncKey = davCollectionTag = [[(id)[theDocumentElement getElementsByTagName: @"SyncKey"] lastObject] textValue];
Expand Down Expand Up @@ -988,6 +996,7 @@ - (void) processSyncCollection: (id <DOMElement>) theDocumentElement
davCollectionTag = [collection davCollectionTag];
}


// Generate the response buffer
[theBuffer appendString: @"<Collection>"];

Expand Down
3 changes: 3 additions & 0 deletions ActiveSync/SOGoActiveSyncDispatcher.h
Expand Up @@ -43,6 +43,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- (id) collectionFromId: (NSString *) theCollectionId
type: (SOGoMicrosoftActiveSyncFolderType) theFolderType;

- (id) globallyUniqueIDToIMAPFolderName: (NSString *) theIdToTranslate
type: (SOGoMicrosoftActiveSyncFolderType) theFolderType;

- (NSException *) dispatchRequest: (id) theRequest
inResponse: (id) theResponse
context: (id) theContext;
Expand Down

0 comments on commit d35c52b

Please sign in to comment.