From 218712bc0f7a22eb679074d88ca02e88ea4d8557 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 11 Jan 2011 21:21:42 +0000 Subject: [PATCH] Monotone-Parent: 044ebf928befcb199e07d3b192460518361eb827 Monotone-Revision: 94c9fbf7703f8bdb98dae4ab4791e27a4d07d72a Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-01-11T21:21:42 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 14 ++ OpenChange/MAPIStoreContactsMessageTable.m | 269 +++++++++++++++++---- 2 files changed, 239 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9acf1b60a..987f6cecc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-01-11 Wolfgang Sourdeau + * OpenChange/MAPIStoreContactsMessageTable.m + (-_element:ofType:excluding:inCard:): new version of the previous + -_phoneOfType:excluding:inCard: method, which now returns the + requested element rather than it's first value and which enables + the specification of the tag. + (-getChildProperty:forKey:withTag:): added support for + PidLidPostalAddressId, PR_POSTAL_ADDRESS_UNICODE, + PR_POST_OFFICE_BOX_UNICODE, PR_STREET_ADDRESS_UNICODE, + PR_LOCALITY_UNICODE, PR_STATE_OR_PROVINCE_UNICODE, + PR_POSTAL_CODE_UNICODE, PR_COUNTRY_UNICODE, PidLidWorkAddress, + PidLidWorkAddressPostOfficeBox, PidLidWorkAddressStreet, + PidLidWorkAddressCity, PidLidWorkAddressState, + PidLidWorkAddressPostalCode and PidLidWorkAddressCountry. + * OpenChange/MAPIStoreContext.m (-openMessage:forKey:inTable:): avoid taking NULL values into account when returning the basic properties. diff --git a/OpenChange/MAPIStoreContactsMessageTable.m b/OpenChange/MAPIStoreContactsMessageTable.m index f7f847d1a..f173037b4 100644 --- a/OpenChange/MAPIStoreContactsMessageTable.m +++ b/OpenChange/MAPIStoreContactsMessageTable.m @@ -53,45 +53,30 @@ return componentQualifier; } -- (NSString *) _phoneOfType: (NSString *) aType - excluding: (NSString *) aTypeToExclude - inCard: (NGVCard *) card +- (CardElement *) _element: (NSString *) elementTag + ofType: (NSString *) aType + excluding: (NSString *) aTypeToExclude + inCard: (NGVCard *) card { NSArray *elements; - NSArray *phones; - NSString *phone; + CardElement *ce, *found; + NSUInteger count, max; - phones = [card childrenWithTag: @"tel"]; + found = nil; - elements = [phones cardElementsWithAttribute: @"type" - havingValue: aType]; - - phone = nil; - - if ([elements count] > 0) + elements = [[card childrenWithTag: elementTag] + cardElementsWithAttribute: @"type" + havingValue: aType]; + max = [elements count]; + for (count = 0; !found && count < max; count++) { - CardElement *ce; - int i; - - for (i = 0; i < [elements count]; i++) - { - ce = [elements objectAtIndex: i]; - phone = [ce value: 0]; - - if (!aTypeToExclude) - break; - - if (![ce hasAttribute: @"type" havingValue: aTypeToExclude]) - break; - - phone = nil; - } + ce = [elements objectAtIndex: count]; + if (!aTypeToExclude + || ![ce hasAttribute: @"type" havingValue: aTypeToExclude]) + found = ce; } - if (!phone) - phone = @""; - - return phone; + return found; } - (enum MAPISTATUS) getChildProperty: (void **) data @@ -100,6 +85,8 @@ { NSString *stringValue; SOGoContactGCSEntry *child; + CardElement *element; + uint32_t longValue; enum MAPISTATUS rc; rc = MAPI_E_SUCCESS; @@ -137,6 +124,8 @@ child = [self lookupChild: childKey]; /* that's buggy but it's for the demo */ stringValue = [[[child vCard] org] componentsJoinedByString: @", "]; + if (!stringValue) + stringValue = @""; *data = [stringValue asUnicodeInMemCtx: memCtx]; break; @@ -160,30 +149,46 @@ case PR_OFFICE_TELEPHONE_NUMBER_UNICODE: child = [self lookupChild: childKey]; - stringValue = [self _phoneOfType: @"work" - excluding: @"fax" - inCard: [child vCard]]; + element = [self _element: @"phone" ofType: @"work" + excluding: @"fax" + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; *data = [stringValue asUnicodeInMemCtx: memCtx]; break; case PR_HOME_TELEPHONE_NUMBER_UNICODE: child = [self lookupChild: childKey]; - stringValue = [self _phoneOfType: @"home" - excluding: @"fax" - inCard: [child vCard]]; + element = [self _element: @"phone" ofType: @"home" + excluding: @"fax" + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; *data = [stringValue asUnicodeInMemCtx: memCtx]; break; case PR_MOBILE_TELEPHONE_NUMBER_UNICODE: child = [self lookupChild: childKey]; - stringValue = [self _phoneOfType: @"cell" - excluding: nil - inCard: [child vCard]]; + element = [self _element: @"phone" ofType: @"cell" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; *data = [stringValue asUnicodeInMemCtx: memCtx]; break; case PR_PRIMARY_TELEPHONE_NUMBER_UNICODE: child = [self lookupChild: childKey]; - stringValue = [self _phoneOfType: @"pref" - excluding: nil - inCard: [child vCard]]; + element = [self _element: @"phone" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; *data = [stringValue asUnicodeInMemCtx: memCtx]; break; @@ -193,6 +198,182 @@ *data = [@"SMTP" asUnicodeInMemCtx: memCtx]; break; + case PidLidPostalAddressId: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if ([element hasAttribute: @"type" + havingValue: @"home"]) + longValue = 1; + else if ([element hasAttribute: @"type" + havingValue: @"work"]) + longValue = 2; + else + longValue = 0; + *data = MAPILongValue (memCtx, longValue); + break; + + /* preferred address */ + case PR_POSTAL_ADDRESS_UNICODE: + child = [self lookupChild: childKey]; + element = [self _element: @"label" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PR_POST_OFFICE_BOX_UNICODE: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PR_STREET_ADDRESS_UNICODE: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 2]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PR_LOCALITY_UNICODE: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 3]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PR_STATE_OR_PROVINCE_UNICODE: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 4]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PR_POSTAL_CODE_UNICODE: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 5]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PR_COUNTRY_UNICODE: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"pref" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 6]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + + // case PidLidAddressCountryCode: + + case PidLidWorkAddress: + child = [self lookupChild: childKey]; + element = [self _element: @"label" ofType: @"work" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + + case PidLidWorkAddressPostOfficeBox: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"work" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 0]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PidLidWorkAddressStreet: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"work" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 2]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PidLidWorkAddressCity: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"work" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 3]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PidLidWorkAddressState: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"work" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 4]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PidLidWorkAddressPostalCode: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"work" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 5]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + case PidLidWorkAddressCountry: + child = [self lookupChild: childKey]; + element = [self _element: @"adr" ofType: @"work" + excluding: nil + inCard: [child vCard]]; + if (element) + stringValue = [element value: 6]; + else + stringValue = @""; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + default: rc = [super getChildProperty: data forKey: childKey