作者 邓超

1

... ... @@ -5,6 +5,7 @@ namespace Controller;
use Lib\Mail\MailFun;
use Model\emailSql;
use Model\listsSql;
use function Swoole\Coroutine\Http\request;
/**
* @author:dc
... ... @@ -50,6 +51,50 @@ class Home extends Base {
}
/**
* 收到前端的同步请求操作
* @author:dc
* @time 2023/3/10 10:38
*/
public function sync(){
$emails = app()->request('emails');
if (empty($emails)){
$tokens = app()->request('tokens');
$tokens = is_array($tokens) ? $tokens : [$tokens];
foreach ($tokens as $k=>$token){
if(!preg_match('/^[0-9a-zA-Z]{32}$/',$token)){
unset($tokens[$k]);
}
}
if(!empty($tokens)){
$where['token'] = array_values($tokens);
}
}else{
$emails = is_array($emails) ? $emails : [$emails];
foreach ($emails as $k=>$email){
if(!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)){
unset($emails[$k]);
}
}
if(!empty($emails)){
$where['email'] = array_values($emails);
}
}
if(empty($where)){
app()->e('sync_request_param_error');
}else{
// 查询id
$ids = db()->all(emailSql::getValues($where));
foreach ($ids as $v){
redis()->rPush('sync_email_lists', $v['id']);
}
// 返回成功的参数值
app()->_json(array_values($where));
}
}
... ...
... ... @@ -258,7 +258,7 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em
* @author:dc
* @time 2023/2/18 11:04
*/
function start_now_mail($email=null){
function start_now_mail(){
$id = 0;
while (true){
... ...
... ... @@ -25,4 +25,6 @@ return [
'folder_tree_max_two' => '文件夹最多2级',
'folder_is_exist' => '文件夹已存在',
'sync_request_param_error' => '同步请求参数异常',
];
\ No newline at end of file
... ...
... ... @@ -66,6 +66,17 @@ class emailSql {
];
}
/**
* 获取字段值
* @param $where
* @param string $field
* @return string
* @author:dc
* @time 2023/3/10 10:46
*/
public static function getValues($where,$field='id'){
return "select `{$field}` from `".static::$table."` where ".dbWhere($where);
}
... ...
... ... @@ -29,42 +29,53 @@ return [
* @param string _token_ token登录凭证
* @param int page 当前页数
*/
'mail/list' => [\Controller\Home::class, 'lists'],
'list' => [\Controller\Home::class, 'lists'],
/**
* 邮件文件夹
* @see \Controller\Folder::lists()
* @param string _token_ token登录凭证
*/
'mail/folder' => [\Controller\Folder::class, 'lists'],
'folder' => [\Controller\Folder::class, 'lists'],
/**
* 邮件/创建文件夹
* @see \Controller\Folder::create()
* @param string _token_ token登录凭证
*/
'mail/folder/create' => [\Controller\Folder::class, 'create'],
'folder/create' => [\Controller\Folder::class, 'create'],
/**
* 邮件/重命名文件夹
* @see \Controller\Folder::rename()
* @param string _token_ token登录凭证
*/
'mail/folder/rename' => [\Controller\Folder::class, 'rename'],
'folder/rename' => [\Controller\Folder::class, 'rename'],
/**
* 邮件/删除文件夹
* @see \Controller\Folder::delete()
* @param string _token_ token登录凭证
*/
'mail/folder/delete' => [\Controller\Folder::class, 'delete'],
'folder/delete' => [\Controller\Folder::class, 'delete'],
/**
* 发送邮件
* @see \Controller\Home::send_mail()
* @param string _token_ token登录凭证
*/
'mail/send' => [\Controller\Home::class, 'send_mail'],
'send' => [\Controller\Home::class, 'send_mail'],
/**
* 同步请求
* @see \Controller\Home::sync()
* @param string _token_ token登录凭证
*/
'sync' => [\Controller\Home::class, 'sync'],
];
... ...