<!--#INCLUDE FILE="../HXINCLUDE/HXINCLUDEHEAD.ASP"-->
<%
If not WS_S.ChkObjInstalled("JMail.SMTPMail") Then HX_GoBack "对不起，此服务器上没有安装jmail组件，所以不能发送E_mail！请与服务商联系！",""
ColumnName="":Tablename="HX_InternetEMail":Orderby=" where WS_USERID="&LOGINUid
WS_InternetEmail=request("WS_InternetEmail"):action=request("action"):WS_INID=request("WS_INID"):WS_BOXID=request("WS_BOXID")
select case action
  case "del" 
    if WS_INID<>"" and isnumeric(WS_INID) then
	  set boxrs=WS_S.HX_SetRSD(ColumnName,"HX_InternetEMailinbox b,HX_InternetEMail e"," where b.WS_InternetEmail=e.WS_InternetEmail and e.WS_INID="&WS_INID)
	  if boxrs.recordcount>0 then
	    conn.execute("delete * from HX_InternetEMailAttachments where WS_BOXID="&boxrs("WS_BOXID"))
		conn.execute("delete * from HX_InternetEMailinbox where WS_BOXID="&boxrs("WS_BOXID"))
      end if
	  WS_S.HX_RSClose(boxrs)
      conn.execute("delete * from HX_InternetEMail where WS_INID="&WS_INID)
      response.Redirect "internetinbox.asp"
      response.End()
    end if
  case "clear"	
    if WS_InternetEmail<>"" then
     conn.execute("delete * from HX_InternetEMailinbox where WS_InternetEmail='"&WS_InternetEmail&"'")
	end if
	 HX_GoBack "清空成功","internetinbox.asp?WS_InternetEmail="&WS_InternetEmail
    response.End()
  case "delbox"
   if WS_BOXID<>"" and isnumeric(WS_BOXID) then
      conn.execute("delete * from HX_InternetEMailinbox where WS_BOXID="&WS_BOXID)
	  conn.execute("delete * from HX_InternetEMailAttachments where WS_BOXID="&WS_BOXID)
      response.Redirect "internetinbox.asp"
      response.End()
    end if
end select	
set rs=WS_S.HX_SetRSD(ColumnName,Tablename,Orderby)
if rs.recordcount>0 then
	  sql=" where WS_USERID="&LOGINUid	  
	  if WS_InternetEmail<>"" and not isnull("WS_InternetEmail") then
	     sql=sql&" and WS_InternetEmail='"&WS_InternetEmail&"'"
	  else
	      WS_InternetEmail=rs("WS_InternetEmail")
	     sql=sql&" and WS_InternetEmail='"&WS_InternetEmail&"'"
	  end if
	  sql=sql&" order by WS_BOXID asc"	
	set brs=WS_S.HX_SetRSD(ColumnName,Tablename,Orderby&" and WS_InternetEmail='"&WS_InternetEmail&"'")
	if brs.recordcount>0 then
	   WS_InternetSendName=brs("WS_InternetSendName")
	   WS_InternetPassword=brs("WS_InternetPassword")
	   WS_InternetPOP3=brs("WS_InternetPOP3")
	end if
   if WS_InternetSendName<>"" and WS_InternetPassword<>"" and WS_InternetPOP3<>"" then		
     on error resume next 
     Set pop3 = Server.CreateObject( "JMail.POP3" )
     pop3.Connect WS_InternetSendName,WS_InternetPassword,WS_InternetPOP3
	 if err then
	   response.Write "错误:<br>·用户名或密码错误;<br>·这台机子没有连接到互联网中;<br>·服务器上的Jmail不支持收信件功能,请到官方网站上下载:http://oa.sspig.com;"
	   response.End()
	 end if
     pop3count=pop3.count
     msg="邮箱"&WS_InternetEmail&"有 <font color=FFC0FF>"&pop3count&"</font> 封信"
	 pop3.Disconnect
   end if   
   set prs=WS_S.HX_SetRSD(ColumnName,"HX_InternetEMailInbox",sql)
	msg=msg&",其中 "&(pop3count-prs.recordcount)&" 新邮件!"
	if (pop3count-prs.recordcount)>0 then 
	  msg=msg&"<a href=internetinbox.asp?action=down&WS_InternetEmail="&WS_InternetEmail&" onclick='return mysub();'><font color=red>下载新邮件</font><a>"
	end if
