diff --git a/ChangeLog b/ChangeLog index f119ae109..24df591e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2011-02-11 Wolfgang Sourdeau + * OpenChange/MAPIStoreGCSMessageTable.m + (-evaluatePropertyRestriction:intoQualifier:) + took version of method from MAPIStoreTable and modified it to + handle all string comparisons with the "UPPER" operator. + (-_fixedDatePropertyRestriction:): renamed version of + evaluateDatePropertyRestriction:intoQualifier: which now returns a + new restriction instead of repassing it to evaluatePropert... + * OpenChange/NSAutoreleasePool+MAPIStore.m: new utility module that enables the reparenting of a talloc pointer to the current NSAutoreleasePool. diff --git a/OpenChange/MAPIStoreGCSMessageTable.m b/OpenChange/MAPIStoreGCSMessageTable.m index 5f0234bf9..cb86f387a 100644 --- a/OpenChange/MAPIStoreGCSMessageTable.m +++ b/OpenChange/MAPIStoreGCSMessageTable.m @@ -22,6 +22,7 @@ #import #import +#import #import #import @@ -35,6 +36,7 @@ #import #import "MAPIStoreTypes.h" +#import "NSAutoreleasePool+MAPIStore.h" #import "MAPIStoreGCSMessageTable.h" @@ -119,34 +121,76 @@ return [self _childKeysUsingRestrictions: YES]; } -- (MAPIRestrictionState) evaluateDatePropertyRestriction: (struct mapi_SPropertyRestriction *) res - intoQualifier: (EOQualifier **) qualifier +- (struct mapi_SPropertyRestriction *) _fixedDatePropertyRestriction: (struct mapi_SPropertyRestriction *) res { - struct mapi_SPropertyRestriction translatedRes; + struct mapi_SPropertyRestriction *translatedRes; NSCalendarDate *dateValue; int32_t longDate; - translatedRes.ulPropTag = (res->ulPropTag & 0xffff0000) | PT_LONG; - translatedRes.relop = res->relop; + translatedRes = talloc (NULL, struct mapi_SPropertyRestriction); + translatedRes->ulPropTag = (res->ulPropTag & 0xffff0000) | PT_LONG; + translatedRes->relop = res->relop; dateValue = NSObjectFromMAPISPropValue (&res->lpProp); longDate = (int32_t) [dateValue timeIntervalSince1970]; - translatedRes.lpProp.ulPropTag = translatedRes.ulPropTag; - translatedRes.lpProp.value.l = longDate; + translatedRes->lpProp.ulPropTag = translatedRes->ulPropTag; + translatedRes->lpProp.value.l = longDate; - return [super evaluatePropertyRestriction: &translatedRes - intoQualifier: qualifier]; + return translatedRes; } - (MAPIRestrictionState) evaluatePropertyRestriction: (struct mapi_SPropertyRestriction *) res intoQualifier: (EOQualifier **) qualifier { + static SEL operators[] = { EOQualifierOperatorLessThan, + EOQualifierOperatorLessThanOrEqualTo, + EOQualifierOperatorGreaterThan, + EOQualifierOperatorGreaterThanOrEqualTo, + EOQualifierOperatorEqual, + EOQualifierOperatorNotEqual, + EOQualifierOperatorContains }; + SEL operator; + id value; + NSString *property; MAPIRestrictionState rc; - if ((res->ulPropTag & 0x0040) == 0x0040) /* is date ? */ - rc = [self evaluateDatePropertyRestriction: res - intoQualifier: qualifier]; + property = [self backendIdentifierForProperty: res->ulPropTag]; + if (property) + { + if (res->relop >= 0 && res->relop < 7) + operator = operators[res->relop]; + else + { + operator = NULL; + [NSException raise: @"MAPIStoreRestrictionException" + format: @"unhandled operator type number %d", res->relop]; + } + + if ((res->ulPropTag & 0xffff) == PT_SYSTIME) + { + res = [self _fixedDatePropertyRestriction: res]; + NSAutoreleaseTallocPointer (res); + } + + value = NSObjectFromMAPISPropValue (&res->lpProp); + if ((res->ulPropTag & 0xffff) == PT_UNICODE) + { + property = [NSString stringWithFormat: @"UPPER(%@)", property]; + value = [value uppercaseString]; + } + + *qualifier = [[EOKeyValueQualifier alloc] initWithKey: property + operatorSelector: operator + value: value]; + [*qualifier autorelease]; + + rc = MAPIRestrictionStateNeedsEval; + } else - rc = [super evaluatePropertyRestriction: res intoQualifier: qualifier]; + { + [self warnUnhandledProperty: res->ulPropTag + inFunction: __FUNCTION__]; + rc = MAPIRestrictionStateAlwaysFalse; + } return rc; }