From 372158a3e90b3bd06d4828d9e0c15550a370dd5a Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 18 Aug 2016 15:34:13 -0400 Subject: [PATCH] (fix) strip protocol value from proxyAddresses (fixes #3182) --- SoObjects/SOGo/LDAPSource.m | 62 +++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index 5f48944ad..c9c2234d3 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -906,7 +906,29 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses { allValues = [[ldapEntry attributeWithName: currentFieldName] allStringValues]; - [emails addObjectsFromArray: allValues]; + + // Special case handling for Microsoft Active Directory. proxyAddresses + // is generally prefixed with smtp: - if we find this (or any value preceeding + // the semi-colon), we strip it. See https://msdn.microsoft.com/en-us/library/ms679424(v=vs.85).aspx + if ([currentFieldName caseInsensitiveCompare: @"proxyAddresses"] == NSOrderedSame) + { + NSRange r; + int i; + + for (i = 0; i < [allValues count]; i++) + { + ldapValue = [allValues objectAtIndex: i]; + r = [ldapValue rangeOfString: @":"]; + if (r.length) + { + [emails addObject: [ldapValue substringFromIndex: r.location+1]]; + } + else + [emails addObject: ldapValue]; + } + } + else + [emails addObjectsFromArray: allValues]; } [ldifRecord setObject: emails forKey: @"c_emails"]; [emails release]; @@ -1695,25 +1717,25 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection, ab = [LDAPSource new]; [ab setSourceID: [sourceRec objectForKey: @"ou"]]; [ab setDisplayName: [sourceRec objectForKey: @"description"]]; - [ab setBindDN: bindDN - password: password - hostname: hostname - port: [NSString stringWithFormat: @"%d", port] - encryption: encryption - bindAsCurrentUser: [NSString stringWithFormat: @"%d", NO]]; - [ab setBaseDN: [entry dn] - IDField: @"cn" - CNField: @"displayName" - UIDField: @"cn" - mailFields: nil - searchFields: nil - groupObjectClasses: nil - IMAPHostField: nil - IMAPLoginField: nil - SieveHostField: nil - bindFields: nil - kindField: nil - andMultipleBookingsField: nil]; + [ab setBindDN: bindDN + password: password + hostname: hostname + port: [NSString stringWithFormat: @"%d", port] + encryption: encryption + bindAsCurrentUser: [NSString stringWithFormat: @"%d", NO]]; + [ab setBaseDN: [entry dn] + IDField: @"cn" + CNField: @"displayName" + UIDField: @"cn" + mailFields: nil + searchFields: nil + groupObjectClasses: nil + IMAPHostField: nil + IMAPLoginField: nil + SieveHostField: nil + bindFields: nil + kindField: nil + andMultipleBookingsField: nil]; [ab setListRequiresDot: NO]; [ab setModifiers: modifier]; [sources addObject: ab];