<?php session_start();
$hostname=$_SESSION[host];
$username=$_SESSION[user];
$userpwd=$_SESSION[pwd];
$mbox=imap_open("$hostname","$username","$userpwd");
$id=$_GET[id];
$tb_mail_time=$_GET[tb_mail_time];

include_once("conn/conn.php");
$sqlstr = 'select * from tb_mail_read where tb_mail_read_id = 0';		//生成sql语句
	/*执行SQL语句 */
	$rst = $conn -> execute($sqlstr) or die('Error: '.$conn -> errorMsg()) ;
	$fields = array();										//创建一个数组
	$fields['tb_mail_id'] = $id;						//向数组中添加数据
	$fields['tb_mail_time'] = $tb_mail_time;						//向数组中添加数据
	/*添加新数据*/
	$insert = $conn -> getInsertSQL($rst,$fields) or die('update error：'.$conn -> errorMsg());
	$conn -> execute($insert);

imap_setflag_full($mbox, $id, "\\Seen");

$obj=imap_header($mbox,$id);
?>
<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>
<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">
<table width="550" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#C6C5CA">
                                      <tr>
                                        <td width="63" height="26" align="center" bgcolor="#FFFFFF">时&nbsp;&nbsp;间：</td>
                                        <td align="left" bgcolor="#FFFFFF" class="STYLE1">&nbsp;&nbsp;
                                            <?php $array=@getdate(strtotime($obj->date));
			   echo $array[year]."-".$array[mon]."-".$array[mday]."&nbsp;".$array[hours].":".$array[minutes].":".$array[seconds];?></td>
                                      </tr>
                                      <tr>
                                        <td height="26" align="center" bgcolor="#FFFFFF">发件人：</td>
                                        <td height="24" align="left" bgcolor="#FFFFFF" class="STYLE1">&nbsp;&nbsp;&nbsp;<?php echo $obj->fromaddress;?></td>
                                      </tr>
                                      <tr>
                                        <td height="26" align="center" bgcolor="#FFFFFF">收件人：</td>
                                        <td height="24" align="left" bgcolor="#FFFFFF" class="STYLE1">&nbsp;&nbsp;&nbsp;<?php echo $obj->toaddress;?></td>
                                      </tr>
                                      <tr>
                                        <td height="26" align="center" bgcolor="#FFFFFF">主&nbsp;&nbsp;题：</td>
                                        <td height="24" align="left" bgcolor="#FFFFFF" class="STYLE1">&nbsp;&nbsp;
                                           <?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;

										?>


                                    </td>
                                      </tr>
                                      <?php
		    $body=@imap_fetchbody($mbox,$id,2);
			if($body!=""){  
		  ?>
                                      <tr>
                                        <td height="26" align="center" bgcolor="#FFFFFF">附&nbsp;&nbsp;件：</td>
                                        <td height="24" align="left" bgcolor="#FFFFFF">
                                          <table height="26" border="0" align="center" cellpadding="0" cellspacing="0">
                                            <tr>
                                              <td width="225" height="26">&nbsp;&nbsp;
                                                  <?php
		        $structure= @imap_fetchstructure($mbox,$id); 
		        $array=$structure->parts;
		        if(($array[1]->dparameters[0]->value)!=""){
                   $filename=$array[1]->dparameters[0]->value;
                }else{
                    $filename=$array[1]->description;
                 }


if(strtolower(substr($filename,0,10))==strtolower("=?gb2312?B"))
	echo base64_decode(substr($filename,11,(strlen($filename)-13)));
elseif(strtolower(substr($filename,0,8))==strtolower("=?gbk?b?"))
	echo base64_decode(substr($filename,8,(strlen($filename)-11)));
else
	echo $filename;
		        ?>
                                              </td>
                                              <td width="82">&nbsp;</td>
                                              <td width="61"><a href="down.php?id=<?php echo $id;?>" class="a1">(下载附件)</a></td>
                                            </tr>
                                        </table></td>
                                      </tr>
                                      <?php
		   }
		  ?>
          </table>
								  <table width="550" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#C6C5CA">
                              <tr>
                                <td height="300" align="center" valign="top" bgcolor="#FFFFFF">

<?php
 
  if(imap_base64(@imap_fetchbody($mbox,$id,1))==""){
    echo @imap_fetchbody($mbox,$id,1);
  }else{
    echo imap_base64(imap_fetchbody($mbox,$id,1)); 
  }
  
?>                                </td>
                              </tr>
</table>
		</td>
      </tr>
    </table>
</body>
</html>
