mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-06-02 17:09:44 +00:00
(feat) added custom fields support from Thunderbird's address book
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* NGVCard+SOGo.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009-2014 Inverse inc.
|
||||
* Copyright (C) 2009-2017 Inverse inc.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -45,6 +45,10 @@
|
||||
- (NSString *) pager;
|
||||
- (NSCalendarDate *) birthday;
|
||||
|
||||
- (void) addElementWithTag: (NSString *) elementTag
|
||||
ofType: (NSString *) type
|
||||
withValue: (id) value;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* NGVCARD_SOGO_H */
|
||||
|
||||
@@ -217,9 +217,9 @@ convention:
|
||||
- (void) updateFromLDIFRecord: (NSDictionary *) ldifRecord
|
||||
{
|
||||
NSInteger year, yearOfToday, month, day;
|
||||
NSArray *units, *elements;
|
||||
CardElement *element;
|
||||
NSCalendarDate *now;
|
||||
NSArray *units;
|
||||
NSString *fn, *ou;
|
||||
id o;
|
||||
|
||||
@@ -320,6 +320,43 @@ convention:
|
||||
else
|
||||
[self setCategories: [o componentsSeparatedByString: @","]];
|
||||
|
||||
// Custom fields from Thunderbird
|
||||
if ((o = [ldifRecord objectForKey: @"custom1"]))
|
||||
{
|
||||
elements = [self childrenWithTag: @"custom1"];
|
||||
[self removeChildren: elements];
|
||||
|
||||
if ([o length])
|
||||
[self addElementWithTag: @"custom1" ofType: nil withValue: o];
|
||||
}
|
||||
|
||||
if ((o = [ldifRecord objectForKey: @"custom2"]))
|
||||
{
|
||||
elements = [self childrenWithTag: @"custom2"];
|
||||
[self removeChildren: elements];
|
||||
|
||||
if ([o length])
|
||||
[self addElementWithTag: @"custom2" ofType: nil withValue: o];
|
||||
}
|
||||
|
||||
if ((o = [ldifRecord objectForKey: @"custom3"]))
|
||||
{
|
||||
elements = [self childrenWithTag: @"custom3"];
|
||||
[self removeChildren: elements];
|
||||
|
||||
if ([o length])
|
||||
[self addElementWithTag: @"custom3" ofType: nil withValue: o];
|
||||
}
|
||||
|
||||
if ((o = [ldifRecord objectForKey: @"custom4"]))
|
||||
{
|
||||
elements = [self childrenWithTag: @"custom4"];
|
||||
[self removeChildren: elements];
|
||||
|
||||
if ([o length])
|
||||
[self addElementWithTag: @"custom4" ofType: nil withValue: o];
|
||||
}
|
||||
|
||||
[self cleanupEmptyChildren];
|
||||
}
|
||||
|
||||
@@ -646,6 +683,19 @@ convention:
|
||||
dn = @"";
|
||||
[ldifRecord setObject: dn forKey: @"dn"];
|
||||
|
||||
// Custom fields from Thunderbird
|
||||
if ((stringValue = [[self uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""]) && [stringValue length])
|
||||
[ldifRecord setObject: stringValue forKey: @"custom1"];
|
||||
|
||||
if ((stringValue = [[self uniqueChildWithTag: @"custom2"] flattenedValuesForKey: @""]) && [stringValue length])
|
||||
[ldifRecord setObject: stringValue forKey: @"custom2"];
|
||||
|
||||
if ((stringValue = [[self uniqueChildWithTag: @"custom3"] flattenedValuesForKey: @""]) && [stringValue length])
|
||||
[ldifRecord setObject: stringValue forKey: @"custom3"];
|
||||
|
||||
if ((stringValue = [[self uniqueChildWithTag: @"custom4"] flattenedValuesForKey: @""]) && [stringValue length])
|
||||
[ldifRecord setObject: stringValue forKey: @"custom4"];
|
||||
|
||||
return ldifRecord;
|
||||
}
|
||||
|
||||
@@ -871,4 +921,33 @@ convention:
|
||||
return fields;
|
||||
}
|
||||
|
||||
- (void) addElementWithTag: (NSString *) elementTag
|
||||
ofType: (NSString *) type
|
||||
withValue: (id) value
|
||||
{
|
||||
NSArray *allValues;
|
||||
NSEnumerator *list;
|
||||
CardElement *element;
|
||||
|
||||
// value is either an array or a string
|
||||
if ([value isKindOfClass: [NSString class]])
|
||||
allValues = [NSArray arrayWithObject: value];
|
||||
else
|
||||
allValues = value;
|
||||
|
||||
// Add all values as separate elements
|
||||
list = [allValues objectEnumerator];
|
||||
while ((value = [list nextObject]))
|
||||
{
|
||||
if ([type length])
|
||||
element = [CardElement simpleElementWithTag: elementTag
|
||||
singleType: type
|
||||
value: value];
|
||||
else
|
||||
element = [CardElement simpleElementWithTag: elementTag
|
||||
value: value];
|
||||
[self addChild: element];
|
||||
}
|
||||
}
|
||||
|
||||
@end /* NGVCard */
|
||||
|
||||
Reference in New Issue
Block a user