mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-05 08:34:30 +00:00
Move setAttributes from NGVCard to UIx*Editors
This commit is contained in:
@@ -34,9 +34,6 @@
|
||||
- (void) updateFromLDIFRecord: (NSDictionary *) ldifRecord;
|
||||
- (NSMutableDictionary *) asLDIFRecord;
|
||||
|
||||
- (void) setAttributes: (NSDictionary *) attributes;
|
||||
//- (NSDictionary *) attributes;
|
||||
|
||||
- (NSString *) workCompany;
|
||||
- (NSString *) fullName;
|
||||
- (NSArray *) secondaryEmails;
|
||||
|
||||
@@ -642,237 +642,6 @@ convention:
|
||||
return ldifRecord;
|
||||
}
|
||||
|
||||
- (void) setAttributes: (NSDictionary *) attributes
|
||||
{
|
||||
NSInteger year, yearOfToday, month, day;
|
||||
CardElement *element;
|
||||
NSCalendarDate *now;
|
||||
NSArray *elements, *values;
|
||||
NSMutableArray *addresses, *units, *categories;
|
||||
NSString *ou;
|
||||
id o;
|
||||
unsigned int i;
|
||||
|
||||
NSLog(@"setAttributes: %@", attributes);
|
||||
|
||||
[self setNWithFamily: [attributes objectForKey: @"sn"]
|
||||
given: [attributes objectForKey: @"givenname"]
|
||||
additional: nil prefixes: nil suffixes: nil];
|
||||
[self setNickname: [attributes objectForKey: @"nickname"]];
|
||||
[self setFn: [attributes objectForKey: @"fn"]];
|
||||
[self setTitle: [attributes objectForKey: @"title"]];
|
||||
|
||||
// element = [self elementWithTag: @"adr" ofType: @"home"];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"mozillahomestreet2"]
|
||||
// atIndex: 1 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"mozillahomestreet"]
|
||||
// atIndex: 2 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"mozillahomelocalityname"]
|
||||
// atIndex: 3 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"mozillahomestate"]
|
||||
// atIndex: 4 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"mozillahomepostalcode"]
|
||||
// atIndex: 5 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"mozillahomecountryname"]
|
||||
// atIndex: 6 forKey: @""];
|
||||
|
||||
// element = [self elementWithTag: @"adr" ofType: @"work"];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"mozillaworkstreet2"]
|
||||
// atIndex: 1 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"street"]
|
||||
// atIndex: 2 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"l"]
|
||||
// atIndex: 3 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"st"]
|
||||
// atIndex: 4 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"postalcode"]
|
||||
// atIndex: 5 forKey: @""];
|
||||
// [element setSingleValue: [ldifRecord objectForKey: @"c"]
|
||||
// atIndex: 6 forKey: @""];
|
||||
if ([[attributes objectForKey: @"addresses"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [self childrenWithTag: @"adr"];
|
||||
[self removeChildren: elements];
|
||||
values = [attributes objectForKey: @"addresses"];
|
||||
addresses = [NSMutableArray arrayWithCapacity: [values count]];
|
||||
for (i = 0; i < [values count]; i++)
|
||||
{
|
||||
o = [values objectAtIndex: i];
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [self elementWithTag: @"adr" ofType: [o objectForKey: @"type"]];
|
||||
[element setSingleValue: [o objectForKey: @"postoffice"]
|
||||
atIndex: 0 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"street2"]
|
||||
atIndex: 1 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"street"]
|
||||
atIndex: 2 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"locality"]
|
||||
atIndex: 3 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"region"]
|
||||
atIndex: 4 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"postalcode"]
|
||||
atIndex: 5 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"country"]
|
||||
atIndex: 6 forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ou = [ldifRecord objectForKey: @"ou"];
|
||||
// if (ou)
|
||||
// units = [NSArray arrayWithObject: ou];
|
||||
// else
|
||||
// units = nil;
|
||||
// [self setOrg: [ldifRecord objectForKey: @"o"]
|
||||
// units: units];
|
||||
if ([[attributes objectForKey: @"orgUnits"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [self childrenWithTag: @"org"];
|
||||
[self removeChildren: elements];
|
||||
values = [attributes objectForKey: @"orgUnits"];
|
||||
units = [NSMutableArray arrayWithCapacity: [values count]];
|
||||
for (i = 0; i < [values count]; i++)
|
||||
{
|
||||
o = [values objectAtIndex: i];
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
[units addObject: [o objectForKey: @"value"]];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
units = nil;
|
||||
}
|
||||
[self setOrg: [attributes objectForKey: @"org"]
|
||||
units: units];
|
||||
|
||||
// [self _setPhoneValues: ldifRecord];
|
||||
|
||||
elements = [self childrenWithTag: @"tel"];
|
||||
[self removeChildren: elements];
|
||||
values = [attributes objectForKey: @"phones"];
|
||||
if ([values isKindOfClass: [NSArray class]])
|
||||
{
|
||||
NSEnumerator *list = [values objectEnumerator];
|
||||
id attrs;
|
||||
while ((attrs = [list nextObject]))
|
||||
{
|
||||
if ([attrs isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [self elementWithTag: @"tel" ofType: [attrs objectForKey: @"type"]];
|
||||
[element setSingleValue: [attrs objectForKey: @"value"] forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [self _setEmails: ldifRecord];
|
||||
if ([[attributes objectForKey: @"emails"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [self childrenWithTag: @"email"];
|
||||
[self removeChildren: elements];
|
||||
values = [attributes objectForKey: @"emails"];
|
||||
if (values)
|
||||
{
|
||||
NSEnumerator *list = [values objectEnumerator];
|
||||
//NSDictionary *attrs;
|
||||
while ((o = [list nextObject]))
|
||||
{
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [self elementWithTag: @"email" ofType: [o objectForKey: @"type"]];
|
||||
[element setSingleValue: [o objectForKey: @"value"] forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [[self elementWithTag: @"url" ofType: @"home"]
|
||||
// setSingleValue: [ldifRecord objectForKey: @"mozillahomeurl"] forKey: @""];
|
||||
// [[self elementWithTag: @"url" ofType: @"work"]
|
||||
// setSingleValue: [ldifRecord objectForKey: @"mozillaworkurl"] forKey: @""];
|
||||
|
||||
elements = [self childrenWithTag: @"url"];
|
||||
[self removeChildren: elements];
|
||||
values = [attributes objectForKey: @"urls"];
|
||||
if ([values isKindOfClass: [NSArray class]])
|
||||
{
|
||||
NSEnumerator *list = [values objectEnumerator];
|
||||
id attrs;
|
||||
while ((attrs = [list nextObject]))
|
||||
{
|
||||
if ([attrs isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [self elementWithTag: @"url" ofType: [attrs objectForKey: @"type"]];
|
||||
[element setSingleValue: [attrs objectForKey: @"value"] forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [[self uniqueChildWithTag: @"x-aim"]
|
||||
// setSingleValue: [ldifRecord objectForKey: @"nsaimid"]
|
||||
// forKey: @""];
|
||||
|
||||
// now = [NSCalendarDate date];
|
||||
// year = [[ldifRecord objectForKey: @"birthyear"] intValue];
|
||||
// if (year < 100)
|
||||
// {
|
||||
// yearOfToday = [now yearOfCommonEra];
|
||||
// if (year == 0)
|
||||
// year = yearOfToday;
|
||||
// else if (yearOfToday < (year + 2000))
|
||||
// year += 1900;
|
||||
// else
|
||||
// year += 2000;
|
||||
// }
|
||||
// month = [[ldifRecord objectForKey: @"birthmonth"] intValue];
|
||||
// day = [[ldifRecord objectForKey: @"birthday"] intValue];
|
||||
|
||||
// if (year && month && day)
|
||||
// [self setBday: [NSString stringWithFormat: @"%.4d-%.2d-%.2d",
|
||||
// year, month, day]];
|
||||
// else
|
||||
// [self setBday: @""];
|
||||
|
||||
// /* hack to carry SOGoLDAPContactInfo to vcards */
|
||||
// [[self uniqueChildWithTag: @"x-sogo-contactinfo"]
|
||||
// setSingleValue: [ldifRecord objectForKey: @"c_info"]
|
||||
// forKey: @""];
|
||||
|
||||
[self setNote: [attributes objectForKey: @"note"]];
|
||||
|
||||
// o = [ldifRecord objectForKey: @"vcardcategories"];
|
||||
|
||||
if ([[attributes objectForKey: @"categories"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [self childrenWithTag: @"categories"];
|
||||
[self removeChildren: elements];
|
||||
values = [attributes objectForKey: @"categories"];
|
||||
categories = [NSMutableArray arrayWithCapacity: [values count]];
|
||||
for (i = 0; i < [values count]; i++)
|
||||
{
|
||||
o = [values objectAtIndex: i];
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
[categories addObject: [o objectForKey: @"value"]];
|
||||
}
|
||||
}
|
||||
[self setCategories: categories];
|
||||
}
|
||||
|
||||
// We can either have an array (from SOGo's web gui) or a
|
||||
// string (from a LDIF import) as the value here.
|
||||
// if ([o isKindOfClass: [NSArray class]])
|
||||
// [self setCategories: o];
|
||||
// else
|
||||
// [self setCategories: [o componentsSeparatedByString: @","]];
|
||||
|
||||
[self cleanupEmptyChildren];
|
||||
|
||||
NSLog(@"%@", [self versitString]);
|
||||
}
|
||||
|
||||
- (NSString *) workCompany
|
||||
{
|
||||
CardElement *org;
|
||||
|
||||
@@ -84,11 +84,6 @@
|
||||
return [self ldifRecord];
|
||||
}
|
||||
|
||||
- (void) setAttributes: (NSDictionary *) newAttributes
|
||||
{
|
||||
[[self vCard] setAttributes: newAttributes];
|
||||
}
|
||||
|
||||
- (BOOL) hasPhoto
|
||||
{
|
||||
return ([[self vCard] firstChildWithTag: @"photo"] != nil);
|
||||
|
||||
@@ -222,45 +222,53 @@ static NSArray *folderListingFields = nil;
|
||||
data = [contactRecord objectForKey: @"c_component"];
|
||||
if ([data length])
|
||||
[contactRecord setObject: data forKey: @"tag"];
|
||||
[contactRecord removeObjectForKey: @"c_component"];
|
||||
|
||||
// c_categories => categories
|
||||
data = [contactRecord objectForKey: @"c_categories"];
|
||||
if ([data length])
|
||||
[contactRecord setObject: data forKey: @"categories"];
|
||||
[contactRecord removeObjectForKey: @"c_categories"];
|
||||
|
||||
// c_name => id
|
||||
data = [contactRecord objectForKey: @"c_name"];
|
||||
if ([data length])
|
||||
[contactRecord setObject: data forKey: @"id"];
|
||||
[contactRecord removeObjectForKey: @"c_name"];
|
||||
|
||||
// c_cn => fn
|
||||
data = [contactRecord objectForKey: @"c_cn"];
|
||||
if ([data length])
|
||||
[contactRecord setObject: data forKey: @"fn"];
|
||||
[contactRecord removeObjectForKey: @"c_cn"];
|
||||
else
|
||||
{
|
||||
data = [contactRecord keysWithFormat: @"%{c_givenname} %{c_sn}"];
|
||||
if ([data length] > 1)
|
||||
{
|
||||
[contactRecord setObject: data forKey: @"c_cn"];
|
||||
}
|
||||
else
|
||||
{
|
||||
data = [contactRecord objectForKey: @"c_o"];
|
||||
[contactRecord setObject: data forKey: @"c_cn"];
|
||||
}
|
||||
}
|
||||
|
||||
// c_givenname => givenname
|
||||
data = [contactRecord objectForKey: @"c_givenname"];
|
||||
if ([data length])
|
||||
[contactRecord setObject: data forKey: @"givenname"];
|
||||
[contactRecord removeObjectForKey: @"c_givenname"];
|
||||
|
||||
// c_sn => sn
|
||||
data = [contactRecord objectForKey: @"c_sn"];
|
||||
if ([data length])
|
||||
[contactRecord setObject: data forKey: @"sn"];
|
||||
[contactRecord removeObjectForKey: @"c_sn"];
|
||||
|
||||
// c_screenname => X-AIM
|
||||
if (![contactRecord objectForKey: @"c_screenname"])
|
||||
[contactRecord setObject: @"" forKey: @"c_screenname"];
|
||||
|
||||
// c_o => org
|
||||
data = [contactRecord objectForKey: @"c_o"];
|
||||
if ([data length])
|
||||
[contactRecord setObject: data forKey: @"org"];
|
||||
[contactRecord removeObjectForKey: @"c_o"];
|
||||
|
||||
// c_mail => emails[]
|
||||
data = [contactRecord objectForKey: @"c_mail"];
|
||||
@@ -270,7 +278,8 @@ static NSArray *folderListingFields = nil;
|
||||
email = [NSDictionary dictionaryWithObjectsAndKeys: @"pref", @"type", data, @"value", nil];
|
||||
[contactRecord setObject: [NSArray arrayWithObject: email] forKey: @"emails"];
|
||||
}
|
||||
[contactRecord removeObjectForKey: @"c_mail"];
|
||||
else
|
||||
[contactRecord setObject: @"" forKey: @"c_mail"];
|
||||
|
||||
// c_telephonenumber => phones
|
||||
data = [contactRecord objectForKey: @"c_telephonenumber"];
|
||||
@@ -280,7 +289,8 @@ static NSArray *folderListingFields = nil;
|
||||
phonenumber = [NSDictionary dictionaryWithObjectsAndKeys: @"pref", @"type", data, @"value", nil];
|
||||
[contactRecord setObject: [NSArray arrayWithObject: phonenumber] forKey: @"phones"];
|
||||
}
|
||||
[contactRecord removeObjectForKey: @"c_telephonenumber"];
|
||||
else
|
||||
[contactRecord setObject: @"" forKey: @"c_telephonenumber"];
|
||||
}
|
||||
|
||||
- (NSArray *) _flattenedRecords: (NSArray *) records
|
||||
|
||||
@@ -37,10 +37,7 @@
|
||||
- (NSDictionary *) ldifRecord;
|
||||
- (NSDictionary *) simplifiedLDIFRecord;
|
||||
|
||||
- (void) setAttributes: (NSDictionary *) newAttributes;
|
||||
|
||||
- (NSException *) save;
|
||||
- (NSException *) delete;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -217,6 +217,11 @@
|
||||
return [source removeContactEntryWithID: [ldifEntry nameInContainer]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize keys of dictionary representing a contact.
|
||||
* @param oldRecord a dictionary with pairs from the source folder (LDAP or SQL)
|
||||
* @see [SOGoContactGCSFolder _fixupContactRecord]
|
||||
*/
|
||||
- (NSDictionary *) _flattenedRecord: (NSDictionary *) oldRecord
|
||||
{
|
||||
NSMutableDictionary *newRecord;
|
||||
@@ -226,26 +231,45 @@
|
||||
newRecord = [NSMutableDictionary dictionaryWithCapacity: 8];
|
||||
[newRecord setObject: [oldRecord objectForKey: @"c_uid"]
|
||||
forKey: @"c_uid"];
|
||||
|
||||
// c_name => id
|
||||
[newRecord setObject: [oldRecord objectForKey: @"c_name"]
|
||||
forKey: @"c_name"];
|
||||
[newRecord setObject: [oldRecord objectForKey: @"c_name"]
|
||||
forKey: @"id"];
|
||||
|
||||
// displayname || c_cn => fn
|
||||
data = [oldRecord objectForKey: @"displayname"];
|
||||
if (!data)
|
||||
data = [oldRecord objectForKey: @"c_cn"];
|
||||
if (!data)
|
||||
if (data)
|
||||
[newRecord setObject: data forKey: @"fn"];
|
||||
else
|
||||
data = @"";
|
||||
[newRecord setObject: data forKey: @"c_cn"];
|
||||
|
||||
// mail => emails[]
|
||||
data = [oldRecord objectForKey: @"mail"];
|
||||
if (!data)
|
||||
data = @"";
|
||||
else if ([data isKindOfClass: [NSArray class]])
|
||||
if (data)
|
||||
{
|
||||
if ([data count] > 0)
|
||||
data = [data objectAtIndex: 0];
|
||||
if ([data isKindOfClass: [NSArray class]])
|
||||
{
|
||||
if ([data count] > 0)
|
||||
data = [data objectAtIndex: 0];
|
||||
else
|
||||
data = nil;
|
||||
}
|
||||
if (data)
|
||||
{
|
||||
NSDictionary *email;
|
||||
email = [NSDictionary dictionaryWithObjectsAndKeys: @"pref", @"type", data, @"value", nil];
|
||||
[newRecord setObject: [NSArray arrayWithObject: email] forKey: @"emails"];
|
||||
}
|
||||
else
|
||||
data = @"";
|
||||
}
|
||||
else
|
||||
data = @"";
|
||||
[newRecord setObject: data forKey: @"c_mail"];
|
||||
|
||||
data = [oldRecord objectForKey: @"nsaimid"];
|
||||
@@ -255,17 +279,27 @@
|
||||
data = @"";
|
||||
[newRecord setObject: data forKey: @"c_screenname"];
|
||||
|
||||
// o => org
|
||||
data = [oldRecord objectForKey: @"o"];
|
||||
if (!data)
|
||||
if (data)
|
||||
[newRecord setObject: data forKey: @"org"];
|
||||
else
|
||||
data = @"";
|
||||
[newRecord setObject: data forKey: @"c_o"];
|
||||
|
||||
// telephonenumber || cellphone || homephone => phones[]
|
||||
data = [oldRecord objectForKey: @"telephonenumber"];
|
||||
if (![data length])
|
||||
data = [oldRecord objectForKey: @"cellphone"];
|
||||
if (![data length])
|
||||
data = [oldRecord objectForKey: @"homephone"];
|
||||
if (![data length])
|
||||
if (data)
|
||||
{
|
||||
NSDictionary *phonenumber;
|
||||
phonenumber = [NSDictionary dictionaryWithObjectsAndKeys: @"pref", @"type", data, @"value", nil];
|
||||
[newRecord setObject: [NSArray arrayWithObject: phonenumber] forKey: @"phones"];
|
||||
}
|
||||
else
|
||||
data = @"";
|
||||
else if ([data isKindOfClass: [NSArray class]])
|
||||
{
|
||||
@@ -282,17 +316,21 @@
|
||||
if (data)
|
||||
{
|
||||
[newRecord setObject: data forKey: @"isGroup"];
|
||||
[newRecord setObject: @"vlist" forKey: @"c_component"];
|
||||
[newRecord setObject: @"vlist" forKey: @"tag"];
|
||||
}
|
||||
#warning TODO: create a custom icon for resources
|
||||
else
|
||||
{
|
||||
[newRecord setObject: @"vcard" forKey: @"c_component"];
|
||||
[newRecord setObject: @"vcard" forKey: @"tag"];
|
||||
}
|
||||
|
||||
// c_info => note
|
||||
data = [oldRecord objectForKey: @"c_info"];
|
||||
if ([data length] > 0)
|
||||
[newRecord setObject: data forKey: @"contactInfo"];
|
||||
{
|
||||
[newRecord setObject: data forKey: @"note"];
|
||||
[newRecord setObject: data forKey: @"contactInfo"];
|
||||
}
|
||||
|
||||
recordSource = [oldRecord objectForKey: @"source"];
|
||||
if ([recordSource conformsToProtocol: @protocol (SOGoDNSource)] &&
|
||||
|
||||
Reference in New Issue
Block a user