diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index ff9321f92..fb9b535ef 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -1127,6 +1127,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. id currentCollection; NSMutableString *s; NSData *d; + NSArray *allCollections; + int j; SOGoMicrosoftActiveSyncFolderType folderType; int status, count; @@ -1135,66 +1137,83 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. status = 1; count = 0; - collectionId = [[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue]; - realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType]; - - if (folderType == ActiveSyncMailFolder) - nameInCache = [NSString stringWithFormat: @"folder%@", realCollectionId]; - else - nameInCache = collectionId; - - realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType]; - - currentCollection = [self collectionFromId: realCollectionId type: folderType]; - - // - // For IMAP, we simply build a request like this: - // - // . UID SORT (SUBJECT) UTF-8 SINCE 1-Jan-2014 NOT DELETED - // * SORT 124576 124577 124579 124578 - // . OK Completed (4 msgs in 0.000 secs) - // - if (folderType == ActiveSyncMailFolder) - { - EOQualifier *notDeletedQualifier, *sinceDateQualifier; - EOAndQualifier *qualifier; - NSCalendarDate *filter; - NSArray *uids; - - filter = [NSCalendarDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]]; - - notDeletedQualifier = [EOQualifier qualifierWithQualifierFormat: - @"(not (flags = %@))", - @"deleted"]; - sinceDateQualifier = [EOQualifier qualifierWithQualifierFormat: - @"(DATE >= %@)", filter]; - - qualifier = [[EOAndQualifier alloc] initWithQualifiers: notDeletedQualifier, sinceDateQualifier, - nil]; - AUTORELEASE(qualifier); - - uids = [currentCollection fetchUIDsMatchingQualifier: qualifier - sortOrdering: @"REVERSE ARRIVAL" - threaded: NO]; - count = [uids count]; - - // Add the number of UIDs expected to "soft delete" - count += [self _softDeleteCountWithFilter: filter collectionId: nameInCache]; - - } - else - { - count = [[currentCollection toOneRelationshipKeys] count]; - } - [s appendString: @""]; [s appendString: @""]; - [s appendFormat: @"%d", status]; + [s appendString: @""]; + + allCollections = (id)[theDocumentElement getElementsByTagName: @"Collection"]; + + for (j = 0; j < [allCollections count]; j++) + { + collectionId = [[(id)[[allCollections objectAtIndex: j] getElementsByTagName: @"CollectionId"] lastObject] textValue]; + realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType]; + + if (folderType == ActiveSyncMailFolder) + nameInCache = [NSString stringWithFormat: @"folder%@", realCollectionId]; + else + nameInCache = collectionId; + + realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType]; + + currentCollection = [self collectionFromId: realCollectionId type: folderType]; - [s appendFormat: @"%@", collectionId]; - [s appendFormat: @"%d", count]; + // + // For IMAP, we simply build a request like this: + // + // . UID SORT (SUBJECT) UTF-8 SINCE 1-Jan-2014 NOT DELETED + // * SORT 124576 124577 124579 124578 + // . OK Completed (4 msgs in 0.000 secs) + // + if (folderType == ActiveSyncMailFolder) + { + EOQualifier *notDeletedQualifier, *sinceDateQualifier; + EOAndQualifier *qualifier; + NSCalendarDate *filter; + NSArray *uids; + + filter = [NSCalendarDate dateFromFilterType: [[(id)[[allCollections objectAtIndex: j] getElementsByTagName: @"FilterType"] lastObject] textValue]]; + + notDeletedQualifier = [EOQualifier qualifierWithQualifierFormat: + @"(not (flags = %@))", + @"deleted"]; + sinceDateQualifier = [EOQualifier qualifierWithQualifierFormat: + @"(DATE >= %@)", filter]; + + qualifier = [[EOAndQualifier alloc] initWithQualifiers: notDeletedQualifier, sinceDateQualifier, + nil]; + AUTORELEASE(qualifier); + + uids = [currentCollection fetchUIDsMatchingQualifier: qualifier + sortOrdering: @"REVERSE ARRIVAL" + threaded: NO]; + count = [uids count]; + + // Add the number of UIDs expected to "soft delete" + count += [self _softDeleteCountWithFilter: filter collectionId: nameInCache]; + } + else + { + count = [[currentCollection toOneRelationshipKeys] count]; + } + + + [s appendString: @""]; + [s appendFormat: @"%d", status]; + + if (folderType == ActiveSyncMailFolder) + [s appendString: @"Email"]; + else if (folderType == ActiveSyncContactFolder) + [s appendString: @"Contacts"]; + else if (folderType == ActiveSyncEventFolder) + [s appendString: @"Calendar"]; + else if (folderType == ActiveSyncTaskFolder) + [s appendString: @"Tasks"]; + + [s appendFormat: @"%@",collectionId]; + [s appendFormat: @"%d", count]; + } - [s appendString: @""]; + [s appendString: @""]; d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml]; @@ -2543,7 +2562,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // If the MS-ASProtocolVersion header is set to "12.1", the body of the SendMail request is // is a "message/rfc822" payload - otherwise, it's a WBXML blob. // - if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame && + if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame || [[theRequest headerForKey: @"content-type"] caseInsensitiveCompare: @"message/rfc822"] == NSOrderedSame) { NSString *s, *xml; @@ -2562,6 +2581,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } xml = [NSString stringWithFormat: @"%@", [s stringByEncodingBase64]]; + d = [xml dataUsingEncoding: NSASCIIStringEncoding]; } diff --git a/NEWS b/NEWS index 4102452cb..54e2f7639 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Bug fixes - fixed login issue after password change (#2601) - fixed potential encoding issue using EAS and 8-bit mails (#3116) + - multiple collections support for GetItemEstimate using EAS 2.2.16 (2015-02-12) -------------------