作者 邓超

1

@@ -46,13 +46,15 @@ class Folder extends Base { @@ -46,13 +46,15 @@ class Folder extends Base {
46 * @time 2023/2/18 17:56 46 * @time 2023/2/18 17:56
47 */ 47 */
48 public function create(){ 48 public function create(){
49 - $email = $this->getEmail('id'); 49 + $email = $this->getEmail();
50 50
51 $formData = app()->request(['pid','folder']); 51 $formData = app()->request(['pid','folder']);
52 // 验证目录 可以输入中文英文数字 52 // 验证目录 可以输入中文英文数字
53 if(empty($formData['folder'])){ 53 if(empty($formData['folder'])){
54 app()->e('folder_create_name_error'); 54 app()->e('folder_create_name_error');
55 } 55 }
  56 + // 加密后的文件夹
  57 + $origin_folder = MailFun::folderEncoding($formData['folder']);
56 // 不为空上级 58 // 不为空上级
57 if(!empty($formData['pid'])){ 59 if(!empty($formData['pid'])){
58 $parent = db()->first(folderSql::first(['id'=>$formData['pid']])); 60 $parent = db()->first(folderSql::first(['id'=>$formData['pid']]));
@@ -63,6 +65,8 @@ class Folder extends Base { @@ -63,6 +65,8 @@ class Folder extends Base {
63 app()->e('folder_tree_max_two'); 65 app()->e('folder_tree_max_two');
64 } 66 }
65 67
  68 + // 加密后的文件夹
  69 + $origin_folder = $parent['origin_folder'].'/'.$origin_folder;
66 } 70 }
67 71
68 $formData['folder'] = str_replace(["'",'"','/','\\','&','*','(',')'],'',$formData['folder']); 72 $formData['folder'] = str_replace(["'",'"','/','\\','&','*','(',')'],'',$formData['folder']);
@@ -71,7 +75,7 @@ class Folder extends Base { @@ -71,7 +75,7 @@ class Folder extends Base {
71 $has = db()->count(folderSql::has( 75 $has = db()->count(folderSql::has(
72 [ 76 [
73 'email_id' => $email['id'], 77 'email_id' => $email['id'],
74 - 'origin_folder' => MailFun::folderEncoding($formData['folder']) 78 + 'origin_folder' => $origin_folder
75 ] 79 ]
76 )); 80 ));
77 81
@@ -90,15 +94,28 @@ class Folder extends Base { @@ -90,15 +94,28 @@ class Folder extends Base {
90 app()->e('login_error_imap'); 94 app()->e('login_error_imap');
91 } 95 }
92 96
  97 + // 远程创建
  98 + $ret = $mail->client->folderCreate($origin_folder);
93 99
  100 + if($ret[0] === false){
  101 + app()->e($ret[1]);
  102 + }
94 103
  104 + // 插入数据
  105 + $id = db()->insert(folderSql::$table,[
  106 + 'pid' => $parent['id']??0,
  107 + 'email_id' => $email['id'],
  108 + 'folder' => $formData['folder'],
  109 + 'origin_folder' => $origin_folder,
  110 + 'uuid' => md5($email['id'].$origin_folder),
  111 + ]);
95 112
96 - $folder = $mail->client->folderCreate($formData['folder']);  
97 -  
98 -  
99 -  
100 - 113 + if(!$id){
  114 + app()->e('folder_create_save_error');
  115 + }
101 116
  117 + // 返回数据
  118 + app()->_json(db()->first(folderSql::first($id)));
102 119
103 } 120 }
104 121
@@ -26,6 +26,7 @@ return [ @@ -26,6 +26,7 @@ return [
26 'folder_parent_not_fount' => '上级文件夹不存在', 26 'folder_parent_not_fount' => '上级文件夹不存在',
27 'folder_tree_max_two' => '文件夹最多2级', 27 'folder_tree_max_two' => '文件夹最多2级',
28 'folder_is_exist' => '文件夹已存在', 28 'folder_is_exist' => '文件夹已存在',
  29 + 'folder_create_save_error' => '文件夹新增失败',
29 30
30 'sync_request_param_error' => '同步请求参数异常', 31 'sync_request_param_error' => '同步请求参数异常',
31 32
@@ -430,23 +430,23 @@ class Imap { @@ -430,23 +430,23 @@ class Imap {
430 * 创建文件夹 430 * 创建文件夹
431 * $folder 目录 创建二级目录用/ a/b 431 * $folder 目录 创建二级目录用/ a/b
432 * @param string $folder 432 * @param string $folder
433 - * @return string 433 + * @return array
434 * @throws \Exception 434 * @throws \Exception
435 * @author:dc 435 * @author:dc
436 - * @time 2022/11/24 23:35 436 + * @time 2023/3/14 11:37
437 */ 437 */
438 - public function folderCreate(string $folder):string { 438 + public function folderCreate(string $folder):array {
439 // 需要转码 439 // 需要转码
440 - $folder = MailFun::folderEncoding($folder); 440 +// $folder = MailFun::folderEncoding($folder);
441 // A003 CREATE owatagusiam 顶级 441 // A003 CREATE owatagusiam 顶级
442 // A003 CREATE owatagusiam/owatagusiam2 有上下级关系的文件夹 442 // A003 CREATE owatagusiam/owatagusiam2 有上下级关系的文件夹
443 $res = $this->request("CREATE \"{$folder}\""); 443 $res = $this->request("CREATE \"{$folder}\"");
444 444
445 if ($res[0] == 'ok'){ 445 if ($res[0] == 'ok'){
446 - return $folder; 446 + return [true,$folder];
447 } 447 }
448 448
449 - throw new \Exception('create folder error:'.end($res[1])); 449 + return [false,end($res[1])];
450 450
451 } 451 }
452 452
@@ -38,12 +38,13 @@ class folderSql { @@ -38,12 +38,13 @@ class folderSql {
38 38
39 /** 39 /**
40 * 查询一条完整的数据 40 * 查询一条完整的数据
41 - * @param $where 41 + * @param array|string $where
42 * @return string 42 * @return string
43 * @author:dc 43 * @author:dc
44 - * @time 2023/2/20 16:39 44 + * @time 2023/3/14 11:49
45 */ 45 */
46 - public static function first($where):string { 46 + public static function first(array|string $where):string {
  47 + $where = is_numeric($where) ? ['id'=>$where] : $where;
47 return "select * from `".self::$table."` where ".dbWhere($where); 48 return "select * from `".self::$table."` where ".dbWhere($where);
48 } 49 }
49 50