From 8cfb0f0d44830fe8972990dd781b77cc2372070b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20S=C3=A1ez?= Date: Wed, 23 Sep 2015 15:52:41 +0200 Subject: [PATCH] Avoid inserting second email for Contacts When we have a contact with an email, avoid generating another one with SOGoMailDomain value (normally we ended up with a contact with two identical emails on 'emails' key and for multidomain source we would had ended up with an email @localhost) --- SoObjects/SOGo/SOGoUserManager.m | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 60f69f9a3..4425a8a8e 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -749,21 +749,19 @@ static Class NSNullK; SOGoDomainDefaults *dd; domain = [contact objectForKey: @"c_domain"]; - if ([domain length]) - dd = [SOGoDomainDefaults defaultsForDomain: domain]; - else - dd = [SOGoSystemDefaults sharedSystemDefaults]; + dd = [SOGoDomainDefaults defaultsForDomain: domain]; emails = [contact objectForKey: @"emails"]; - uid = [contact objectForKey: @"c_uid"]; - if ([uid rangeOfString: @"@"].location == NSNotFound) - systemEmail - = [NSString stringWithFormat: @"%@@%@", uid, [dd mailDomain]]; - else - systemEmail = uid; - - // We always add the system email, which will always be returned - // by SOGoUser -systemEmail. - [emails addObject: systemEmail]; + if ([emails count] == 0) + { + uid = [contact objectForKey: @"c_uid"]; + if ([uid rangeOfString: @"@"].location == NSNotFound) + systemEmail = [NSString stringWithFormat: @"%@@%@", uid, [dd mailDomain]]; + else + systemEmail = uid; + // We always add the system email, which will always be returned + // by SOGoUser -systemEmail. + [emails addObject: systemEmail]; + } [contact setObject: [emails objectAtIndex: 0] forKey: @"c_email"]; }