/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event. /// </summary> /// <param name="e"> /// An <see cref="T:System.EventArgs"/> object that contains the event data. /// </param> protected override void OnInit(EventArgs e) { this.To = new EmailAddressList(); this.Cc = new EmailAddressList(); this.Bcc = new EmailAddressList(); var h = new HtmlEditorDataType(); var pS = (PortalSettings)HttpContext.Current.Items["PortalSettings"]; try { h.Value = pS.CustomSettings["SITESETTINGS_DEFAULT_EDITOR"].ToString(); this.txtBody = h.GetEditor( this.PlaceHolderHTMLEditor, int.Parse(this.Context.Request["mID"]), bool.Parse(pS.CustomSettings["SITESETTINGS_SHOWUPLOAD"].ToString()), pS); } catch { this.txtBody = h.GetEditor(this.PlaceHolderHTMLEditor, int.Parse(this.Context.Request["mID"]), true, pS); } this.lblEmailAddressesNotOk.Text = General.GetString( "EMF_ADDRESSES_NOT_OK", "The emailaddresses are not ok.", this.lblEmailAddressesNotOk); this.txtTo.Text = string.Join(";", (string[])this.To.ToArray(typeof(string))); this.txtCc.Text = string.Join(";", (string[])this.Cc.ToArray(typeof(string))); this.txtBcc.Text = string.Join(";", (string[])this.Bcc.ToArray(typeof(string))); base.OnInit(e); }
/// <summary> /// Returns the "Last Modified" string, or an empty string if option is not active. /// </summary> /// <returns> /// The get last modified. /// </returns> public string GetLastModified() { // CHANGE by [email protected] on june, 2 2003 if (((ISettingItem<bool>)this.PortalSettings.CustomSettings["SITESETTINGS_SHOW_MODIFIED_BY"]).Value && ((ISettingItem<bool>)this.Settings["MODULESETTINGS_SHOW_MODIFIED_BY"]).Value) { // Get stuff from database var email = string.Empty; var timeStamp = DateTime.MinValue; WorkFlowDB.GetLastModified(this.ModuleID, this.Version, ref email, ref timeStamp); // Do some checking if (email == string.Empty) { return string.Empty; } // Check if email address is valid var eal = new EmailAddressList(); try { eal.Add(email); email = string.Format("<a href=\"mailto:{0}\">{1}</a>", email, email); } catch { } // Construct the rest of the html return string.Format( "<span class=\"LastModified\">{0} {1} {2} {3} {4}</span>", General.GetString("LMB_LAST_MODIFIED_BY"), email, General.GetString("LMB_ON"), timeStamp.ToLongDateString(), timeStamp.ToShortTimeString()); } return string.Empty; // END CHANGE by [email protected] on june, 2 2003 }
/// <summary> /// This function returns an EmailAddressList object. /// </summary> /// <param name="Account"> /// Windows user or group /// </param> /// <returns> /// EmailAddressList /// </returns> /// <remarks> /// </remarks> public static EmailAddressList GetEmailAddresses(string Account) { // Lookup the domain in which we must look for the user or group var account = Account.Split("\\".ToCharArray()); if (account.Length != 2) { return new EmailAddressList(); // not a valid windows account! } DirectoryEntry rootEntry = null; var domains = Config.ADdns.Split(";".ToCharArray()); // jes1111 - ConfigurationSettings.AppSettings["ADdns"].Split(";".ToCharArray()); // NT domains do not keep track of email addresses foreach (var t in domains.Where(t => !t.Trim().ToLower().StartsWith("winnt://"))) { rootEntry = GetDomainRoot(t); if (GetNetbiosName(rootEntry).Trim().ToLower() == account[0].Trim().ToLower()) { break; } rootEntry = null; } // Unknown domain : return empty list if (rootEntry == null) { return new EmailAddressList(); } // Domain found: lets lookup the object DirectoryEntry entry; using (var mySearcher = new DirectorySearcher(rootEntry)) { mySearcher.Filter = "(&(|(objectClass=group)(&(objectClass=user)(objectCategory=person)))(sAMAccountName=" + account[1] + "))"; mySearcher.PropertiesToLoad.Add("mail"); mySearcher.PropertiesToLoad.Add("objectClass"); mySearcher.PropertiesToLoad.Add("member"); try { entry = mySearcher.FindOne().GetDirectoryEntry(); } catch { throw new Exception(string.Format("Could not get users/groups from domain '{0}'.", account[0])); } } // determine account type var accounttype = GetAccountType(entry); var eal = new EmailAddressList(); // object is user --> retrieve its email address and return if (accounttype == ADAccountType.user) { try { eal.Add(entry.Properties["mail"][0]); } catch { } return eal; } // object is group --> retrieve all users that are contained // in the group or in groups of the group GetUsersInGroup(entry, eal, new ArrayList()); return eal; }
/// <summary> /// Gets the users in group. /// </summary> /// <param name="group"> /// The group. /// </param> /// <param name="eal"> /// The eal. /// </param> /// <param name="searchedGroups"> /// The searched groups. /// </param> /// <remarks> /// </remarks> private static void GetUsersInGroup(DirectoryEntry group, EmailAddressList eal, ArrayList searchedGroups) { // Search all users/groups in directoryentry var rootPath = group.Path; rootPath = rootPath.Substring(0, rootPath.IndexOf("/", 7) + 1); searchedGroups.Add(group.Path); for (var i = 0; i < group.Properties["member"].Count; i++) { var currentEntry = new DirectoryEntry(rootPath + group.Properties["member"][i]); if (GetAccountType(currentEntry) == ADAccountType.user) { // add to eal var values = currentEntry.Properties["mail"]; if (values.Count > 0) { var email = (string)values[0]; if (!eal.Contains(email)) { try { eal.Add(email); } catch { } } } } else { // see if we already had the group if (!searchedGroups.Contains(currentEntry.Path)) { GetUsersInGroup(currentEntry, eal, searchedGroups); } } } }
/// <summary> /// Gets the email addresses in roles. /// </summary> /// <param name="roles"> /// The roles. /// </param> /// <param name="portalId"> /// The portal ID. /// </param> /// <returns> /// A string[] value... /// </returns> public static string[] GetEmailAddressesInRoles(string[] roles, int portalId) { if (Config.UseSingleUserBase) { portalId = 0; } if (HttpContext.Current.User is WindowsPrincipal) { var addresses = new List<string>(); foreach (var t in roles.Select(ADHelper.GetEmailAddresses).SelectMany( ea => ea.Cast<string>().Where(t => !addresses.Contains(t)))) { addresses.Add(t); } return addresses.ToArray(); } // No roles --> no email addresses if (roles.Length == 0) { return new string[0]; } // Build the SQL select var adaptedRoles = new string[roles.Length]; for (var i = 0; i < roles.Length; i++) { adaptedRoles[i] = roles[i].Replace("'", "''"); } var delimitedRoleList = string.Format("N'{0}'", string.Join("', N'", adaptedRoles)); var sql = string.Format( "SELECT DISTINCT rb_Users.Email FROM rb_UserRoles INNER JOIN rb_Users ON rb_UserRoles.UserID = rb_Users.UserID INNER JOIN rb_Roles ON rb_UserRoles.RoleID = rb_Roles.RoleID WHERE (rb_Users.PortalID = {0}) AND (rb_Roles.RoleName IN ({1}))", portalId, delimitedRoleList); // Execute the SQL var eal = new EmailAddressList(); var reader = DBHelper.GetDataReader(sql); try { while (reader.Read()) { if (!reader.IsDBNull(0)) { try { var email = reader.GetString(0); if (email.Trim().Length != 0) { eal.Add(email); } } catch { } } } } finally { reader.Close(); } // Return the result return (string[])eal.ToArray(typeof(string)); }
/// <summary> /// This function return's the email address of the current logged on user. /// If its email-address is not valid or not found, /// then the Default address is returned /// </summary> /// <param name="defaultEmail"> /// The default email. /// </param> /// <param name="validated"> /// if set to <c>true</c> [validated]. /// </param> /// <returns> /// Current user's email address. /// </returns> public static string GetCurrentUserEmailAddress(string defaultEmail, bool validated = true) { if (HttpContext.Current.User is WindowsPrincipal) { // windows user var eal = ADHelper.GetEmailAddresses(HttpContext.Current.User.Identity.Name); return eal.Count == 0 ? defaultEmail : (string)eal[0]; } else { // Get the logged on email address from the context // string email = System.Web.HttpContext.Current.User.Identity.Name; var email = PortalSettings.CurrentUser.Identity.Email; if (!validated) { return email; } // Check if its email address is valid var eal = new EmailAddressList(); try { eal.Add(email); return email; } catch { return defaultEmail; } } }