LDIF to vCard: Handle multiple emails & phones
This commit is contained in:
parent
41bc68946d
commit
33b035b360
|
@ -1,6 +1,6 @@
|
||||||
/* NGVCard+SOGo.m - this file is part of SOGo
|
/* NGVCard+SOGo.m - this file is part of SOGo
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009-2014 Inverse inc.
|
* Copyright (C) 2009-2015 Inverse inc.
|
||||||
*
|
*
|
||||||
* This file is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -187,29 +187,59 @@ convention:
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (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]))
|
||||||
|
{
|
||||||
|
element = [CardElement simpleElementWithTag: elementTag
|
||||||
|
singleType: type
|
||||||
|
value: value];
|
||||||
|
[self addChild: element];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void) _setPhoneValues: (NSDictionary *) ldifRecord
|
- (void) _setPhoneValues: (NSDictionary *) ldifRecord
|
||||||
{
|
{
|
||||||
CardElement *phone;
|
[self addElementWithTag: @"tel"
|
||||||
|
ofType: @"work"
|
||||||
phone = [self elementWithTag: @"tel" ofType: @"work"];
|
withValue: [ldifRecord objectForKey: @"telephonenumber"]];
|
||||||
[phone setSingleValue: [ldifRecord objectForKey: @"telephonenumber"] forKey: @""];
|
[self addElementWithTag: @"tel"
|
||||||
phone = [self elementWithTag: @"tel" ofType: @"home"];
|
ofType: @"home"
|
||||||
[phone setSingleValue: [ldifRecord objectForKey: @"homephone"] forKey: @""];
|
withValue: [ldifRecord objectForKey: @"homephone"]];
|
||||||
phone = [self elementWithTag: @"tel" ofType: @"cell"];
|
[self addElementWithTag: @"tel"
|
||||||
[phone setSingleValue: [ldifRecord objectForKey: @"mobile"] forKey: @""];
|
ofType: @"cell"
|
||||||
phone = [self elementWithTag: @"tel" ofType: @"fax"];
|
withValue: [ldifRecord objectForKey: @"mobile"]];
|
||||||
[phone setSingleValue: [ldifRecord objectForKey: @"facsimiletelephonenumber"]
|
[self addElementWithTag: @"tel"
|
||||||
forKey: @""];
|
ofType: @"fax"
|
||||||
phone = [self elementWithTag: @"tel" ofType: @"pager"];
|
withValue: [ldifRecord objectForKey: @"facsimiletelephonenumber"]];
|
||||||
[phone setSingleValue: [ldifRecord objectForKey: @"pager"] forKey: @""];
|
[self addElementWithTag: @"tel"
|
||||||
|
ofType: @"pager"
|
||||||
|
withValue: [ldifRecord objectForKey: @"pager"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _setEmails: (NSDictionary *) ldifRecord
|
- (void) _setEmails: (NSDictionary *) ldifRecord
|
||||||
{
|
{
|
||||||
CardElement *mail, *homeMail;
|
CardElement *homeMail;
|
||||||
|
|
||||||
mail = [self elementWithTag: @"email" ofType: @"work"];
|
// Emails from the configured mail fields of the source have already been extracted in
|
||||||
[mail setSingleValue: [ldifRecord objectForKey: @"mail"] forKey: @""];
|
// [LDAPSource _fillEmailsOfEntry:intoLDIFRecord:]
|
||||||
|
[self addElementWithTag: @"email"
|
||||||
|
ofType: @"work"
|
||||||
|
withValue: [ldifRecord objectForKey: @"c_emails"]];
|
||||||
homeMail = [self elementWithTag: @"email" ofType: @"home"];
|
homeMail = [self elementWithTag: @"email" ofType: @"home"];
|
||||||
[homeMail setSingleValue: [ldifRecord objectForKey: @"mozillasecondemail"] forKey: @""];
|
[homeMail setSingleValue: [ldifRecord objectForKey: @"mozillasecondemail"] forKey: @""];
|
||||||
[[self uniqueChildWithTag: @"x-mozilla-html"]
|
[[self uniqueChildWithTag: @"x-mozilla-html"]
|
||||||
|
|
|
@ -92,7 +92,7 @@
|
||||||
[vcard setProdID: [NSString
|
[vcard setProdID: [NSString
|
||||||
stringWithFormat: @"-//Inverse inc./SOGo %@//EN",
|
stringWithFormat: @"-//Inverse inc./SOGo %@//EN",
|
||||||
SOGoVersion]];
|
SOGoVersion]];
|
||||||
[vcard updateFromLDIFRecord: [self simplifiedLDIFRecord]];
|
[vcard updateFromLDIFRecord: [self ldifRecord]];
|
||||||
|
|
||||||
return vcard;
|
return vcard;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* SOGoContactSourceFolder.m - this file is part of SOGo
|
/* SOGoContactSourceFolder.m - this file is part of SOGo
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2013 Inverse inc.
|
* Copyright (C) 2006-2015 Inverse inc.
|
||||||
*
|
*
|
||||||
* This file is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -249,17 +249,26 @@
|
||||||
[newRecord setObject: data forKey: @"c_cn"];
|
[newRecord setObject: data forKey: @"c_cn"];
|
||||||
|
|
||||||
// mail => emails[]
|
// mail => emails[]
|
||||||
data = [oldRecord objectForKey: @"mail"];
|
data = [oldRecord objectForKey: @"c_emails"];
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
if ([data isKindOfClass: [NSArray class]])
|
if ([data isKindOfClass: [NSArray class]])
|
||||||
{
|
{
|
||||||
if ([data count] > 0)
|
if ([data count] > 0)
|
||||||
data = [data objectAtIndex: 0];
|
{
|
||||||
else
|
NSEnumerator *emails;
|
||||||
data = nil;
|
NSMutableArray *recordEmails;
|
||||||
|
NSString *email;
|
||||||
|
emails = [(NSArray *)data objectEnumerator];
|
||||||
|
recordEmails = [NSMutableArray arrayWithCapacity: [data count]];
|
||||||
|
while ((email = [emails nextObject]))
|
||||||
|
{
|
||||||
|
[recordEmails addObject: [NSDictionary dictionaryWithObject: email forKey: @"value"]];
|
||||||
}
|
}
|
||||||
if (data)
|
[newRecord setObject: recordEmails forKey: @"emails"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (data)
|
||||||
{
|
{
|
||||||
NSDictionary *email;
|
NSDictionary *email;
|
||||||
email = [NSDictionary dictionaryWithObjectsAndKeys: @"pref", @"type", data, @"value", nil];
|
email = [NSDictionary dictionaryWithObjectsAndKeys: @"pref", @"type", data, @"value", nil];
|
||||||
|
|
Loading…
Reference in a new issue