...
|
...
|
@@ -121,69 +121,84 @@ class Mail { |
|
|
// 读取所有文件夹,未解密
|
|
|
$folders = $this->client->getFolder();
|
|
|
|
|
|
// $db->transaction();
|
|
|
foreach ($folders as $folder){
|
|
|
$pid = 0;
|
|
|
$uuid = md5($email_id.$folder['folder']);
|
|
|
|
|
|
// 处理子父文件夹
|
|
|
if(str_contains($folder['folder'], '/')){
|
|
|
// 子目录
|
|
|
$folder['name'] = explode('/',$folder['parseFolder']);
|
|
|
// 查找pid
|
|
|
$pid = $db->value(folderSql::has(['uuid'=>md5($email_id.explode('/',$folder['folder'])[0])]));
|
|
|
// 去掉父目录名称
|
|
|
$folder['parseFolder'] = explode('/',$folder['parseFolder'])[1];
|
|
|
foreach ($folders as $k=>$item){
|
|
|
$pname = explode('/',$item['folder']);
|
|
|
if(count($pname)>1){
|
|
|
array_pop($pname);
|
|
|
$pname = implode('/',$pname);
|
|
|
}else{
|
|
|
$pname = '';
|
|
|
}
|
|
|
|
|
|
$folders[$k]['pname'] = $pname;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
$folder_name = '';
|
|
|
// 已发送
|
|
|
if(in_array('Send',$folder['check'])){
|
|
|
$folder_name = folderAlias('Send');
|
|
|
}
|
|
|
// 草稿
|
|
|
elseif(in_array('Drafts',$folder['check'])){
|
|
|
$folder_name = folderAlias('Drafts');
|
|
|
}
|
|
|
// 垃圾
|
|
|
elseif(in_array('Junk',$folder['check'])){
|
|
|
$folder_name = folderAlias('Junk');
|
|
|
}
|
|
|
// 回收站
|
|
|
elseif(in_array('Trash',$folder['check'])){
|
|
|
$folder_name = folderAlias('Trash');
|
|
|
}
|
|
|
$p = 0;
|
|
|
$uuids = [];
|
|
|
while ($folders){
|
|
|
foreach ($folders as $fk=>$folder){
|
|
|
$uuid = md5($email_id.$folder['folder']);
|
|
|
$uuids[$uuid] = $uuid;
|
|
|
// 查找/出现的次数
|
|
|
if (substr_count($folder['folder'],'/') == $p){
|
|
|
// 查找pid
|
|
|
$pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])]));
|
|
|
$pid = $pid ? $pid : 0;
|
|
|
// try {
|
|
|
$folder_name = '';
|
|
|
// 已发送
|
|
|
if(in_array('Send',$folder['check'])){
|
|
|
$folder_name = folderAlias('Send');
|
|
|
}
|
|
|
// 草稿
|
|
|
elseif(in_array('Drafts',$folder['check'])){
|
|
|
$folder_name = folderAlias('Drafts');
|
|
|
}
|
|
|
// 垃圾
|
|
|
elseif(in_array('Junk',$folder['check'])){
|
|
|
$folder_name = folderAlias('Junk');
|
|
|
}
|
|
|
// 回收站
|
|
|
elseif(in_array('Trash',$folder['check'])){
|
|
|
$folder_name = folderAlias('Trash');
|
|
|
}
|
|
|
|
|
|
if(!$folder_name){
|
|
|
$folder_name = folderAlias($folder['parseFolder']);
|
|
|
}
|
|
|
if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
|
|
|
$db->insert(folderSql::$table,[
|
|
|
'email_id' => $email_id,
|
|
|
'folder' => folderAlias($folder_name),
|
|
|
'origin_folder' => $folder['folder'],
|
|
|
'uuid' => $uuid,
|
|
|
'pid' => $pid
|
|
|
],false);
|
|
|
}else{
|
|
|
$db->update(folderSql::$table,[
|
|
|
'email_id' => $email_id,
|
|
|
'folder' => folderAlias($folder_name),
|
|
|
'origin_folder' => $folder['folder'],
|
|
|
'uuid' => $uuid,
|
|
|
'pid' => $pid
|
|
|
],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);
|
|
|
}
|
|
|
}catch (\Throwable $e){
|
|
|
// 这里就不处理失败了
|
|
|
}
|
|
|
if(!$folder_name){
|
|
|
$fn = explode('/',$folder['parseFolder']);
|
|
|
$folder_name = folderAlias(end($fn));
|
|
|
}
|
|
|
if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
|
|
|
$db->insert(folderSql::$table,[
|
|
|
'email_id' => $email_id,
|
|
|
'folder' => folderAlias($folder_name),
|
|
|
'origin_folder' => $folder['folder'],
|
|
|
'uuid' => $uuid,
|
|
|
'pid' => $pid
|
|
|
],false);
|
|
|
}else{
|
|
|
$db->update(folderSql::$table,[
|
|
|
'email_id' => $email_id,
|
|
|
'folder' => folderAlias($folder_name),
|
|
|
'origin_folder' => $folder['folder'],
|
|
|
'uuid' => $uuid,
|
|
|
'pid' => $pid
|
|
|
],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);
|
|
|
}
|
|
|
// }catch (\Throwable $e){
|
|
|
// 这里就不处理失败了
|
|
|
// }
|
|
|
|
|
|
unset($folders[$fk]);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
$p++;
|
|
|
}
|
|
|
|
|
|
if($uuids){
|
|
|
// 删除以前的
|
|
|
$db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$email_id]);
|
|
|
}
|
|
|
// $db->commit();
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|