<?php namespace Lib\Imap\Parse; use Lib\Imap\Request\Msg; /** * 邮件 * @author:dc * @time 2024/9/18 11:30 * @property Body $body * @method bool seen() 标记为 已读 * @method bool unseen() 标记为 未读 * @method bool deleted() 标记为 删除 * @method bool undeleted() 标记为 取消删除 * @method bool flagged() 标记为 星标 * @method bool unflagged() 标记为 取消星标 * @method bool recent() 标记为 最近 * @method bool unrecent() 标记为 取消最近 * @method bool answered() 标记为 已回复 * @method bool unanswered() 标记为 取消已回复 * @method bool draft() 标记为 草稿 * @method bool undraft() 标记为 取消草稿 * @method bool move(string $folder,bool $utf7 = true) 移动当前邮件到指定目录 * @method bool copy(string $folder,bool $utf7 = true) 复制当前邮件到指定目录 * Class MessageItem * @package Lib\Imap\Parse */ class MessageItem { /** * 邮件的唯一id 文件夹下面唯一 * @var int */ public int $uid = 0; /** * 邮件编号 * @var int */ public int $msgno = 0; /** * 这个是邮件收到的时间 * @var string */ public string $date = ''; /** * 邮件大小 * @var int */ public int $size = 0; /** * 标记 * @var array */ public array $flags = []; /** * 头部信息 主题 发件 收件 发送时间等消息 * @var Header */ public Header $header; /** * 邮件的mime结构体 * @var string */ public string $bodystructure; /** * @var Msg */ protected Msg $msg; /** * MessageItem constructor. * @param int $msgno */ public function __construct(int $msgno, Msg $msg) { $this->msg = $msg; $this->msgno = $msgno; } /** * 是否已被标记为删除了 * @return bool * @author:dc * @time 2024/9/18 11:52 */ public function isDeleted():bool { return in_array('deleted',$this->flags); } /** * 已读 * @return bool * @author:dc * @time 2024/9/18 17:53 */ public function isSeen():bool { return in_array('seen',$this->flags); } /** * 草稿 * @return bool * @author:dc * @time 2024/9/18 17:53 */ public function isDraft():bool { return in_array('draft',$this->flags); } /** * 星标 * @return bool * @author:dc * @time 2024/9/18 17:53 */ public function isFlagged():bool { return in_array('flagged',$this->flags); } /** * 已回复 * @return bool * @author:dc * @time 2024/9/18 17:52 */ public function isAnswered():bool { return in_array('answered',$this->flags); } /** * 最近 * @return bool * @author:dc * @time 2024/9/18 17:54 */ public function isRecent():bool { return in_array('recent',$this->flags); } /** * 获取邮件体 字段 内容 * @param string $name * @return mixed * @author:dc * @time 2024/9/20 15:13 */ public function get(string $name){ return $this->header->get($name); } /** * 获取body体 * @return Body * @author:dc * @time 2024/9/20 15:14 */ public function getBody():Body { if(isset($this->body)){ return $this->body; } $this->body = $this->msg->getBody($this); return $this->body; } /** * 所属文件夹 * @return string * @author:dc * @time 2024/9/26 11:46 */ public function getFolderName():string { return $this->msg->folder->getName(); } public function __get(string $name) { if($name=='body'){ return $this->getBody(); }else{ $this->get($name); } } /** * @return bool 是否有附件 * @author:dc * @time 2024/9/29 13:58 */ public function isAttachment():bool { return stripos($this->bodystructure, '"attachment"') !== false; } public function __call(string $name, array $arguments) { switch ($name){ case 'seen':{} // 已读 case 'unseen':{} // 未读 case 'deleted':{}//删除 case 'undeleted':{}//取消删除 case 'flagged':{}//星标 case 'unflagged':{}//取消星标 case 'recent':{}//最近 case 'unrecent':{}// 取消最近 case 'answered':{} // 已回复 case 'unanswered':{}// 取消已回复 case 'draft':{}// 草稿 case 'undraft':{}//取消草稿 case 'move':{}//移动当前邮件到指定目录 case 'copy':{return $this->msg->uid($this->uid)->{$name}(...$arguments);}//移动当前邮件到指定目录 default:{ throw new \Exception('未定义函数 '.$name); } } } }