From 7a655ff8cefa0885ccc15bd365c4e6aa8c10c75b Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 21 Mar 2012 15:50:07 +0000 Subject: [PATCH] Monotone-Parent: 54cc41b15e02fc61bfa80e7db07aeb97e541fdfc Monotone-Revision: 3c8a49fe7ef93ec55aaeef9dd064be1de6052cfe Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-03-21T15:50:07 --- ChangeLog | 13 ++++++++ SoObjects/Contacts/SOGoContactGCSEntry.m | 5 +++ SoObjects/Contacts/SOGoContactLDIFEntry.m | 33 +++++++++++++++++++- SoObjects/Contacts/SOGoContactObject.h | 1 + SoObjects/Contacts/SOGoContactSourceFolder.m | 9 +++++- SoObjects/SOGo/SOGoUserManager.m | 15 +++++++-- UI/Contacts/UIxContactEditor.m | 2 +- 7 files changed, 73 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 329fedd75..78221e0d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-03-21 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoUserManager.m (_compactAndCompleteContacts:): + if "mail" is an array, all values are added to "c_emails". + + * SoObjects/Contacts/SOGoContactSourceFolder.m + (_flattenedRecord:): if "mail" is an array, we only take the first + value of it. + + * SoObjects/Contacts/SOGoContactLDIFEntry.m (-simplifiedRecord): + new record guaranteeing that all array values have been stripped + and converted to strings. + 2012-03-20 Francis Lachapelle * SoObjects/Mailer/SOGoMailObject+Draft.m diff --git a/SoObjects/Contacts/SOGoContactGCSEntry.m b/SoObjects/Contacts/SOGoContactGCSEntry.m index 09c18ebbd..fd33f7cfc 100644 --- a/SoObjects/Contacts/SOGoContactGCSEntry.m +++ b/SoObjects/Contacts/SOGoContactGCSEntry.m @@ -76,6 +76,11 @@ return [[self vCard] asLDIFRecord]; } +- (NSDictionary *) simplifiedLDIFRecord +{ + return [self ldifRecord]; +} + - (BOOL) hasPhoto { return ([[self vCard] firstChildWithTag: @"photo"] != nil); diff --git a/SoObjects/Contacts/SOGoContactLDIFEntry.m b/SoObjects/Contacts/SOGoContactLDIFEntry.m index f4b09e800..6801875fb 100644 --- a/SoObjects/Contacts/SOGoContactLDIFEntry.m +++ b/SoObjects/Contacts/SOGoContactLDIFEntry.m @@ -95,7 +95,7 @@ [vcard setProdID: [NSString stringWithFormat: @"-//Inverse inc./SOGo %@//EN", SOGoVersion]]; - [vcard updateFromLDIFRecord: [self ldifRecord]]; + [vcard updateFromLDIFRecord: [self simplifiedLDIFRecord]]; return vcard; } @@ -115,6 +115,37 @@ return ldifEntry; } +- (NSDictionary *) simplifiedLDIFRecord +{ + NSMutableDictionary *newRecord; + NSArray *keys; + NSUInteger count, max; + NSString *key; + id value; + + newRecord = [[self ldifRecord] mutableCopy]; + [newRecord autorelease]; + + keys = [newRecord allKeys]; + max = [keys count]; + for (count = 0; count < max; count++) + { + key = [keys objectAtIndex: count]; + value = [newRecord objectForKey: key]; + if ([value isKindOfClass: [NSArray class]] + && ![key isEqualToString: @"objectclass"]) + { + if ([value count] > 0) + [newRecord setObject: [value objectAtIndex: 0] + forKey: key]; + else + [newRecord removeObjectForKey: key]; + } + } + + return newRecord; +} + - (BOOL) hasPhoto { return NO; diff --git a/SoObjects/Contacts/SOGoContactObject.h b/SoObjects/Contacts/SOGoContactObject.h index 6b718eefa..e49219a91 100644 --- a/SoObjects/Contacts/SOGoContactObject.h +++ b/SoObjects/Contacts/SOGoContactObject.h @@ -33,6 +33,7 @@ /* web editing */ - (void) setLDIFRecord: (NSDictionary *) newLDIFRecord; - (NSDictionary *) ldifRecord; +- (NSDictionary *) simplifiedLDIFRecord; - (NSException *) save; - (NSException *) delete; diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.m b/SoObjects/Contacts/SOGoContactSourceFolder.m index 780bcd742..b4a5b2318 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.m +++ b/SoObjects/Contacts/SOGoContactSourceFolder.m @@ -213,7 +213,7 @@ - (NSDictionary *) _flattenedRecord: (NSDictionary *) oldRecord { NSMutableDictionary *newRecord; - NSString *data; + id data; NSObject *recordSource; newRecord = [NSMutableDictionary dictionaryWithCapacity: 8]; @@ -232,6 +232,13 @@ data = [oldRecord objectForKey: @"mail"]; if (!data) data = @""; + else if ([data isKindOfClass: [NSArray class]]) + { + if ([data count] > 0) + data = [data objectAtIndex: 0]; + else + data = @""; + } [newRecord setObject: data forKey: @"c_mail"]; data = [oldRecord objectForKey: @"nsaimid"]; diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index e84ca329a..6540de462 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -816,11 +816,12 @@ { NSMutableDictionary *compactContacts, *returnContact; NSDictionary *userEntry; - NSArray *newContacts; + NSArray *newContacts, *allEmails; NSMutableArray *emails; NSString *uid, *email, *info; NSNumber *isGroup; id source; + NSUInteger count, max; compactContacts = [NSMutableDictionary dictionary]; while ((userEntry = [contacts nextObject])) @@ -851,7 +852,17 @@ [returnContact setObject: emails forKey: @"emails"]; } email = [userEntry objectForKey: @"mail"]; - if (email && ![emails containsObject: email]) + if ([email isKindOfClass: [NSArray class]]) + { + allEmails = (NSArray *) email; + max = [allEmails count]; + for (count = 0; count < max; count++) + { + email = [allEmails objectAtIndex: count]; + [emails addObjectUniquely: email]; + } + } + else if (email && ![emails containsObject: email]) [emails addObject: email]; email = [userEntry objectForKey: @"mozillasecondemail"]; if (email && ![emails containsObject: email]) diff --git a/UI/Contacts/UIxContactEditor.m b/UI/Contacts/UIxContactEditor.m index 73a88d448..b73125d1a 100644 --- a/UI/Contacts/UIxContactEditor.m +++ b/UI/Contacts/UIxContactEditor.m @@ -88,7 +88,7 @@ static Class SOGoContactGCSEntryK = Nil; if (!ldifRecord) { - clientLDIFRecord = [[self clientObject] ldifRecord]; + clientLDIFRecord = [[self clientObject] simplifiedLDIFRecord]; ldifRecord = [clientLDIFRecord mutableCopy]; queryValue = [self queryParameterForKey: @"contactEmail"]; if ([queryValue length] > 0)