Folder.php 2.2 KB
<?php

namespace Controller;


use Lib\Mail\Mail;
use Lib\Mail\MailFun;
use Model\folderSql;

/**
 * 文件夹管理
 * @author:dc
 * @time 2023/2/18 17:58
 * Class Folder
 * @package Controller
 */
class Folder extends Base {


    /**
     * 邮箱文件夹
     * @author:dc
     * @time 2023/2/18 10:58
     */
    public function lists(){
        // 查询
        $folders = db()->all(
            \Model\folderSql::all(
                $this->getEmail('id'),
                '`id`,`folder`,`pid`,`exsts`,`unseen`'
            )
        );

        // 转tree
        $folders = list_to_tree($folders);

        app()->_json($folders);
    }




    /**
     * 创建 目录
     * @author:dc
     * @time 2023/2/18 17:56
     */
    public function create(){
        $formData = app()->request(['pid','folder']);
        // 验证目录 可以输入中文英文数字
        if(empty($formData['folder']) || !preg_match("/^[\u4E00-\u9FA5A-Za-z0-9_]+$/",$formData['folder'])){
            app()->e('folder_create_name_error');
        }
        // 不为空上级
        if(!empty($formData['pid'])){
            $parent = db()->first(folderSql::first(['id'=>$formData['pid']]));
            if(!$parent || $parent['email_id'] != $this->login_email['id']){
                app()->e('folder_parent_not_fount');
            }
            if($parent['pid']){
                app()->e('folder_tree_max_two');
            }

        }

        // 判断文件夹是否存在
        $has = db()->count(folderSql::has(
            [
                'email_id'  =>  $this->login_email['id'],
                'origin_folder' =>  $formData['folder']
            ]
        ));

        if($has){
            app()->e('folder_is_exist');
        }

        // 远程创建
        $mail = new Mail();
        $mail->login($this->login_email['email'],$this->login_email['password'],$this->login_email['imap']);
        $folder = $mail->client->folderCreate($formData['folder']);






    }


    /**
     * 改名
     * @author:dc
     * @time 2023/3/3 17:40
     */
    public function rename(){

    }

    /**
     * 删除
     * @author:dc
     * @time 2023/3/3 17:38
     */
    public function delete(){

    }





}