Avoid duplicated emails in LDAP-based addressbook

Fixes #4129
pull/236/head
Francis Lachapelle 2017-04-25 14:49:29 -04:00
parent 4caff58918
commit 59dbef5ee7
3 changed files with 33 additions and 9 deletions

1
NEWS
View File

@ -14,6 +14,7 @@ Bug fixes
- [web] fixed email reminder with attendees (#4115) - [web] fixed email reminder with attendees (#4115)
- [web] prevented form to be marked dirty when changing password (#4138) - [web] prevented form to be marked dirty when changing password (#4138)
- [web] restored support for SOGoLDAPContactInfoAttribute - [web] restored support for SOGoLDAPContactInfoAttribute
- [web] avoid duplicated email addresses in LDAP-based addressbook (#4129)
- [core] cherry-picked comma escaping fix from v2 (#3296) - [core] cherry-picked comma escaping fix from v2 (#3296)
- [core] fix sogo-tool restore potentially crashing on corrupted data (#4048) - [core] fix sogo-tool restore potentially crashing on corrupted data (#4048)
- [core] handle properly mails using windows-1255 charset (#4124) - [core] handle properly mails using windows-1255 charset (#4124)

View File

@ -236,19 +236,40 @@ convention:
- (void) _setEmails: (NSDictionary *) ldifRecord - (void) _setEmails: (NSDictionary *) ldifRecord
{ {
CardElement *homeMail; CardElement *homeMail;
NSString* mail; NSArray *emails;
NSEnumerator *mailList;
id mail;
// Emails from the configured mail fields of the source have already been extracted in // Emails from the configured mail fields of the source have already been extracted in
// [LDAPSource _fillEmailsOfEntry:intoLDIFRecord:] // [LDAPSource _fillEmailsOfEntry:intoLDIFRecord:]
[self addElementWithTag: @"email" [self addElementWithTag: @"email"
ofType: @"work" ofType: @"work"
withValue: [ldifRecord objectForKey: @"c_emails"]]; withValue: [ldifRecord objectForKey: @"c_emails"]];
// When importing an LDIF file, add the default mail attribute // When importing an LDIF file, add the default mail attribute
mail = [ldifRecord objectForKey: @"mail"]; mail = [ldifRecord objectForKey: @"mail"];
if ([mail length] && ![[self emails] containsObject: mail]) if (mail)
[self addElementWithTag: @"email" {
ofType: @"work" emails = [self emails];
withValue: [ldifRecord objectForKey: @"mail"]]; 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 = [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"]

View File

@ -25,6 +25,7 @@
#import <NGExtensions/NSObject+Logs.h> #import <NGExtensions/NSObject+Logs.h>
#import <NGObjWeb/WOContext+SoObjects.h> #import <NGObjWeb/WOContext+SoObjects.h>
#import <NGCards/NSDictionary+NGCards.h>
#import "SOGoUser.h" #import "SOGoUser.h"
#import "SOGoUserDefaults.h" #import "SOGoUserDefaults.h"
@ -74,14 +75,15 @@
*/ */
- (NSString *) jsonRepresentation - (NSString *) jsonRepresentation
{ {
NSString *v; id v;
NSMutableDictionary *attrs; NSMutableDictionary *attrs;
attrs = [NSMutableDictionary dictionary]; attrs = [NSMutableDictionary dictionary];
v = [self value: 0 ofAttribute: @"type"]; v = [[self attributes] objectForCaseInsensitiveKey: @"type"];
if ([v length]) if (v && [v isKindOfClass: [NSArray class]] && [v count])
[attrs setObject: v // We can have multiple types, but we only return the first one
[attrs setObject: [v objectAtIndex: 0]
forKey: @"type"]; forKey: @"type"];
[attrs setObject: [self flattenedValuesForKey: @""] [attrs setObject: [self flattenedValuesForKey: @""]
forKey: @"value"]; forKey: @"value"];