/// <summary> /// Add the email to the collection /// </summary> /// <param name="email">The email address to be added</param> /// <returns>The index position it was added at. If the index is -1 then it already exists in the collection</returns> /// <remarks>The only wild card we will support is *</remarks> /// <exception cref="ArgumentException">The email address is in a format not understood</exception> public int Add(string email) { IAddress addr = null; if (m_isAvailable) addr = m_ldapEngine.GetAddressInformation(email); else addr = new Address(email); return Add(addr); }
/// <summary> /// This method will create the address information object /// </summary> /// <param name="ldapResults">The search results to create the object with</param> /// <param name="properties">The properties required.</param> /// <returns>The new address object.</returns> /// <exception cref="InvalidOperationException">If LDAP provider has raised an COM exception</exception> private static IAddress CreateAddress(SearchResult ldapResults, List<string> properties) { Hashtable hh = SearchForProperties(ldapResults, properties); string displayName = ""; string adsPath = ""; string email = ""; ClassType ct = ClassType.Object; if (hh.ContainsKey("cn") && hh["cn"] != null) { if (hh["cn"].GetType() == typeof(string)) displayName = ""; else displayName = ((ResultPropertyValueCollection)hh["cn"])[0].ToString(); } if (hh.ContainsKey("adspath") && hh["adspath"] != null) { adsPath = ((ResultPropertyValueCollection)hh["adspath"])[0].ToString(); // Now remove the server entry from the path if (adsPath.LastIndexOf("/") > -1) adsPath = adsPath.Substring(adsPath.LastIndexOf("/") + 1); } if (hh.ContainsKey("mail") && hh["mail"] != null) { if (hh["mail"].GetType() == typeof(string)) email = hh["mail"].ToString(); else email = ((ResultPropertyValueCollection)hh["mail"])[0].ToString(); if (email.Length == 0) email = adsPath; } if (hh.ContainsKey("objectclass") && hh["objectclass"] != null) { ResultPropertyValueCollection rp = hh["objectclass"] as ResultPropertyValueCollection; foreach (string classType in rp) { switch (classType.ToLower(System.Threading.Thread.CurrentThread.CurrentCulture)) { case "organizationalperson": case "dominoperson": ct = ClassType.User; break; case "dominogroup": case "group": ct = ClassType.Group; break; } if (ct != ClassType.Object) break; } } Address ad = new Address(email, displayName, adsPath); ad.LdapType = ct; return (IAddress)ad; }
public IAddress GetAddressInformation(string email) { IAddress addr = null; if (IsLdapAvailable) { addr = m_engine.GetAddressInformation(email); StringBuilder sb = new StringBuilder(); sb.AppendFormat("Found {0} address for email ({1})", addr.AddressType, email); Logger.LogInfo(sb.ToString()); } else addr = new Address(email); return addr; }