📄 send_email.aspx
字号:
<%@ Page language="C#" validateRequest="false" %>
<!--
Copyright 2002-2005 Corey Trager
Distributed under the terms of the GNU General Public License
-->
<!-- #include file = "inc.aspx" -->
<!-- #include file = "inc_insert_bug.aspx" -->
<!-- #include file = "inc_print_bug.aspx" -->
<script language="C#" runat="server">
int id;
String sql;
DbUtil dbutil;
Security security;
///////////////////////////////////////////////////////////////////////
void Page_Load(Object sender, EventArgs e)
{
Util.do_not_cache(Response);
dbutil = new DbUtil();
security = new Security();
security.check_security(dbutil, Request, Response, Security.ANY_USER_OK);
title.InnerText = Util.get_setting("AppTitle","BugTracker.NET") + " - "
+ "send email";
msg.InnerText = "";
string string_bc_id = Request["bc_id"];
string string_bg_id = Request["bg_id"];
string request_to = Request["to"];
string request_from = Request["from"];
string reply = Request["reply"];
if (!IsPostBack)
{
if (string_bc_id != null && string_bc_id != "")
{
string_bc_id = Util.sanitize_integer(string_bc_id);
sql = @"select
bg_id,
bg_short_desc,
bc_email_from,
bc_comment,
bc_email_from,
bc_date,
us_email,
isnull(pj_pop3_email_from,'') [pj_pop3_email_from]
from bug_comments
inner join bugs on bc_bug = bg_id
inner join users on us_id = $us
left outer join projects on bg_project = pj_id
where bc_id = $id";
sql = sql.Replace("$id", string_bc_id);
sql = sql.Replace("$us", Convert.ToString(security.this_usid));
DataRow dr = dbutil.get_datarow(sql);
back_href.HRef = "edit_bug.aspx?id=" + Convert.ToString(dr["bg_id"]);
if (request_to != null)
{
to.Value = request_to;
}
else
{
to.Value = (string) dr["bc_email_from"];
}
if (request_from != null)
{
from.Value = request_from;
}
else
{
from.Value = (string) dr["pj_pop3_email_from"];
}
if (reply != null && reply == "all")
{
Regex regex = new Regex("\n");
string[] lines = regex.Split((string) dr["bc_comment"]);
string carbon = "";
string copy = "";
for (int i = 0; i < 5; i++)
{
if (lines[i].IndexOf("To:") == 0 || lines[i].IndexOf("Cc:") == 0)
{
carbon += "," + lines[i].Substring(3, lines[i].Length - 3);
}
}
carbon = carbon.Substring(1, carbon.Length - 1);
foreach (string i in carbon.Split(new char[] { ',' })) {
if (i.Trim() != String.Empty && i.IndexOf(from.Value) == -1) {
copy += i + ", ";
}
}
if (copy.Length > 2)
{
copy = copy.Substring(0, copy.Length - 2);
}
cc.Value = copy;
}
//subject.Value = (string) dr["bg_short_desc"];
bugid.Value = Convert.ToString(dr["bg_id"]);
subject.Value = (string) dr["bg_short_desc"]
+ " (DO NOT EDIT THIS:"
+ bugid.Value
+ ")";
if (Request["quote"] != null)
{
Regex regex = new Regex("\n");
string[] lines = regex.Split((string) dr["bc_comment"]);
body.Value += ">From: " + dr["bc_email_from"] + "\n";
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].IndexOf("To:") == 0 && i < 3)
{
body.Value += ">" + lines[i] + "\n";
body.Value += ">Date: " + Convert.ToString(dr["bc_date"]) + "\n>\n";
}
else
{
body.Value += ">" + lines[i] + "\n";
}
}
}
}
else if (string_bg_id != null && string_bg_id != "")
{
string_bg_id = Util.sanitize_integer(string_bg_id);
sql = @"select
bg_short_desc,
isnull(us_email,'') [us_email]
from bugs, users
where us_id = $us
and bg_id = $bg";
sql = sql.Replace("$us", Convert.ToString(security.this_usid));
sql = sql.Replace("$bg", string_bg_id);
DataRow dr = dbutil.get_datarow(sql);
back_href.HRef = "edit_bug.aspx?id=" + string_bg_id;
//Response.Write (request_to);
//Response.End();
if (request_to != null)
{
to.Value = request_to;
}
if (request_from != null)
{
from.Value = request_from;
}
else
{
from.Value = (string) dr["us_email"];
}
bugid.Value = string_bg_id;
subject.Value = (string) dr["bg_short_desc"]
+ " (DO NOT EDIT THIS:"
+ bugid.Value
+ ")";
}
}
}
///////////////////////////////////////////////////////////////////////
void Page_Unload(Object sender, EventArgs e)
{
if (dbutil != null) {dbutil.close();}
}
///////////////////////////////////////////////////////////////////////
bool validate()
{
Boolean good = true;
if (to.Value == "")
{
good = false;
to_err.InnerText = "\"To\" is required.";
}
else
{
to_err.InnerText = "";
}
if (from.Value == "")
{
good = false;
from_err.InnerText = "\"From\" is required.";
}
else
{
from_err.InnerText = "";
}
if (subject.Value == "")
{
good = false;
subject_err.InnerText = "\"Subject\" is required.";
}
else
{
subject_err.InnerText = "";
}
msg.InnerText = "Email was not sent.";
return good;
}
///////////////////////////////////////////////////////////////////////
string get_bug_text(int bugid)
{
// Get bug html
DataRow bug_dr = get_bug_datarow(bugid);
// Create a fake response and let the code
// write the html to that response
System.IO.StringWriter writer = new System.IO.StringWriter();
HttpResponse my_response = new HttpResponse(writer);
print_bug(my_response, bug_dr);
return writer.ToString();
}
///////////////////////////////////////////////////////////////////////
void on_update(object Source, EventArgs e)
{
if (!validate()) return;
sql = @"insert into bug_comments
(bc_bug, bc_user, bc_date, bc_comment, bc_email_from, bc_email_to, bc_type)
values($id, $us, getdate(), N'$cm', N'$fr', N'$to', 'sent')
select @@IDENTITY";
sql = sql.Replace("$id", bugid.Value);
sql = sql.Replace("$us", Convert.ToString(security.this_usid));
sql = sql.Replace("$cm", HttpUtility.HtmlDecode(body.Value.Replace("'", "''")));
sql = sql.Replace("$fr", from.Value.Replace("'", "''"));
sql = sql.Replace("$to", to.Value.Replace("'","''"));
int comment_id = Convert.ToInt32(dbutil.execute_scalar(sql));
string attachment = handle_attachment(comment_id);
string body_text;
System.Web.Mail.MailFormat format;
if (include_bug_cb.Checked)
{
// white space isn't handled well, I guess.
body_text = body.Value.Replace("\n","<br>");
body_text = body_text.Replace("\t"," ");
body_text = body_text.Replace(" "," ");
body_text += "<hr>" + get_bug_text(System.Convert.ToInt32(bugid.Value));
format = System.Web.Mail.MailFormat.Html;
}
else
{
body_text = HttpUtility.HtmlDecode(body.Value);
//body_text = body_text.Replace("\n","\r\n");
format = System.Web.Mail.MailFormat.Text;
}
string result = Util.send_email(
to.Value,
from.Value,
cc.Value,
subject.Value,
body_text,
format,
attachment);
send_notifications(UPDATE, Convert.ToInt32(bugid.Value),security.this_usid);
if (result == "")
{
Response.Redirect("edit_bug.aspx?id=" + bugid.Value);
}
else
{
msg.InnerText = result;
}
}
///////////////////////////////////////////////////////////////////////
string handle_attachment(int comment_id)
{
string real_filename = "";
string filename = System.IO.Path.GetFileName(attached_file.PostedFile.FileName);
if (filename == "")
{
// no attachment
return "";
}
int max_upload_size = Convert.ToInt32(Util.get_setting("MaxUploadSize","100000"));
int content_length = attached_file.PostedFile.ContentLength;
if (content_length > max_upload_size)
{
msg.InnerText = "File exceeds maximum allowed length of "
+ Convert.ToString(max_upload_size)
+ ".";
return "";
}
if (content_length == 0)
{
msg.InnerText = "No data was uploaded.";
return "";
}
string upload_folder = Util.get_setting("UploadFolder","c:\\");
if (!System.IO.Directory.Exists(upload_folder))
{
msg.InnerText = "Upload Folder does not exist on server.";
return "";
}
sql = @"insert into bug_attachments
(ba_bug, ba_file, ba_desc, ba_size, ba_uploaded_date, ba_uploaded_user, ba_comment)
values ($1, N'$2', N'$3', $4, getdate(), $5, $6)
select @@IDENTITY";
sql = sql.Replace("$1", bugid.Value);
sql = sql.Replace("$2", filename.Replace("'","''"));
sql = sql.Replace("$3", "email attachment");
sql = sql.Replace("$4", Convert.ToString(content_length));
sql = sql.Replace("$5", Convert.ToString(security.this_usid));
sql = sql.Replace("$6", Convert.ToString(comment_id));
// save the attachment's identity
int ba_id = Convert.ToInt32(dbutil.execute_scalar(sql));
real_filename = upload_folder + "\\" + bugid.Value + "_" // bug id
+ ba_id + "_" // attachment id
+ filename;
// save to disk
attached_file.PostedFile.SaveAs(real_filename);
return real_filename;
}
</script>
<html>
<head>
<title id="title" runat="server">btnet send email</title>
<link rel="StyleSheet" href="btnet.css" type="text/css">
</head>
<body>
<% security.write_menu(Response, Util.get_setting("PluralBugLabel","bugs")); %>
<div class=align><table border=0><tr><td>
<a id="back_href" runat="server" href="">back to <% Response.Write(Util.get_setting("SingularBugLabel","bug")); %></a>
<form class=frm runat="server" enctype="multipart/form-data">
<table border=0>
<tr>
<td class=lbl>To:</td>
<td><input runat="server" type=text class=txt id="to" maxlength=255 size=80></td>
<td runat="server" class=err id="to_err"> </td>
</tr>
<tr>
<td class=lbl>From:</td>
<td><input runat="server" type=text class=txt id="from" maxlength=80 size=80></td>
<td runat="server" class=err id="from_err"> </td>
</tr>
<tr>
<td class=lbl>CC:</td>
<td><input runat="server" type=text class=txt id="cc" size=80></td>
<td runat="server" class=err id="cc_err"> </td>
</tr>
<tr>
<td class=lbl>Subject:</td>
<td><input runat="server" type=text class=txt id="subject" size=80></td>
<td runat="server" class=err id="subject_err"> </td>
</tr>
<tr>
<td class=lbl>Attachment:</td>
<td><input runat="server" type=file class=txt id="attached_file" maxlength=255 size=60></td>
<td runat="server" class=err id="attached_file_err"> </td>
</tr>
<tr>
<td class=lbl> </td>
<td><input runat="server" type=checkbox class=txt id="include_bug_cb" >Include print of <% Response.Write(Util.get_setting("SingularBugLabel","Bug")); %></td>
</tr>
<tr>
<td colspan=3>
<textarea rows=15 cols=72 runat="server" class=txt id="body"></textarea>
</td>
</tr>
<tr><td colspan=3 align=left>
<span runat="server" class=err id="msg"> </span>
</td></tr>
<tr>
<td colspan=2 align=center>
<input runat="server" class=btn type=submit id="sub" value="Send" OnServerClick="on_update">
<td> </td>
</td>
</tr>
</td></tr></table>
<input type=hidden id="bugid" runat="server">
</form>
</td></tr></table></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -