From e0d49d24073ec57af26627f860df8c2dc3500468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Thu, 29 Oct 2015 23:04:42 +0100 Subject: [PATCH 1/2] oc-mail: Check the number of uids fetched on synchroniseCache Equals to the number of uids requested. There are corner-cases when this is not happening, we don't know yet why this is happening but IMAP server log should do the trick. This avoids to launch a NSException trying to access an element outside the array bounds. --- OpenChange/MAPIStoreMailFolder.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 7c8e4f8ac..7492f27bd 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -599,7 +599,7 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data) uint64_t lastModseqNbr; EOQualifier *searchQualifier; NSArray *uids, *changeNumbers; - NSUInteger count, max; + NSUInteger count, max, nFetched; NSArray *fetchResults; NSDictionary *result; NSData *changeKey; @@ -678,6 +678,13 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data) = [fetchResults sortedArrayUsingFunction: _compareFetchResultsByMODSEQ context: NULL]; + nFetched = [fetchResults count]; + if (nFetched != max) { + [self errorWithFormat: @"Error fetching UIDs. Asked: %d Received: %d." + @"Check the IMAP conversation for details", max, nFetched]; + return NO; + } + for (count = 0; count < max; count++) { result = [fetchResults objectAtIndex: count]; From 77bba8e5ea6253b7473f15e3fac684e0d1901aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Thu, 29 Oct 2015 23:10:22 +0100 Subject: [PATCH 2/2] Use application context when initialising quick tables ACLs As the stored context from initialisation may have changed by `setContext` by other operations when acting as a OpenChange library. This would make having a login set to nil and forcing a NSException when it attempts to set a nil key at [SOGoAppointmentFolder:roleForComponentsWithAccessClass:forUser] inside [SOGoAppointmentFolder:initializeQuickTablesAclsInContext]. --- SoObjects/Appointments/SOGoAppointmentFolder.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index cfda94c82..cff8d8c03 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -604,8 +604,16 @@ static Class iCalEventK = nil; NSNumber *classNumber; unsigned int grantedCount; iCalAccessClass currentClass; + WOContext *localContext; - [self initializeQuickTablesAclsInContext: context]; + /* FIXME: The stored context from initialisation may have changed + by setContext by other operations in OpenChange library, + so we keep tighly to use the current session one. Without + this, the login is set to nil and a NSException is raised + at [SOGoAppointmentFolder:roleForComponentsWithAccessClass:forUser] + inside [SOGoAppointmentFolder:initializeQuickTablesAclsInContext]. */ + localContext = [[WOApplication application] context]; + [self initializeQuickTablesAclsInContext: localContext]; grantedClasses = [NSMutableArray arrayWithCapacity: 3]; deniedClasses = [NSMutableArray arrayWithCapacity: 3]; for (currentClass = 0;