<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
server.ScriptTimeout =240
If session("EmailAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("id")="" Then
	ef=True
	ec="请输入产品ID！"
ElseIf not IsNumeric(Request.Form ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf not IsNumeric(Request.Form ("size"))  Then
	ef=True
	ec="单个邮箱大小应该是数字！"
ElseIf Request.Form ("size")<1  Then
	ef=True
	ec="单个邮箱大小不能小于1M！"
ElseIf Request.Form ("size")>4000  Then
	ef=True
	ec="单个邮箱大小不能大于4000M！"
ElseIf len(Request.Form ("email"))<3  Then
	ef=True
	ec="邮箱名长度必须大于3！"
ElseIf Request.Form ("del")="add" and trim(Request.Form ("password"))="" Then
	ef=True
	ec="密码没填写！"
ElseIf lcase(trim(Request.Form ("email")))="postmaster" or lcase(trim(Request.Form ("email")))="root" Then
	ef=True
	ec="不能操作此邮箱名。"
ElseIf not IsNumeric(Request.Form ("oldsize"))  Then
	ef=True
	ec="旧大小应该是数字！"
ElseIf  RegExpTest("[^A-Za-z0-9]",Request.Form ("password")) Then
	ef=True
	ec="密码不能有特殊字符！"
ElseIf Request.Form ("password")="123456" or Request.Form ("password")="888888" Then
	ef=True
	ec="密码过于简单(不能小于6位数)！"
ElseIf Request.Form ("password")<>"" And len(Request.Form ("password"))<6 Then
	ef=True
	ec="密码过于简单(不能小于6位数)！"
ElseIf  RegExpTest("[^A-Za-z0-9\.\-\_]",Request.Form ("email")) Then
	ef=True
	ec="邮箱名不能有特殊字符！"
end if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsph = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Product_Email where id='"&session("EmailAUID")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,1
if dsph.Eof then
	ef=True
	ec="不存在的邮箱产品ID！"
end if
end if

if not ef then
	Set dspdl = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_EmailProductlist where Emailtype='"&dsph ("Emailtype")&"'"
		dspdl.Open Sql,conn,1,1
If dspdl.Eof Then
	ef=True
	ec="不存在的邮箱产品类型！"
end if
end if

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serveremaillist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
else
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
end if
end If

if not ef then
if dsserver("softtype")="WebEasyMail" And lcase(trim(Request.Form ("email")))="admin" Then
	ef=True
	ec="邮箱软件限制,不能操作此邮箱名。"
end If
end If

if not ef then
Set dspdallemail = Server.CreateObject("ADODB.Recordset")	
Sql="Select top 1 * from FreeHost.FreeHost_Product_ALLEmail where PdEID='"&dsph ("id")&"' and emailname is not null"
		dspdallemail.Open Sql,conn,1,3
if dspdallemail.Eof then
	ef=True
	ec="管理邮箱不存在！请先绑定域。"
end if
end if

if not ef then
email=trim(dspdallemail("emailname"))
emailarry=split(email,"@")
name1=emailarry(0)
domain=lcase(trim(emailarry(1)))

if Request.Form ("size")<>Request.Form ("oldsize") Then

if dsserver("softtype")="Imail" then
regpath=domain&"\users"
key="MaxSize"
domainsize=replace(Regimailop(URL,FreeHostsharekey,domain,key,keyvalue,1),"操作成功，数值为：","")/1024/1024

'if domainsize=0 then domainsize=dspdl("domainspacelimt")'2008-当imail超过4G的域

if domainsize=0 Then
domainsize=dspdl("domainspacelimt")'2008-当imail超过4G的域
If Not IsNull(dsph("domainspacelimt")) Then domainsize=dsph("domainspacelimt")'2008-当imail超过4G的域
End if

'Response.Write domainsize

'list all
sizeall=0
regpath=domain&"\users"
op=5'1,r nun,2 w num,3 r str,4 w str,5 list
returnstr=Regimailop(URL,FreeHostsharekey,regpath,key,keyvalue,op)
arrystr=split(replace(replace(returnstr,"操作成功：",""),"_aliases@",""),"@")
for idformail=0 to ubound(arrystr)
arrystr(idformail)=replace(arrystr(idformail),vbcrlf,"")
if len(arrystr(idformail))>0 and arrystr(idformail)<>"root" and arrystr(idformail)<>trim(lcase(Request.Form ("email"))) then
regpath=domain&"\users\"&arrystr(idformail)
key="MaxSize"
retvlue=replace(Regimailop(URL,FreeHostsharekey,regpath,key,keyvalue,1),"操作成功，数值为：","")
if retvlue=0 then
regpath=domain
key="MaxRcv"
retvlue=replace(Regimailop(URL,FreeHostsharekey,regpath,key,keyvalue,1),"操作成功，数值为：","")
'Response.Write retvlue
end if
returnstr=round(retvlue/1024/1024,1)
sizeall=sizeall+returnstr
end if
next
if (sizeall+Request.Form ("size"))>domainsize then
	ef=True
	ec="您设置的邮箱总大小超出了这个域所允许的总大小。"
end if

else'winwebmail
sizeall=0
admname=dsserver("admname")
admpass=dsserver("admpass")
returnstr=ListDomainmail(URL,FreeHostsharekey,admname,admpass,domain)
returnstr=replace(returnstr,"授权通过 ","")
arrystrSize=split(returnstr,"#")
domainmaxuser=arrystrSize(1)
domainsize=round(arrystrSize(2)/1024,1)
arrystr=split(arrystrSize(0),"$")
for idformail=0 to ubound(arrystr)
arryemail=split(arrystr(idformail),"|")
if len(arrystr(idformail))>0 then
if trim(lcase(Request.Form ("email")))&"@"&domain<>arryemail(0) then
sizeall=sizeall+round(arryemail(1)/1024,1)
end if
end if
next

if (sizeall+Request.Form ("size"))>domainsize then
	ef=True
	ec="您设置的邮箱总大小超出了这个域所允许的总大小。"
end if

end if'end check size


end if
end if

if not ef then
if Request.Form ("del")="yes" and trim(lcase(Request.Form ("email")))=lcase(trim(name1)) Then
	ef=True
	ec="域管理员不能删除。"
end if
end if

if not ef then

if dsserver("softtype")="Imail" then
if Request.Form ("del")="no" Then
if Request.Form ("password")<>"" Then
tem=ChpassEmail(dsph ("ServerlistID"),lcase(Request.Form ("email")),domain,Request.Form ("password"))
'Response.Write tem
end if

if Request.Form ("size")<>Request.Form ("oldsize") Then
regpath=domain&"\users\"&trim(lcase(Request.Form ("email")))
key="MaxSize"
keyvalue=Request.Form ("size")*1024*1024
retvlue=Regimailop(URL,FreeHostsharekey,regpath,key,keyvalue,2)
'Response.Write retvlue
end if

ElseIf Request.Form ("del")="yes" Then

retvlue=DelEmail(dsph ("ServerlistID"),lcase(Request.Form ("email"))&"@"&domain)

ElseIf Request.Form ("del")="add" Then
keyvalue=Request.Form ("size")*1024
retvlue=AddEmail(dsph ("ServerlistID"),lcase(Request.Form ("email"))&"@"&domain,Request.Form ("password"),keyvalue)
regpath=domain&"\users\"&trim(lcase(Request.Form ("email")))
key="MaxSize"
keyvalue=Request.Form ("size")*1024*1024
retvlue2=Regimailop(URL,FreeHostsharekey,regpath,key,keyvalue,2)'2008
end if

else

If Request.Form ("del")="add" Then
retvlue=AddEmail(dsph ("ServerlistID"),lcase(Request.Form ("email"))&"@"&domain,Request.Form ("password"),Request.Form ("size")*1024)
end if
If Request.Form ("del")="yes" Then
retvlue=DelEmail(dsph ("ServerlistID"),lcase(Request.Form ("email"))&"@"&domain)
end if

if Request.Form ("del")="no" Then
if Request.Form ("password")<>"" Then
tem=ChpassEmail(dsph ("ServerlistID"),lcase(Request.Form ("email")),domain,Request.Form ("password"))
end if
if Request.Form ("size")<>Request.Form ("oldsize") Then
dim websize
websize=Request.Form ("size")*1024
tem=ChpassEmail(dsph ("ServerlistID"),lcase(Request.Form ("email")),domain,Request.Form ("password"))
end if
end if

end if




end if

if not ef then%>
<!--#include virtual="/inc-freehost-function/template-emailadm-top.asp"--> 邮箱管理

<br>
<br>
保存成功：<%=tem%>　<%=retvlue%> <br><br>
<br>
<br>
　<a href="adm.asp?id=<%=Request("id")%>"><font color="#000000">[返回]</font></a>
<!--#include virtual="/inc-freehost-function/template-emailadm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>