作者 邓超

x

... ... @@ -191,18 +191,24 @@ function sync($email_id){
if(!$folders){
return 3;
}
$folders = list_to_tree($folders);
$call = function ($email_id,$folder_id,$origin_folder) use ($mailServer){
// 同步父文件夹
$result = $mailServer->syncMail($email_id,$folder_id,$origin_folder);
_echo('同步文件夹('.$origin_folder.')邮件列表 '.(is_array($result)?count($result):'未同步'));
};
// $folders = list_to_tree($folders);
foreach ($folders as $folder){
try {
if(empty($folder['_child'])){
_echo('同步文件夹('.$folder['origin_folder'].')邮件列表');
// 同步父文件夹
$mailServer->syncMail($email_id,$folder['id'],$folder['origin_folder']);
$call($email_id,$folder['id'],$folder['origin_folder']);
}else{
foreach ($folder['_child'] as $item){
_echo('同步文件夹('.$item['origin_folder'].')邮件列表');
// 同步子文件夹
$mailServer->syncMail($email_id,$item['id'],$item['origin_folder']);
$call($email_id,$item['id'],$item['origin_folder']);
}
}
... ...
... ... @@ -173,17 +173,17 @@ class Mail {
* @param $folder_id
* @param string $folder
* @param null|DbPool $db
* @return bool
* @return bool|array
* @throws \Exception
* @author:dc
* @time 2023/2/18 9:54
*/
public function syncMail($email_id,$folder_id,$folder='INBOX',$db = null):bool {
public function syncMail($email_id,$folder_id,$folder='INBOX') {
if(empty($folder)){
return 0;
}
// _echo('正在同步文件夹:'.$folder);
$db = $db ? $db : db();
$db = db();
// 选择文件夹
try {
$status = $this->client->selectFolder($folder);
... ... @@ -219,6 +219,7 @@ class Mail {
//
$nu = 100;
$msgno = 1;
$success_uid = [];
while (true){
// 结束操作了
... ... @@ -259,7 +260,7 @@ class Mail {
$blackFolder,
$db
);
$success_uid = array_merge($success_uid,$uids);
}
}
... ... @@ -272,7 +273,7 @@ class Mail {
false
);
return true;
return $success_uid;
}
... ...