//移动邮件到指定分组
function move_mails($msglist,$mailbox)
{
if(!$this->marubox)
return false;
imap_mail_move($this->marubox,$msglist,$mailbox);
}
function creat_mailbox($mailbox)
{
if(!$this->marubox)
return false;
//imap_renamemailbox($imap_stream,$old_mbox,$new_mbox);
imap_create($this->marubox,$mailbox);
}
/*
- decode_mime()转换邮件标题的字符编码,处理乱码
*/
function decode_mime($str){
$str=imap_mime_header_decode($str);
return $str[0]->text;
echo "str";print_r($str);
if ($str[0]->charset!="default")
{echo "==".$str[0]->text;
return iconv($str[0]->charset,$str[0]->text);
}
else
{
return $str[0]->text;
}
}
/**
- Set path name of the uploaded file to be saved.
-
- @param int $fileID
- @param string $extension
- @access public
- @return string
*/
public function setPathName($fileID,$extension)
{
return date('Ym/dHis',time()) . $fileID . mt_rand(0,10000) . '.' . $extension;
}
}
?>
3.控制层./mailreceived/mailControl.php
./mailreceived/mailControl.php 内容如下:
public function __construct()
{
$this->now = date("Y-m-d H:i:s",time());
$this->setSavePath();
}
/**
- mail Received()读取收件箱邮件
-
- @param
- @access public
- @return result
*/
public function mailReceived()
{
// Creating a object of reciveMail Class
$obj= new receivemail($this->mailAccount,$this->mailPasswd,$this->mailAddress,$this->mailServer,$this->serverType,$this->port,false);
//Connect to the Mail Box
$res=$obj->connect(); //If connection fails give error message and exit
if (!$res)
{
return array("msg"=>"Error: Connecting to mail server");
}
// Get Total Number of Unread Email in mail box
$tot=$obj->getTotalMails(); //Total Mails in Inbox Return integer value
if($tot < 1) { //如果信件数为0,显示信息
return array("msg"=>"No Message for ".$this->mailAccount);
}
else
{
$res=array("msg"=>"Total Mails:: $tot<br>");
for($i=$tot;$i>0;$i--)
{
$head=$obj->getHeaders($i); // Get Header Info Return Array Of Headers **Array Keys are (subject,to,toOth,toNameOth,from,fromName)
//处理邮件附件
$files=$obj->GetAttach($i,$this->savePath); // 获取邮件附件,返回的邮件附件信息数组
$imageList=array();
foreach($files as $k => $file)
{
//type=1为附件,0为邮件内容图片
if($file['type'] == 0)
{
$imageList[$file['title']]=$file['pathname'];
}
}
$body = $obj->getBody($i,$this->webPath,$imageList);
$res['mail'][]=array('head'=>$head,'body'=>$body,"attachList"=>$files);
// $obj->deleteMails($i); // Delete Mail from Mail box
// $obj->move_mails($i,"taskMail");
}
$obj->close_mailbox(); //Close Mail Box
return $res;
}
}
/**
- creatBox
-
- @access public
- @return void
*/
public function creatBox($boxName)
{
// Creating a object of reciveMail Class
$obj= new receivemail($this->mailAccount,false);
$obj->creat_mailbox($boxName);
}
(编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|