<?php session_start();
$hostname=$_SESSION[host];
$username=$_SESSION[user];
$userpwd=$_SESSION[pwd];
$mbox=imap_open("$hostname","$username","$userpwd");
$check = imap_mailboxmsginfo($mbox);
$sum=$check->Unread;
for($i=1;$i<=$sum;$i++){
	$obj=imap_header($mbox,$i);
  	$array=strtotime($obj->date);
	include_once ("conn/conn.php");						//载入adodb.ini.php文件
	$sql="select * from tb_mail_read where tb_mail_time='$array'";
	$rst = $conn -> Execute($sql);	//执行pageExecute函数
	
	while(!$rst -> EOF){											//配合wihle语句循环输出结果
		$status = imap_setflag_full($mbox, $i, "\\Seen");
		$rst -> movenext();
	}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>未读邮件</title>
<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>
<script language="javascript" src="js/checkbox.js"></script>
<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="575" height="340" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center" valign="top">
					  <table width="550" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td>
	<form action="not_delmail.php" method="post" name="form1" id="form1">
<table width="550" height="50" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#D4D4D4">
                            <tr bgcolor="#CCFF33">  <td width="39" height="25" bgcolor="#FFECB7"><div align="center" class="STYLE1 style2">操作</div></td>
                              <td width="159" height="25" bgcolor="#FFECB7"><div align="center" class="STYLE1 style2">邮件主题</div></td>
                              <td width="109" bgcolor="#FFECB7"><div align="center" class="STYLE1 style2">发件人</div></td>
                              <td width="98" bgcolor="#FFECB7"><div align="center" class="STYLE1 style2">发件时间</div></td>
                              <td width="49" bgcolor="#FFECB7"><div align="center" class="STYLE1 style2">大小</div></td>
                            </tr>
                            <?php
  $check = imap_mailboxmsginfo($mbox);
		  $sum=$check->Unread;
$j=0;
		 
		  
		  for($i=1;$i<=$sum;$i++){


		    $obj=imap_header($mbox,$i);

			if($obj->Recent=="N"){
$j++;

		  ?>
                            <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;?>&tb_mail_time=<?php 
										   $array=strtotime($obj->date);
										   echo $array;
										?>
" 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
									  }
}
$_SESSION[not_mail]=$j;
  if($j<=0){
		  ?>
                            <tr>
                              <td height="25" colspan="5" align="center" bgcolor="#FFFFFF"><span class="STYLE35">暂无未邮件</span></td>
                            </tr>
                            <?php
		  }else{

							  ?>
              </table>
<table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
                              <tr bgcolor="#EEEEEE">
                                <td width="47" align="center">
<input name="submit2" type="submit" class="buttoncss" value="删除" /></td>
                                <td width="128" align="center" class="STYLE1">共有邮件&nbsp;<?php echo $j;?>&nbsp;封</td>
                                <td width="202" align="center"><input name="button" type=button class="buttoncss" onClick="checkAll(form1,status)" value="全选">
                                  <input name="button" type=button class="buttoncss" onClick="switchAll(form1,status)" value="反选">
                                  <input name="button" type=button class="buttoncss" onClick="uncheckAll(form1,status)" value="不选"></td>
                                <td width="77">
                          
                                    <?php
								}
			?>
&nbsp;</td>
                              </tr>
              </table>
</form>                          </td>
                        </tr>
          </table>		</td>
      </tr>
</table>
<?php
imap_close($mbox);
?>
</body>
</html>
