正在显示
3 个修改的文件
包含
42 行增加
和
1 行删除
@@ -64,6 +64,12 @@ class MessageItem { | @@ -64,6 +64,12 @@ class MessageItem { | ||
64 | */ | 64 | */ |
65 | public Header $header; | 65 | public Header $header; |
66 | 66 | ||
67 | + /** | ||
68 | + * 邮件的mime结构体 | ||
69 | + * @var string | ||
70 | + */ | ||
71 | + public string $bodystructure; | ||
72 | + | ||
67 | 73 | ||
68 | /** | 74 | /** |
69 | * @var Msg | 75 | * @var Msg |
@@ -189,6 +195,15 @@ class MessageItem { | @@ -189,6 +195,15 @@ class MessageItem { | ||
189 | } | 195 | } |
190 | } | 196 | } |
191 | 197 | ||
198 | + /** | ||
199 | + * @return bool 是否有附件 | ||
200 | + * @author:dc | ||
201 | + * @time 2024/9/29 13:58 | ||
202 | + */ | ||
203 | + public function isAttachment():bool { | ||
204 | + return stripos($this->bodystructure, '"attachment"') !== false; | ||
205 | + } | ||
206 | + | ||
192 | 207 | ||
193 | 208 | ||
194 | public function __call(string $name, array $arguments) | 209 | public function __call(string $name, array $arguments) |
@@ -136,6 +136,32 @@ class Messager { | @@ -136,6 +136,32 @@ class Messager { | ||
136 | $this->item[$msgno]->size = array_shift($tokens); | 136 | $this->item[$msgno]->size = array_shift($tokens); |
137 | break; | 137 | break; |
138 | } | 138 | } |
139 | + //* 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 | ||
140 | + //L NIL) "mixed" ("boundary" "----=_Part_340444_1698792253.1568602720140") NIL NIL) RFC822.HEADER {816} | ||
141 | + case 'BODYSTRUCTURE':{ | ||
142 | + $BODYSTRUCTURE = ''; | ||
143 | + $leftNum = $RightNum = 0; | ||
144 | + foreach ($tokens as $key=>$str){ | ||
145 | + // 还有括号不对等的情况,无语了 | ||
146 | + if($str == 'RFC822.HEADER'){ | ||
147 | + break; | ||
148 | + } | ||
149 | + // 找出现的次数 | ||
150 | + $leftNum += substr_count($str,'('); | ||
151 | + $RightNum += substr_count($str,')'); | ||
152 | + // 拼接起来 | ||
153 | + $BODYSTRUCTURE .= ' '.$str; | ||
154 | + unset($tokens[$key]); | ||
155 | + // 说明找到结束了 | ||
156 | + if($leftNum===$RightNum){ | ||
157 | + break; | ||
158 | + } | ||
159 | + } | ||
160 | + $tokens = array_values($tokens); | ||
161 | + | ||
162 | + $this->item[$msgno]->bodystructure = $BODYSTRUCTURE; | ||
163 | + break; | ||
164 | + } | ||
139 | case 'RFC822.HEADER':{ | 165 | case 'RFC822.HEADER':{ |
140 | $str = trim(implode(' ',$tokens)); | 166 | $str = trim(implode(' ',$tokens)); |
141 | // 是否带有字符数数量 | 167 | // 是否带有字符数数量 |
@@ -119,7 +119,7 @@ class Msg extends Request{ | @@ -119,7 +119,7 @@ class Msg extends Request{ | ||
119 | public function get():Messager{ | 119 | public function get():Messager{ |
120 | $this->folder->exec(); // 防止在其他文件夹下面 | 120 | $this->folder->exec(); // 防止在其他文件夹下面 |
121 | $this->cmd( | 121 | $this->cmd( |
122 | - "%sFETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER)", | 122 | + "%sFETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE BODYSTRUCTURE RFC822.HEADER)", |
123 | $this->isUid?'UID ':'', | 123 | $this->isUid?'UID ':'', |
124 | implode(',',$this->number) | 124 | implode(',',$this->number) |
125 | ); | 125 | ); |
-
请 注册 或 登录 后发表评论