作者 邓超

1

... ... @@ -46,13 +46,15 @@ class Folder extends Base {
* @time 2023/2/18 17:56
*/
public function create(){
$email = $this->getEmail('id');
$email = $this->getEmail();
$formData = app()->request(['pid','folder']);
// 验证目录 可以输入中文英文数字
if(empty($formData['folder'])){
app()->e('folder_create_name_error');
}
// 加密后的文件夹
$origin_folder = MailFun::folderEncoding($formData['folder']);
// 不为空上级
if(!empty($formData['pid'])){
$parent = db()->first(folderSql::first(['id'=>$formData['pid']]));
... ... @@ -63,6 +65,8 @@ class Folder extends Base {
app()->e('folder_tree_max_two');
}
// 加密后的文件夹
$origin_folder = $parent['origin_folder'].'/'.$origin_folder;
}
$formData['folder'] = str_replace(["'",'"','/','\\','&','*','(',')'],'',$formData['folder']);
... ... @@ -71,7 +75,7 @@ class Folder extends Base {
$has = db()->count(folderSql::has(
[
'email_id' => $email['id'],
'origin_folder' => MailFun::folderEncoding($formData['folder'])
'origin_folder' => $origin_folder
]
));
... ... @@ -90,15 +94,28 @@ class Folder extends Base {
app()->e('login_error_imap');
}
// 远程创建
$ret = $mail->client->folderCreate($origin_folder);
if($ret[0] === false){
app()->e($ret[1]);
}
// 插入数据
$id = db()->insert(folderSql::$table,[
'pid' => $parent['id']??0,
'email_id' => $email['id'],
'folder' => $formData['folder'],
'origin_folder' => $origin_folder,
'uuid' => md5($email['id'].$origin_folder),
]);
if(!$id){
app()->e('folder_create_save_error');
}
$folder = $mail->client->folderCreate($formData['folder']);
// 返回数据
app()->_json(db()->first(folderSql::first($id)));
}
... ...
... ... @@ -26,6 +26,7 @@ return [
'folder_parent_not_fount' => '上级文件夹不存在',
'folder_tree_max_two' => '文件夹最多2级',
'folder_is_exist' => '文件夹已存在',
'folder_create_save_error' => '文件夹新增失败',
'sync_request_param_error' => '同步请求参数异常',
... ...
... ... @@ -430,23 +430,23 @@ class Imap {
* 创建文件夹
* $folder 目录 创建二级目录用/ a/b
* @param string $folder
* @return string
* @return array
* @throws \Exception
* @author:dc
* @time 2022/11/24 23:35
* @time 2023/3/14 11:37
*/
public function folderCreate(string $folder):string {
public function folderCreate(string $folder):array {
// 需要转码
$folder = MailFun::folderEncoding($folder);
// $folder = MailFun::folderEncoding($folder);
// A003 CREATE owatagusiam 顶级
// A003 CREATE owatagusiam/owatagusiam2 有上下级关系的文件夹
$res = $this->request("CREATE \"{$folder}\"");
if ($res[0] == 'ok'){
return $folder;
return [true,$folder];
}
throw new \Exception('create folder error:'.end($res[1]));
return [false,end($res[1])];
}
... ...
... ... @@ -38,12 +38,13 @@ class folderSql {
/**
* 查询一条完整的数据
* @param $where
* @param array|string $where
* @return string
* @author:dc
* @time 2023/2/20 16:39
* @time 2023/3/14 11:49
*/
public static function first($where):string {
public static function first(array|string $where):string {
$where = is_numeric($where) ? ['id'=>$where] : $where;
return "select * from `".self::$table."` where ".dbWhere($where);
}
... ...