Exemplo n.º 1
0
        public static void add_addresses_to_email(MailMessage msg, string addrs, AddrType addr_type)
        {
            Util.write_to_log("to email addr: " + addrs);

            string separator_char = Util.get_setting("EmailAddressSeparatorCharacter", ",");

            string[] addr_array = addrs.Replace(separator_char + " ", separator_char).Split(separator_char[0]);

            for (int i = 0; i < addr_array.Length; i++)
            {
                string just_address = Email.simplify_email_address(addr_array[i]);
                string just_display_name = addr_array[i].Replace(just_address, "").Replace("<>", "");
                if (addr_type == AddrType.to)
                {
                    msg.To.Add(new MailAddress(just_address, just_display_name, Encoding.UTF8));
                }
                else
                {
                    msg.CC.Add(new MailAddress(just_address, just_display_name, Encoding.UTF8));
                }
            }
        }
Exemplo n.º 2
0
        ///////////////////////////////////////////////////////////////////////
        public static DataRow get_user_datarow_maybe_using_from_addr(SharpMimeMessage mime_message, string from_addr, string username)
        {
            DataRow dr = null;

            string sql = @"
select us_id, us_admin, us_username, us_org, og_other_orgs_permission_level, isnull(us_forced_project,0) us_forced_project
from users
inner join orgs on us_org = og_id
where us_username = N'$us'";

            // Create a new user from the "from" email address
            string btnet_service_username = Util.get_setting("CreateUserFromEmailAddressIfThisUsername", "");

            if (!string.IsNullOrEmpty(from_addr) && username == btnet_service_username)
            {
                // We can do a better job of parsing the from_addr here than we did in btnet_service.exe
                if (mime_message != null)
                {
                    if (mime_message.Header.From != null && mime_message.Header.From != "")
                    {
                        from_addr = SharpMimeTools.parserfc2047Header(mime_message.Header.From);

                        // handle multiline from
                        from_addr = from_addr.Replace("\t", " ");
                    }
                }

                // See if there's already a username that matches this email address
                username = Email.simplify_email_address(from_addr);

                // Does a user with this email already exist?
                sql = sql.Replace("$us", username.Replace("'", "''"));

                // We maybe found [email protected], so let's use him as the user instead of the btnet_service.exe user
                dr = btnet.DbUtil.get_datarow(sql);

                // We didn't find the user, so let's create him, using the email address as the username.
                if (dr == null)
                {
                    bool use_domain_as_org_name = Util.get_setting("UseEmailDomainAsNewOrgNameWhenCreatingNewUser", "0") == "1";

                    btnet.User.copy_user(
                        username,
                        username,
                        "", "", "",                // first, last, signature
                        0,                         // salt
                        Guid.NewGuid().ToString(), // random value for password,
                        Util.get_setting("CreateUsersFromEmailTemplate", "[error - missing user template]"),
                        use_domain_as_org_name);

                    // now that we have created a user, try again
                    dr = btnet.DbUtil.get_datarow(sql);
                }
            }
            else
            {
                // Use the btnet_service.exe user as the username
                sql = sql.Replace("$us", username.Replace("'", "''"));
                dr  = btnet.DbUtil.get_datarow(sql);
            }

            return(dr);
        }
Exemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////
        public void Page_Load(Object sender, EventArgs e)
        {
            btnet.Util.do_not_cache(Response);
            Page.Header.Title = btnet.Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                                + "send email";

            msg.InnerText = "";

            string string_bp_id = Request["bp_id"];
            string string_bg_id = Request["bg_id"];
            string request_to   = Request["to"];
            string reply        = Request["reply"];

            enable_internal_posts = (Util.get_setting("EnableInternalOnlyPosts", "0") == "1");

            if (!enable_internal_posts)
            {
                include_internal_posts.Visible       = false;
                include_internal_posts_label.Visible = false;
            }

            if (!IsPostBack)
            {
                Session["email_addresses"] = null;

                DataRow dr = null;

                if (string_bp_id != null)
                {
                    string_bp_id = btnet.Util.sanitize_integer(string_bp_id);

                    sql = new SQLString(@"select
				bp_parent,
                bp_file,
                bp_id,
				bg_id,
				bg_short_desc,
				bp_email_from,
				bp_comment,
				bp_email_from,
				bp_date,
				bp_type,
                bp_content_type,
				bg_project,
                bp_hidden_from_external_users,
				isnull(us_signature,'') [us_signature],
				isnull(pj_pop3_email_from,'') [pj_pop3_email_from],
				isnull(us_email,'') [us_email],
				isnull(us_firstname,'') [us_firstname],
				isnull(us_lastname,'') [us_lastname]				
				from bug_posts
				inner join bugs on bp_bug = bg_id
				inner join users on us_id = @us
				left outer join projects on bg_project = pj_id
				where bp_id = @id
				or (bp_parent = @id and bp_type='file')"                );

                    sql = sql.AddParameterWithValue("id", string_bp_id);
                    sql = sql.AddParameterWithValue("us", Convert.ToString(User.Identity.GetUserId()));

                    DataView dv = btnet.DbUtil.get_dataview(sql);
                    dr = null;
                    if (dv.Count > 0)
                    {
                        dv.RowFilter = "bp_id = " + string_bp_id;
                        if (dv.Count > 0)
                        {
                            dr = dv[0].Row;
                        }
                    }

                    int int_bg_id        = (int)dr["bg_id"];
                    int permission_level = btnet.Bug.get_bug_permission_level(int_bg_id, User.Identity);
                    if (permission_level == PermissionLevel.None)
                    {
                        Response.Write("You are not allowed to view this item");
                        Response.End();
                    }

                    if ((int)dr["bp_hidden_from_external_users"] == 1)
                    {
                        if (User.Identity.GetIsExternalUser())
                        {
                            Response.Write("You are not allowed to view this post");
                            Response.End();
                        }
                    }

                    string_bg_id   = Convert.ToString(dr["bg_id"]);
                    back_href.HRef = "edit_bug.aspx?id=" + string_bg_id;
                    bg_id.Value    = string_bg_id;


                    to.Value = dr["bp_email_from"].ToString();


                    // Work around for a mysterious bug:
                    // http://sourceforge.net/tracker/?func=detail&aid=2815733&group_id=66812&atid=515837
                    if (btnet.Util.get_setting("StripDisplayNameFromEmailAddress", "0") == "1")
                    {
                        to.Value = Email.simplify_email_address(to.Value);
                    }

                    load_from_dropdown(dr, true); // list the project's email address first

                    if (reply != null && reply == "all")
                    {
                        Regex    regex    = new Regex("\n");
                        string[] lines    = regex.Split((string)dr["bp_comment"]);
                        string   cc_addrs = "";

                        int max = lines.Length < 5 ? lines.Length : 5;

                        // gather cc addresses, which might include the current user
                        for (int i = 0; i < max; i++)
                        {
                            if (lines[i].StartsWith("To:") || lines[i].StartsWith("Cc:"))
                            {
                                string cc_addr = lines[i].Substring(3, lines[i].Length - 3).Trim();

                                // don't cc yourself

                                if (cc_addr.IndexOf(from.SelectedItem.Value) == -1)
                                {
                                    if (cc_addrs != "")
                                    {
                                        cc_addrs += ",";
                                    }

                                    cc_addrs += cc_addr;
                                }
                            }
                        }

                        cc.Value = cc_addrs;
                    }

                    if (dr["us_signature"].ToString() != "")
                    {
                        if (User.Identity.GetUseFCKEditor())
                        {
                            body.Value += "<br><br><br>";
                            body.Value += dr["us_signature"].ToString().Replace("\r\n", "<br>");
                            body.Value += "<br><br><br>";
                        }
                        else
                        {
                            body.Value += "\n\n\n";
                            body.Value += dr["us_signature"].ToString();
                            body.Value += "\n\n\n";
                        }
                    }


                    if (Request["quote"] != null)
                    {
                        Regex    regex = new Regex("\n");
                        string[] lines = regex.Split((string)dr["bp_comment"]);

                        if (dr["bp_type"].ToString() == "received")
                        {
                            if (User.Identity.GetUseFCKEditor())
                            {
                                body.Value += "<br><br><br>";
                                body.Value += "&#62;From: " + dr["bp_email_from"].ToString().Replace("<", "&#60;").Replace(">", "&#62;") + "<br>";
                            }
                            else
                            {
                                body.Value += "\n\n\n";
                                body.Value += ">From: " + dr["bp_email_from"] + "\n";
                            }
                        }

                        bool next_line_is_date = false;
                        for (int i = 0; i < lines.Length; i++)
                        {
                            if (i < 4 && (lines[i].IndexOf("To:") == 0 || lines[i].IndexOf("Cc:") == 0))
                            {
                                next_line_is_date = true;
                                if (User.Identity.GetUseFCKEditor())
                                {
                                    body.Value += "&#62;" + lines[i].Replace("<", "&#60;").Replace(">", "&#62;") + "<br>";
                                }
                                else
                                {
                                    body.Value += ">" + lines[i] + "\n";
                                }
                            }
                            else if (next_line_is_date)
                            {
                                next_line_is_date = false;
                                if (User.Identity.GetUseFCKEditor())
                                {
                                    body.Value += "&#62;Date: " + Convert.ToString(dr["bp_date"]) + "<br>&#62;<br>";
                                }
                                else
                                {
                                    body.Value += ">Date: " + Convert.ToString(dr["bp_date"]) + "\n>\n";
                                }
                            }
                            else
                            {
                                if (User.Identity.GetUseFCKEditor())
                                {
                                    if (Convert.ToString(dr["bp_content_type"]) != "text/html")
                                    {
                                        body.Value += "&#62;" + lines[i].Replace("<", "&#60;").Replace(">", "&#62;") + "<br>";
                                    }
                                    else
                                    {
                                        if (i == 0)
                                        {
                                            body.Value += "<hr>";
                                        }

                                        body.Value += lines[i];
                                    }
                                }
                                else
                                {
                                    body.Value += ">" + lines[i] + "\n";
                                }
                            }
                        }
                    }

                    if (reply == "forward")
                    {
                        to.Value = "";
                        //original attachments
                        //dv.RowFilter = "bp_parent = " + string_bp_id;
                        dv.RowFilter = "bp_type = 'file'";
                        foreach (DataRowView drv in dv)
                        {
                            attachments_label.InnerText = "Select attachments to forward:";
                            lstAttachments.Items.Add(new ListItem(drv["bp_file"].ToString(), drv["bp_id"].ToString()));
                        }
                    }
                }
                else if (string_bg_id != null)
                {
                    string_bg_id = btnet.Util.sanitize_integer(string_bg_id);

                    int permission_level = btnet.Bug.get_bug_permission_level(Convert.ToInt32(string_bg_id), User.Identity);
                    if (permission_level == PermissionLevel.None ||
                        permission_level == PermissionLevel.ReadOnly)
                    {
                        Response.Write("You are not allowed to edit this item");
                        Response.End();
                    }

                    sql = new SQLString(@"select
				bg_short_desc,
				bg_project,
				isnull(us_signature,'') [us_signature],
				isnull(us_email,'') [us_email],
				isnull(us_firstname,'') [us_firstname],
				isnull(us_lastname,'') [us_lastname],
				isnull(pj_pop3_email_from,'') [pj_pop3_email_from]
				from bugs
				inner join users on us_id = @us
				left outer join projects on bg_project = pj_id
				where bg_id = @bg"                );

                    sql = sql.AddParameterWithValue("us", Convert.ToString(User.Identity.GetUserId()));
                    sql = sql.AddParameterWithValue("bg", string_bg_id);

                    dr = btnet.DbUtil.get_datarow(sql);

                    load_from_dropdown(dr, false); // list the user's email first, then the project

                    back_href.HRef = "edit_bug.aspx?id=" + string_bg_id;
                    bg_id.Value    = string_bg_id;

                    if (request_to != null)
                    {
                        to.Value = request_to;
                    }

                    // Work around for a mysterious bug:
                    // http://sourceforge.net/tracker/?func=detail&aid=2815733&group_id=66812&atid=515837
                    if (btnet.Util.get_setting("StripDisplayNameFromEmailAddress", "0") == "1")
                    {
                        to.Value = Email.simplify_email_address(to.Value);
                    }

                    if (dr["us_signature"].ToString() != "")
                    {
                        if (User.Identity.GetUseFCKEditor())
                        {
                            body.Value += "<br><br><br>";
                            body.Value += dr["us_signature"].ToString().Replace("\r\n", "<br>");
                        }
                        else
                        {
                            body.Value += "\n\n\n";
                            body.Value += dr["us_signature"].ToString();
                        }
                    }
                }

                short_desc.Value = (string)dr["bg_short_desc"];

                if (string_bp_id != null || string_bg_id != null)
                {
                    subject.Value = (string)dr["bg_short_desc"]
                                    + "  (" + btnet.Util.get_setting("TrackingIdString", "DO NOT EDIT THIS:")
                                    + bg_id.Value
                                    + ")";

                    // for determining which users to show in "address book"
                    project = (int)dr["bg_project"];
                }
            }
            else
            {
                on_update();
            }
        }