diff --git a/ChangeLog b/ChangeLog index 58de6b6a6..c51b99e2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2012-03-19 Wolfgang Sourdeau + * Main/SOGo+DAV.m (_fillCollections:where:matches:inContext:): + added bogosupport for + "{http://calendarserver.org/ns/}email-address-set". + (_principalCollectionsMatching:inContext:): relationship between + search criteria is now and "OR" rathern than an "AND". + * SoObjects/Appointments/SOGoUserFolder+Appointments.m (-davCalendarUserType, -davEmailAddressSet): new DAV accessors. diff --git a/Main/SOGo+DAV.m b/Main/SOGo+DAV.m index 66f7f0461..67f0b3a6a 100644 --- a/Main/SOGo+DAV.m +++ b/Main/SOGo+DAV.m @@ -40,6 +40,7 @@ #import #import #import +#import #import #import #import @@ -362,46 +363,53 @@ [collections addObject: collection]; } -- (NSMutableArray *) _firstPrincipalCollectionsWhere: (NSString *) key - matches: (NSString *) value - inContext: (WOContext *) localContext +- (void) _fillCollections: (NSMutableArray *) collections + withEmailAddressSetMatching: (NSString *) value + inContext: (WOContext *) localContext { - NSMutableArray *collections; + id authenticationSource; + SOGoUser *activeUser; + NSArray *records; + NSUInteger count, max; + NSString *uid; + SOGoUserFolder *collection; - collections = [NSMutableArray array]; + activeUser = [localContext activeUser]; + if ([activeUser respondsToSelector: @selector (authenticationSource)]) + { + authenticationSource = [[localContext activeUser] authenticationSource]; + records = [authenticationSource + fetchContactsMatching: value + inDomain: [activeUser domain]]; + max = [records count]; + for (count = 0; count < max; count++) + { + uid = [[records objectAtIndex: count] objectForKey: @"c_uid"]; + if ([uid length] > 0) + { + collection = [[SOGoUser userWithLogin: uid] + homeFolderInContext: localContext]; + [collections addObject: collection]; + } + } + } +} + +- (void) _fillCollections: (NSMutableArray *) collections + where: (NSString *) key + matches: (NSString *) value + inContext: (WOContext *) localContext +{ if ([key isEqualToString: @"{urn:ietf:params:xml:ns:caldav}calendar-home-set"]) [self _fillCollections: collections withCalendarHomeSetMatching: value inContext: localContext]; + else if ([key isEqualToString: @"{http://calendarserver.org/ns/}email-address-set"]) + [self _fillCollections: collections withEmailAddressSetMatching: value + inContext: localContext]; else - [self errorWithFormat: @"principal-property-search: unhandled key '%@'", + [self warnWithFormat: @"principal-property-search: unhandled key '%@'", key]; - - return collections; -} - -- (void) _principalCollections: (NSMutableArray **) baseCollections - where: (NSString *) key - matches: (NSString *) value - inContext: (WOContext *) localContext -{ - SOGoUserFolder *currentCollection; - unsigned int count, max; - - if (!*baseCollections) - *baseCollections = [self _firstPrincipalCollectionsWhere: key - matches: value - inContext: localContext]; - else - { - max = [*baseCollections count]; - for (count = max; count > 0; count--) - { - currentCollection = [*baseCollections objectAtIndex: count - 1]; - if (![currentCollection collectionDavKey: key matches: value]) - [*baseCollections removeObjectAtIndex: count - 1]; - } - } } - (NSArray *) _principalCollectionsMatching: (NSDictionary *) matches @@ -411,14 +419,14 @@ NSEnumerator *allKeys; NSString *currentKey; - collections = nil; + collections = [NSMutableArray array]; allKeys = [[matches allKeys] objectEnumerator]; while ((currentKey = [allKeys nextObject])) - [self _principalCollections: &collections - where: currentKey - matches: [matches objectForKey: currentKey] - inContext: localContext]; + [self _fillCollections: collections + where: currentKey + matches: [matches objectForKey: currentKey] + inContext: localContext]; return collections; } @@ -453,13 +461,14 @@ SEL methodSel; NSString *currentProperty; id currentValue; - NSMutableArray *response, *props; + NSMutableArray *response, *props, *propstat; NSDictionary *keyTuple; response = [NSMutableArray array]; [response addObject: davElementWithContent (@"href", XMLNS_WEBDAV, [collection davURLAsString])]; props = [NSMutableArray array]; + max = [properties count]; for (count = 0; count < max; count++) { @@ -483,10 +492,13 @@ currentValue)]; } } - [response addObject: davElementWithContent (@"propstat", XMLNS_WEBDAV, - davElementWithContent - (@"prop", XMLNS_WEBDAV, - props))]; + + propstat = [NSMutableArray array]; + [propstat addObject: davElementWithContent (@"status", XMLNS_WEBDAV, + @"HTTP/1.1 200 OK")]; + [propstat addObject: davElementWithContent (@"prop", XMLNS_WEBDAV, + props)]; + [response addObject: davElementWithContent (@"propstat", XMLNS_WEBDAV, propstat)]; [responses addObject: davElementWithContent (@"response", XMLNS_WEBDAV, response)]; } @@ -503,8 +515,8 @@ responses = [NSMutableArray arrayWithCapacity: max]; for (count = 0; count < max; count++) [self _appendProperties: properties - ofCollection: [collections objectAtIndex: count] - toResponses: responses]; + ofCollection: [collections objectAtIndex: count] + toResponses: responses]; mStatus = davElementWithContent (@"multistatus", XMLNS_WEBDAV, responses); [response appendContentString: [mStatus asWebDavStringWithNamespaces: nil]]; }