end if
if action="down" and WS_InternetEmail<>"" then
    on error resume next
	set brs=WS_S.HX_SetRSD(ColumnName,Tablename,Orderby&" and WS_InternetEmail='"&WS_InternetEmail&"'")
	if brs.recordcount>0 then
	   WS_InternetSendName=brs("WS_InternetSendName")
	   WS_InternetPassword=brs("WS_InternetPassword")
	   WS_InternetPOP3=brs("WS_InternetPOP3")
	end if
   if WS_InternetSendName<>"" and WS_InternetPassword<>"" and 	WS_InternetPOP3<>"" then		 
   Set pop3 = Server.CreateObject( "JMail.POP3" )
   pop3.Connect WS_InternetSendName,WS_InternetPassword,WS_InternetPOP3
   pop3count=pop3.count 
   if pop3.count>0 then   
	dim popmsg(9999)	
	if prs.recordcount>0 then WS_Date=prs("WS_Date")
	server.ScriptTimeout=9999
	For ii=1 To pop3.count	
	   Set popmsg(ii) = pop3.Messages.item(ii)
	    popmsg(ii).Silent=True
		if WS_Date<>"" and isdate(WS_Date) then 
		  if popmsg(ii).Date>=WS_Date then
		    WDate=true
		  else
		    WDate=false	
		  end if
		else
		  WDate=true
		end if				
		if WDate=true  then
		 set prs=WS_S.HX_SetRSD(ColumnName,"HX_InternetEMailInbox"," where WS_InternetEmail='"&WS_InternetEmail&"' and WS_USERID="&LOGINUid&" and WS_Subject='"&popmsg(ii).Subject&"'")
		 if prs.recordcount<=0 then
		  prs.addnew
		  prs("WS_InternetEmail")=WS_InternetEmail
		  prs("WS_USERID")=LOGINUid
		  prs("WS_Subject")=popmsg(ii).Subject
		  prs("WS_Date")=popmsg(ii).Date
		  prs("WS_From")=popmsg(ii).From
		  prs("WS_FromName")=popmsg(ii).FromName
		  prs("WS_Body")=popmsg(ii).Body
		  prs("WS_BodyText")=popmsg(ii).BodyText
		  prs("WS_DownDate")=now
		  prs.update
		  if downpath<>"" then
		    call getAttachments(prs("WS_BOXID"),ii)
		  end if
		 end if
		end if    		
    Next
	if err then
	  response.redirect "internetinbox.asp?WS_InternetEmail="&WS_InternetEmail
	  response.end
	end if
	  response.redirect "internetinbox.asp?WS_InternetEmail="&WS_InternetEmail
	  response.end
    Function getAttachments(BOXID,j)	 		
	  	Set Attachments = popmsg(j).Attachments
	  	For k = 0 To Attachments.Count - 1
		 	Set at = Attachments(k)
			if at.Name<>"" and instr(at.Name,"asp")=0 and instr(at.Name,"cer")=0  and instr(at.Name,"asa")=0 and instr(at.Name,"cdx")=0 then
   	 	       at.SaveToFile(downpath&"\"& at.Name )
			    conn.execute("insert into HX_InternetEMailAttachments(WS_BOXID,WS_Attachments,WS_AttachmentsSize) values("&BOXID&",'Emailannex/"&at.Name&"','"&at.Size&"')")
	  	    end if
		Next
	 End Function	 	
	 end if
	 pop3.Disconnect	
end if
end if
  response.Write "<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><title>邮件列表</title><link rel=stylesheet type=text/css href='../HXinclude/HX_Style.css'><script src='../HXINCLUDE/HX_function.js'></script></head><body topmargin='20' leftmargin='0' bottommargin='20'><script language='javascript'>function mysub(){if(!confirm('执行此操作，会占用大量系统资源\n需要继续吗？')){return false;}else{esave.style.visibility='visible';return true;}return true;}</script><div id='esave' style='position:absolute; top:99px; left:243px; z-index:200; visibility:hidden'><TABLE WIDTH=340 BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><td width=20% ></td><TD bgcolor=#ff0000 width='60%'><TABLE WIDTH=100% height=120 BORDER=0 CELLSPACING=1 CELLPADDING=0><TR><td bgcolor=#FFFBE8 align=center><font color=red>正在下载邮件，请稍候...</font><div align=left><font color=blue>注:如果需要下载的邮件接收时间在已下载邮件之前将不被下载,请自行删除已下载邮件或自行下载WEB服务器上邮件!</font><input name='stop' type='button' value='停止' onclick='javascript:window.opener.location.load();'></div><img src='../hximages/loading.gif'></td></tr></table></td><td width=20% ></td></tr></table></div><table width='596'  border='0' cellspacing='1' cellpadding='0' align=center bgcolor='#613c25'><tr><td colspan='2' bgcolor=FFFBE8><table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr><td height='25' background='../hximages/titleline.gif'><font class='fontmenu'>邮件账户列表</font></td></tr></table><table border='0' cellspacing='1' cellpadding='3' width='100%' align='center' bgcolor='#FFFBE8'><tr bgcolor='#3D8BBC' class=td4><td width='61%' height='25'><div align='center'>电子邮件地址</div></td><td width='39%'><div align='center'>操 作</div></td></tr>"
if rs.recordcount<=0 then
  response.write "<tr><td align=center colspan=2 bgcolor=FFFBE8>暂无电子邮件，请自行<a href='setinternetemail.asp'>创建</a></td></tr>"
else
do until rs.eof
 response.Write "<tr bgcolor='#FFFBE8'><td><div align='center'><a href='internetinbox.asp?WS_InternetEmail="&rs("WS_InternetEmail")&"'>"&rs("WS_InternetEmail")&"</a></div></td><td><div align='center'><a href='setinternetemail.asp?action=edit&WS_INID="&rs("WS_INID")&"'>配置</a> <a href='internetinbox.asp?action=del&WS_INID="&rs("WS_INID")&"'>删除</a> <a style='cursor:hand;' onclick=""javascript:if(!confirm('确认要清空"&rs("WS_InternetEmail")&"中全部本地数据吗？')) {return false;};else {location.href='internetinbox.asp?action=clear&WS_InternetEmail="&rs("WS_InternetEmail")&"';return true;} return true;"">清空邮件</a></div></td></tr>"
 rs.movenext
loop
end if
 response.Write "</table><table border='0' cellspacing='1' cellpadding='3' width='100%' align='center' bgcolor='#FFFBE8'><tr bgcolor='#3D8BBC'><td height='25' colspan='4'><table width='100%'  border='0' cellspacing='0' cellpadding='0' class=td4><tr><td>"&msg&"</td></tr></table></td></tr><tr bgcolor='#BF9B73'><td width='27%' height='25'><div align='center'>标 题</div></td><td width='30%'><div align='center'>发信人</div></td><td width='34%'><div align='center'>正 文</div></td><td width='9%'><div align='center'>操 作</div></td></tr>"
 if rs.recordcount>0 then
    set prs=WS_S.HX_SetRSD("top 10 *","HX_InternetEMailInbox",sql)
	if  prs.recordcount<=0 then	
	response.write "<tr><td align=center colspan=4 height=25 bgcolor=FFFBE8><font color=red>"&WS_InternetEmail&"</font>邮箱中没数据</td></tr>"
	else
    prs.PageSize =15 '每页记录条数
	iCount=prs.RecordCount '记录总数
	iPageSize=prs.PageSize
    	maxpage=prs.PageCount 
    	page=request("page")
    if Not IsNumeric(page) or page="" then
        page=1
    else
        page=cint(page)
    end if
    if page<1 then
        page=1
    elseif  page>maxpage then
        page=maxpage
    end if
    prs.AbsolutePage=Page
	if page=maxpage then
		x=iCount-(maxpage-1)*iPageSize
	else
		x=iPageSize
	end if
	j=0
	do while not prs.EOF
     response.Write "<tr bgcolor='#FFFBE8' onmouseover=javascript:this.bgColor='#F9F8F2' onmouseout=javascript:this.bgColor='#FFFBE8'><td><a href='javascript:' onclick=""openwin(750,550,'Viewinternetinbox.asp?WS_BOXID="&prs("WS_BOXID")&"')"">"&left(prs("WS_Subject"),10)&"</a>("&WS_S.FormatColor(WS_S.Format_Time(prs("WS_Date"),4),"808080")&")</td><td>"&prs("WS_FromName")&" ("&WS_S.FormatColor(prs("WS_From"),"808080")&") </td><td>"&left(prs("WS_body"),20)&"</td><td><div align='center'><a href='internetinbox.asp?action=delbox&WS_BOXID="&prs("WS_BOXID")&"'>删除</a></div></td></tr>" 
		   j=j+1
	       if j>=prs.PageSize then Exit Do
	       prs.movenext
           loop
          call WS_S.PageControl(iCount,maxpage,page,"border=0 align=right","<p align=right>",4)
	   end if
	  end if
response.Write "</table></td></tr></table>"
WS_S.HX_RSClose prs:WS_S.HX_RSClose rs
%>