Keep your Sharepoint Mail Enabled list Email Adress clean

Did you once give the possibility in Sharepoint for Enabled Lists or Libraries and thought, oops the Sharepoint Users can make a real big mess with the Email Adresses in our Active Directoy?

Maybe you give External partners access to Lists via Email. How does the external Customers think about your Company if an Sharepoint user gives mail like it come up in his Mind. For Example one uses <mossdocs@contoso.com> and an other take <moss-docs@contoso.com>.

We implemented a small script whitch gives the Sharepointusers a little clue, what name he can use to give good email adresses any Enabled List.

We made Adaptions in Files EmailSettings.aspx{text} from %HIVE12%.

Keep mind that the files will maybe be overwritten after an Farmupdate so your changes will be lost! Sure this can damage the whole functionality.

In the File EmailSettings.aspx go above the begin Javascript part and drop the Following Serverside Script in:

<%
    SPWeb oWeb = SPControl.GetContextWeb(Context);
    Guid requestListGuid = new System.Guid(Request.QueryString["List"]);

    SPList selectedList = null;
    string listName = "nodefined";

    foreach (SPList list in oWeb.Lists)
    {
        //Response.Write(list.ID);
        //Response.Write(list.Title);
        if(list.ID == requestListGuid)
        {
            listName = list.Title;
        }
    }

    string webTitle = oWeb.Name;
    webTitle = System.Text.RegularExpressions.Regex.Replace(webTitle, "[^0-9a-zA-Z.]", ".");

    // How the Email Generation Rules work.
    // 1. SiteTitle-ListTitle
    // 2. Only Characters 0-9a-zA-Z._- are allowed
    // 3. Alle duplicated points are replaced with singlepoints

    String tmpEmailAlias = webTitle;
    tmpEmailAlias = tmpEmailAlias + "-" + listName;

    tmpEmailAlias = System.Text.RegularExpressions.Regex.Replace(tmpEmailAlias, "[.]+", ".");

    tmpEmailAlias = tmpEmailAlias.Replace("À", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Á", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Â", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Ã", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Ä", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("â", "a");
    tmpEmailAlias = tmpEmailAlias.Replace("ã", "a");
    tmpEmailAlias = tmpEmailAlias.Replace("ä", "ae");
    tmpEmailAlias = tmpEmailAlias.Replace("à", "a");
    tmpEmailAlias = tmpEmailAlias.Replace("á", "a");

    tmpEmailAlias = tmpEmailAlias.Replace("È", "E'");
    tmpEmailAlias = tmpEmailAlias.Replace("É", "E'");
    tmpEmailAlias = tmpEmailAlias.Replace("Ê", "E");
    tmpEmailAlias = tmpEmailAlias.Replace("Ë", "EA");
    tmpEmailAlias = tmpEmailAlias.Replace("ê", "e");
    tmpEmailAlias = tmpEmailAlias.Replace("ë", "ea");
    tmpEmailAlias = tmpEmailAlias.Replace("è", "e");
    tmpEmailAlias = tmpEmailAlias.Replace("é", "e");

    tmpEmailAlias = tmpEmailAlias.Replace("Ì", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("Í", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("Î", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("Ï", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("î", "i");
    tmpEmailAlias = tmpEmailAlias.Replace("ï", "i");
    tmpEmailAlias = tmpEmailAlias.Replace("ì", "i");
    tmpEmailAlias = tmpEmailAlias.Replace("í", "i");

    tmpEmailAlias = tmpEmailAlias.Replace("Ò", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Ó", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Ô", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Õ", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Ö", "OU");
    tmpEmailAlias = tmpEmailAlias.Replace("ô", "o");
    tmpEmailAlias = tmpEmailAlias.Replace("õ", "o");
    tmpEmailAlias = tmpEmailAlias.Replace("ö", "ou");
    tmpEmailAlias = tmpEmailAlias.Replace("ò", "o");
    tmpEmailAlias = tmpEmailAlias.Replace("ó", "o");

    tmpEmailAlias = tmpEmailAlias.Replace("Ù", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("Ú", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("Û", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("Ü", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("û", "u");
    tmpEmailAlias = tmpEmailAlias.Replace("ü", "u");
    tmpEmailAlias = tmpEmailAlias.Replace("ù", "u'");
    tmpEmailAlias = tmpEmailAlias.Replace("ú", "u'");

    tmpEmailAlias = tmpEmailAlias.Replace("Ý", "Y");
    tmpEmailAlias = tmpEmailAlias.Replace("ý", "y");
    tmpEmailAlias = tmpEmailAlias.Replace("ñ", "n");

    tmpEmailAlias = System.Text.RegularExpressions.Regex.Replace(tmpEmailAlias, "[ ]", ".");
    tmpEmailAlias = System.Text.RegularExpressions.Regex.Replace(tmpEmailAlias, "[^0-9a-zA-Z._-]", string.Empty);

    tmpEmailAlias = tmpEmailAlias.ToLower();

    string emailAlias = tmpEmailAlias;

%>

Above we do the biggest part of the Script. Find the Liste Title and the Webname and clean it up with some Replacements. As the First Line inside the Javascript Section place the following single Line. That Line make sure that we get the cleaned EmailAlias as an Javascript Value.

    var l_EmailAlias = '<%=emailAlias%>';

And for the Last in EmailSettings.aspx replace the Following Part:

    function SetControlsDisabled(state)
    {
        document.getElementById("<%= TxtAlias.ClientID %>").disabled = state;
    }

with the little next part:

    function SetControlsDisabled(state)
    {
        if(!state)
        {
            document.getElementById("<%= TxtAlias.ClientID %>").disabled = state;
            document.getElementById("<%= TxtAlias.ClientID %>").value = l_EmailAlias;
        }
        else
        {
            document.getElementById("<%= TxtAlias.ClientID %>").disabled = state;
            document.getElementById("<%= TxtAlias.ClientID %>").value = "";
        }
    }

Thats it and have fun.

Hinterlassen Sie einen Kommentar