作者 邓超

x

... ... @@ -64,6 +64,12 @@ class MessageItem {
*/
public Header $header;
/**
* 邮件的mime结构体
* @var string
*/
public string $bodystructure;
/**
* @var Msg
... ... @@ -189,6 +195,15 @@ class MessageItem {
}
}
/**
* @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)
... ...
... ... @@ -136,6 +136,32 @@ class Messager {
$this->item[$msgno]->size = array_shift($tokens);
break;
}
//* 1 FETCH (UID 1568602720 INTERNALDATE "16-Sep-2019 10:58:40 +0800" FLAGS (\Seen) BODYSTRUCTURE (("text" "html" ("charset" "utf-8") NIL NIL "quoted-printable" 4115 97 NIL NI
//L NIL) "mixed" ("boundary" "----=_Part_340444_1698792253.1568602720140") NIL NIL) RFC822.HEADER {816}
case 'BODYSTRUCTURE':{
$BODYSTRUCTURE = '';
$leftNum = $RightNum = 0;
foreach ($tokens as $key=>$str){
// 还有括号不对等的情况,无语了
if($str == 'RFC822.HEADER'){
break;
}
// 找出现的次数
$leftNum += substr_count($str,'(');
$RightNum += substr_count($str,')');
// 拼接起来
$BODYSTRUCTURE .= ' '.$str;
unset($tokens[$key]);
// 说明找到结束了
if($leftNum===$RightNum){
break;
}
}
$tokens = array_values($tokens);
$this->item[$msgno]->bodystructure = $BODYSTRUCTURE;
break;
}
case 'RFC822.HEADER':{
$str = trim(implode(' ',$tokens));
// 是否带有字符数数量
... ...
... ... @@ -119,7 +119,7 @@ class Msg extends Request{
public function get():Messager{
$this->folder->exec(); // 防止在其他文件夹下面
$this->cmd(
"%sFETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER)",
"%sFETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE BODYSTRUCTURE RFC822.HEADER)",
$this->isUid?'UID ':'',
implode(',',$this->number)
);
... ...