<?php session_start();
$hostname=$_SESSION[host];
$username=$_SESSION[user];
$userpwd=$_SESSION[pwd];
if(!$mbox=@imap_open("$hostname","$username","$userpwd")){
   echo "<script>alert('登录超时，请重新登录!');history.back();</script>";
   exit;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>收取邮件</title>
<script language="javascript" src="js/checkbox.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-image: url(images/mrbg.gif);
}
-->
</style>
</head>
<body> 
<table width="575" height="104" border="0" cellpadding="0" cellspacing="0" background="images/首页(2)_5.jpg">
  <tr>
    <td width="82" height="60">&nbsp;</td>
    <td width="493">&nbsp;</td>
  </tr>
  <tr>
    <td height="32">&nbsp;</td>
    <td><span class="STYLE34"><?php echo $lmbs;?></span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="550" height="421" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center" valign="top">
		<form action="delmail.php" method="post" name="form1" id="form1">
					  <table width="454" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td><table width="550" height="50" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#D4D4D4">
                            <tr bgcolor="#CCFF33">
                              <td width="44" height="25" align="center" bgcolor="#FFECB7" class="STYLE2"><div align="center" class="STYLE1">选择</div></td>
                              <td width="115" height="25" bgcolor="#FFECB7" class="STYLE2"><div align="center" class="STYLE1 ">邮件主题</div></td>
                              <td width="127" bgcolor="#FFECB7" class="STYLE2"><div align="center" class="STYLE1 ">发件人</div></td>
                              <td width="114" bgcolor="#FFECB7" class="STYLE2"><div align="center" class="STYLE1 ">发件时间</div></td>
                              <td width="54" bgcolor="#FFECB7" class="STYLE2"><div align="center" class="STYLE1 ">大小</div></td>
                            </tr>
                            <?php
		  $check = imap_check($mbox);
		  $sum=$check->Nmsgs;
		  if($sum<=0){
		  ?>
                            <tr>
                              <td height="25" colspan="5" align="center" bgcolor="#FFFFFF">暂无邮件</td>
                            </tr>
                            <?php
		  }else{
		   if($_GET[page]=="" || is_numeric($_GET[page]==false)){
		     $page=1;
		   }else{
		     $page=$_GET[page];
		   }
		   
		   $pagesize=3;
		   if($sum%$pagesize==0){
		     $totalpage=$sum/$pagesize;
		   }else{
		     $totalpage=ceil($sum/$pagesize);
		   }
		   
		  
		   $frompage=($page-1)*$pagesize+1; //获取每页的第一条记录
		   $topage=$frompage+$pagesize;		//获取每页的最后一条记录
		   if(($sum-$topage)<0){
		     $topage=$sum+1;
		   }
		  
		  for($i=$frompage;$i<$topage;$i++){ 
		    $obj=imap_headerinfo($mbox,$i);
		  ?>
                            <tr>
                              <td height="25" bgcolor="#FFFFFF"><div align="center">
                                  <input name="<?php echo $i;?>" type="checkbox" id="<?php echo $i;?>" value="<?php echo strtotime($obj->date);?>">
                              </div></td>
                              <td height="25" bgcolor="#FFFFFF" class="STYLE1"><div align="left">&nbsp;<a href="index.php?lmbs=查看邮件&id=<?php echo $i?>" class="a1">
                                  <?php
									if(strtolower(substr($obj->Subject,0,10))==strtolower("=?gb2312?B"))
										echo base64_decode(substr($obj->Subject,11,(strlen($obj->Subject)-13)));
									elseif(strtolower(substr($obj->Subject,0,8))==strtolower("=?gbk?b?"))
										echo base64_decode(substr($obj->Subject,8,(strlen($obj->Subject)-11)));
									else
										echo $obj->Subject;

										?>
                              </a></div></td>
                              <td bgcolor="#FFFFFF" class="STYLE1"><div align="center"><?php echo ($obj->fromaddress);?></div></td>
                              <td bgcolor="#FFFFFF" class="STYLE1"><div align="center">
                                  <?php 
										   $array=getdate(strtotime($obj->date));
										   echo $array[year]."-".$array[mon]."-".$array[mday]."&nbsp;".$array[hours].":".$array[minutes];
										?>
                              </div></td>
                              <td bgcolor="#FFFFFF" class="STYLE1"><div align="center">
                                  <?php 
									   $size=$obj->Size;
										if($size>=1024)
										  {
											echo number_format(($size/1024),2)."&nbsp;KB";
										  
										  }
										  elseif($size>1024*1024)
										  {
											echo number_format(($size/(1024*1024)),2)."&nbsp;M";
										  }
										  elseif($size>1024*1024*1024)
										  {
											echo number_format(($size/(1024*1024*1024)),2)."&nbsp;G";
										  }
										  elseif($size<1024)
										  {
											echo ($size)."&nbsp;字节";
										  }
									?>
                              </div></td>
                            </tr>
                            <?php
									  }
								  ?>
    <tr>
                              <td height="25" colspan="5" align="center" bgcolor="#FFFFFF"><input name="button" type=button class="buttoncss" onClick="checkAll(form1,status)" value="全选">
&nbsp;<input type=button value="反选" class="buttoncss" onClick="switchAll(form1,status)">
&nbsp;<input type=button value="不选" class="buttoncss" onClick="uncheckAll(form1,status)"></td>
                            </tr>
                          </table>
                       <table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
                              <tr bgcolor="#EEEEEE">
                                <td width="50" align="center">
<input name="submit2" type="submit" class="buttoncss" value="删除" />
</td>
                                <td width="374" class="STYLE1"><div align="left">共有邮件&nbsp;<?php echo $sum;?>&nbsp;封&nbsp;&nbsp;每页显示&nbsp;<?php echo $pagesize;?>&nbsp;封&nbsp;(第&nbsp;<?php echo $page;?>&nbsp;页/共&nbsp;<?php echo $totalpage;?>&nbsp;页)</div></td>
                                <td width="162" class="STYLE1">
                                  <div align="right">
                                    <span class="STYLE1">
                                    <?php
								  if($page>=2){
								 ?>
                                    
                                    <?    
								  }
								 if($totalpage<=4){
								   for($j=1;$j<=$totalpage;$j++){
								  echo "<a href=index.php?lmbs=".$_GET[lmbs]."&&page=".$j." class=a1>".$j."</a>&nbsp;";
								  }
								 }else{
								  for($j=1;$j<=4;$j++){
								  echo "<a href=index.php?lmbs=".$_GET[lmbs]."&&page=".$j." class=a1>".$j."</a>&nbsp;";
								  } 
								?>
                                    
                                    <?php
			}}
			?>
                                    </span>&nbsp;&nbsp;</div></td>
                              </tr>
                            </table></td>
                        </tr>
              </table>
            </form>
		</td>
      </tr>
    </table>




<?php
imap_close($mbox);
?>
</body>
</html>
