From f48ab310d6bc9de3183bccb6f079daefa084e7f3 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 29 Dec 2016 10:52:32 -0500 Subject: [PATCH] (fix) add support for "other" addresses (fixes #3966) --- ActiveSync/NGVCard+ActiveSync.m | 95 ++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/ActiveSync/NGVCard+ActiveSync.m b/ActiveSync/NGVCard+ActiveSync.m index 608c16d1f..86c5876db 100644 --- a/ActiveSync/NGVCard+ActiveSync.m +++ b/ActiveSync/NGVCard+ActiveSync.m @@ -83,7 +83,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - (NSString *) activeSyncRepresentationInContext: (WOContext *) context { NSArray *emails, *addresses, *categories, *elements; - CardElement *n, *homeAdr, *workAdr; + NSMutableArray *other_addresses; + CardElement *n, *homeAdr, *workAdr, *otherAdr; NSMutableString *s, *a; NSString *url; id o; @@ -232,6 +233,39 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; } + + // Other Address + + other_addresses = [[self childrenWithTag: @"adr"] mutableCopy]; + [other_addresses removeObjectsInArray: [self childrenWithTag: @"adr" andAttribute: @"type" havingValue: @"work"]]; + [other_addresses removeObjectsInArray: [self childrenWithTag: @"adr" andAttribute: @"type" havingValue: @"home"]]; + + if ([other_addresses count]) + { + otherAdr = [other_addresses objectAtIndex: 0]; + a = [NSMutableString string]; + + if ((o = [otherAdr flattenedValueAtIndex: 2 forKey: @""])) + [a appendString: [o activeSyncRepresentationInContext: context]]; + + if ((o = [otherAdr flattenedValueAtIndex: 1 forKey: @""]) && [o length]) + [a appendFormat: @"\n%@", [o activeSyncRepresentationInContext: context]]; + + [s appendFormat: @"%@", a]; + + if ((o = [otherAdr flattenedValueAtIndex: 3 forKey: @""])) + [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; + + if ((o = [otherAdr flattenedValueAtIndex: 4 forKey: @""])) + [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; + + if ((o = [otherAdr flattenedValueAtIndex: 5 forKey: @""])) + [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; + + if ((o = [otherAdr flattenedValueAtIndex: 6 forKey: @""])) + [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; + } + // Other, less important fields if ((o = [self birthday])) { @@ -267,7 +301,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. inContext: (WOContext *) context { CardElement *element; - NSMutableArray *addressLines; + NSMutableArray *addressLines, *other_addresses; id o; // Contact's note @@ -398,6 +432,63 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. atIndex: 6 forKey: @""]; } + // OtherCountry + // + + other_addresses = [[self childrenWithTag: @"adr"] mutableCopy]; + [other_addresses removeObjectsInArray: [self childrenWithTag: @"adr" andAttribute: @"type" havingValue: @"work"]]; + [other_addresses removeObjectsInArray: [self childrenWithTag: @"adr" andAttribute: @"type" havingValue: @"home"]]; + + if ([other_addresses count]) + element = [other_addresses objectAtIndex: 0]; + else + { + element = [CardElement elementWithTag: @"adr"]; + [self addChild: element]; + } + + if ((o = [theValues objectForKey: @"OtherStreet"]) || ![self _isGhosted: @"OtherStreet" inContext: context]) + { + addressLines = [NSMutableArray arrayWithArray: [o componentsSeparatedByString: @"\n"]]; + + [element setSingleValue: @"" + atIndex: 1 forKey: @""]; + [element setSingleValue: [addressLines count] ? [addressLines objectAtIndex: 0] : @"" + atIndex: 2 forKey: @""]; + + // Extended address line. If there are more then 2 address lines we add them to the extended address line. + if ([addressLines count] > 1) + { + [addressLines removeObjectAtIndex: 0]; + [element setSingleValue: [addressLines componentsJoinedByString: @" "] + atIndex: 1 forKey: @""]; + } + } + + if ((o = [theValues objectForKey: @"OtherCity"]) || ![self _isGhosted: @"OtherCity" inContext: context]) + { + [element setSingleValue: [theValues objectForKey: @"OtherCity"] + atIndex: 3 forKey: @""]; + } + + if ((o = [theValues objectForKey: @"OtherState"]) || ![self _isGhosted: @"OtherState" inContext: context]) + { + [element setSingleValue: [theValues objectForKey: @"OtherState"] + atIndex: 4 forKey: @""]; + } + + if ((o = [theValues objectForKey: @"OtherPostalCode"]) || ![self _isGhosted: @"OtherPostalCode" inContext: context]) + { + [element setSingleValue: [theValues objectForKey: @"OtherPostalCode"] + atIndex: 5 forKey: @""]; + } + + if ((o = [theValues objectForKey: @"OtherCountry"]) || ![self _isGhosted: @"OtherCountry" inContext: context]) + { + [element setSingleValue: [theValues objectForKey: @"OtherCountry"] + atIndex: 6 forKey: @""]; + } + // Company's name if ((o = [theValues objectForKey: @"CompanyName"])) [self setOrg: o units: nil];