作者 邓超

x

@@ -191,18 +191,24 @@ function sync($email_id){ @@ -191,18 +191,24 @@ function sync($email_id){
191 if(!$folders){ 191 if(!$folders){
192 return 3; 192 return 3;
193 } 193 }
194 - $folders = list_to_tree($folders); 194 +
  195 + $call = function ($email_id,$folder_id,$origin_folder) use ($mailServer){
  196 + // 同步父文件夹
  197 + $result = $mailServer->syncMail($email_id,$folder_id,$origin_folder);
  198 + _echo('同步文件夹('.$origin_folder.')邮件列表 '.(is_array($result)?count($result):'未同步'));
  199 + };
  200 +
  201 +// $folders = list_to_tree($folders);
195 foreach ($folders as $folder){ 202 foreach ($folders as $folder){
196 try { 203 try {
  204 +
  205 +
197 if(empty($folder['_child'])){ 206 if(empty($folder['_child'])){
198 - _echo('同步文件夹('.$folder['origin_folder'].')邮件列表');  
199 - // 同步父文件夹  
200 - $mailServer->syncMail($email_id,$folder['id'],$folder['origin_folder']); 207 + $call($email_id,$folder['id'],$folder['origin_folder']);
201 }else{ 208 }else{
202 foreach ($folder['_child'] as $item){ 209 foreach ($folder['_child'] as $item){
203 - _echo('同步文件夹('.$item['origin_folder'].')邮件列表');  
204 // 同步子文件夹 210 // 同步子文件夹
205 - $mailServer->syncMail($email_id,$item['id'],$item['origin_folder']); 211 + $call($email_id,$item['id'],$item['origin_folder']);
206 } 212 }
207 } 213 }
208 214
@@ -173,17 +173,17 @@ class Mail { @@ -173,17 +173,17 @@ class Mail {
173 * @param $folder_id 173 * @param $folder_id
174 * @param string $folder 174 * @param string $folder
175 * @param null|DbPool $db 175 * @param null|DbPool $db
176 - * @return bool 176 + * @return bool|array
177 * @throws \Exception 177 * @throws \Exception
178 * @author:dc 178 * @author:dc
179 * @time 2023/2/18 9:54 179 * @time 2023/2/18 9:54
180 */ 180 */
181 - public function syncMail($email_id,$folder_id,$folder='INBOX',$db = null):bool { 181 + public function syncMail($email_id,$folder_id,$folder='INBOX') {
182 if(empty($folder)){ 182 if(empty($folder)){
183 return 0; 183 return 0;
184 } 184 }
185 // _echo('正在同步文件夹:'.$folder); 185 // _echo('正在同步文件夹:'.$folder);
186 - $db = $db ? $db : db(); 186 + $db = db();
187 // 选择文件夹 187 // 选择文件夹
188 try { 188 try {
189 $status = $this->client->selectFolder($folder); 189 $status = $this->client->selectFolder($folder);
@@ -219,6 +219,7 @@ class Mail { @@ -219,6 +219,7 @@ class Mail {
219 // 219 //
220 $nu = 100; 220 $nu = 100;
221 $msgno = 1; 221 $msgno = 1;
  222 + $success_uid = [];
222 while (true){ 223 while (true){
223 224
224 // 结束操作了 225 // 结束操作了
@@ -259,7 +260,7 @@ class Mail { @@ -259,7 +260,7 @@ class Mail {
259 $blackFolder, 260 $blackFolder,
260 $db 261 $db
261 ); 262 );
262 - 263 + $success_uid = array_merge($success_uid,$uids);
263 } 264 }
264 265
265 } 266 }
@@ -272,7 +273,7 @@ class Mail { @@ -272,7 +273,7 @@ class Mail {
272 false 273 false
273 ); 274 );
274 275
275 - return true; 276 + return $success_uid;
276 277
277 } 278 }
278 279