Avoid duplicated emails in LDAP-based addressbook

Fixes #4129
This commit is contained in:
Francis Lachapelle
2017-04-25 14:49:29 -04:00
parent 4caff58918
commit 59dbef5ee7
3 changed files with 33 additions and 9 deletions
+26 -5
View File
@@ -236,19 +236,40 @@ convention:
- (void) _setEmails: (NSDictionary *) ldifRecord
{
CardElement *homeMail;
NSString* mail;
NSArray *emails;
NSEnumerator *mailList;
id mail;
// Emails from the configured mail fields of the source have already been extracted in
// [LDAPSource _fillEmailsOfEntry:intoLDIFRecord:]
[self addElementWithTag: @"email"
ofType: @"work"
withValue: [ldifRecord objectForKey: @"c_emails"]];
// When importing an LDIF file, add the default mail attribute
mail = [ldifRecord objectForKey: @"mail"];
if ([mail length] && ![[self emails] containsObject: mail])
[self addElementWithTag: @"email"
ofType: @"work"
withValue: [ldifRecord objectForKey: @"mail"]];
if (mail)
{
emails = [self emails];
if ([mail isKindOfClass: [NSArray class]])
{
mailList = [(NSArray *)mail objectEnumerator];
while ((mail = [mailList nextObject]))
{
if ([mail length] && ![emails containsObject: mail])
[self addElementWithTag: @"email"
ofType: @"work"
withValue: mail];
}
}
else if ([mail length] && ![emails containsObject: mail])
{
[self addElementWithTag: @"email"
ofType: @"work"
withValue: mail];
}
}
homeMail = [self elementWithTag: @"email" ofType: @"home"];
[homeMail setSingleValue: [ldifRecord objectForKey: @"mozillasecondemail"] forKey: @""];
[[self uniqueChildWithTag: @"x-mozilla-html"]