正在显示
9 个修改的文件
包含
103 行增加
和
122 行删除
@@ -14,26 +14,30 @@ use Model\emailSql; | @@ -14,26 +14,30 @@ use Model\emailSql; | ||
14 | */ | 14 | */ |
15 | abstract class Base { | 15 | abstract class Base { |
16 | 16 | ||
17 | - /** | ||
18 | - * 当前登录的邮箱 | ||
19 | - * @var array[] | ||
20 | - */ | ||
21 | - protected $login_email; | ||
22 | 17 | ||
23 | /** | 18 | /** |
24 | - * 构造 | ||
25 | - * Home constructor. | 19 | + * @param string $filed |
20 | + * @return mixed|null | ||
21 | + * @throws \Lib\Err | ||
22 | + * @author:dc | ||
23 | + * @time 2023/3/10 15:15 | ||
26 | */ | 24 | */ |
27 | - public function __construct() | ||
28 | - { | ||
29 | - // 获取 当前请求的 邮箱 | ||
30 | - $this->login_email = db()->first(emailSql::firstByToken(token())); | ||
31 | - if(!$this->login_email){ | ||
32 | - app()->e('token_verify_notfound'); | 25 | + protected final function getEmails($filed='*'){ |
26 | + static $data; | ||
27 | + if(empty($data)){ | ||
28 | + $data = db()->all(emailSql::all(web_request_emails())); | ||
29 | + if(empty($data)){ | ||
30 | + app()->e('email_request_required'); | ||
31 | + } | ||
33 | } | 32 | } |
34 | 33 | ||
34 | + if($filed == '*'){ | ||
35 | + return $data; | ||
35 | } | 36 | } |
36 | 37 | ||
38 | + return array_column($data,$filed); | ||
39 | + | ||
40 | + } | ||
37 | 41 | ||
38 | 42 | ||
39 | 43 |
@@ -27,9 +27,30 @@ class Home extends Base { | @@ -27,9 +27,30 @@ class Home extends Base { | ||
27 | $page = app()->request('page',1,'intval'); | 27 | $page = app()->request('page',1,'intval'); |
28 | $page = $page ? $page : 1; | 28 | $page = $page ? $page : 1; |
29 | 29 | ||
30 | - $lists = db()->all(listsSql::lists($this->login_email['id'],$page)); | ||
31 | - | ||
32 | - app()->_json(listsPage($lists,100,1,30)); | 30 | + $size = app()->request('size',20,'intval'); |
31 | + $size = $size ? $size : 1; | ||
32 | + | ||
33 | + // 邮件文件夹的id | ||
34 | + $folder_id = app()->request('folder_id'); | ||
35 | + | ||
36 | + $lists = db()->all( | ||
37 | + listsSql::lists( | ||
38 | + $this->getEmails('id'), | ||
39 | + $page, | ||
40 | + $size, | ||
41 | + (int) $folder_id | ||
42 | + ) | ||
43 | + ); | ||
44 | + | ||
45 | + // 总数 | ||
46 | + $total = db()->count( | ||
47 | + listsSql::listCount( | ||
48 | + $this->getEmails('id'), | ||
49 | + (int) $folder_id | ||
50 | + ) | ||
51 | + ); | ||
52 | + | ||
53 | + app()->_json(listsPage($lists,$total,$page,$size)); | ||
33 | 54 | ||
34 | } | 55 | } |
35 | 56 | ||
@@ -57,29 +78,8 @@ class Home extends Base { | @@ -57,29 +78,8 @@ class Home extends Base { | ||
57 | * @time 2023/3/10 10:38 | 78 | * @time 2023/3/10 10:38 |
58 | */ | 79 | */ |
59 | public function sync(){ | 80 | public function sync(){ |
60 | - $emails = app()->request('emails'); | ||
61 | - if (empty($emails)){ | ||
62 | - $tokens = app()->request('tokens'); | ||
63 | - $tokens = is_array($tokens) ? $tokens : [$tokens]; | ||
64 | - foreach ($tokens as $k=>$token){ | ||
65 | - if(!preg_match('/^[0-9a-zA-Z]{32}$/',$token)){ | ||
66 | - unset($tokens[$k]); | ||
67 | - } | ||
68 | - } | ||
69 | - if(!empty($tokens)){ | ||
70 | - $where['token'] = array_values($tokens); | ||
71 | - } | ||
72 | - }else{ | ||
73 | - $emails = is_array($emails) ? $emails : [$emails]; | ||
74 | - foreach ($emails as $k=>$email){ | ||
75 | - if(!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)){ | ||
76 | - unset($emails[$k]); | ||
77 | - } | ||
78 | - } | ||
79 | - if(!empty($emails)){ | ||
80 | - $where['email'] = array_values($emails); | ||
81 | - } | ||
82 | - } | 81 | + |
82 | + $where['email'] = web_request_emails(); | ||
83 | 83 | ||
84 | if(empty($where)){ | 84 | if(empty($where)){ |
85 | app()->e('sync_request_param_error'); | 85 | app()->e('sync_request_param_error'); |
@@ -61,8 +61,6 @@ class Login { | @@ -61,8 +61,6 @@ class Login { | ||
61 | 'smtp' => $formData['smtp'], | 61 | 'smtp' => $formData['smtp'], |
62 | 'status' => 1, | 62 | 'status' => 1, |
63 | 'pwd_error' => 0, | 63 | 'pwd_error' => 0, |
64 | - 'name' => '', | ||
65 | - 'token' => md5($formData['email'].$formData['password'].$formData['imap']), | ||
66 | ]; | 64 | ]; |
67 | 65 | ||
68 | if($id){ | 66 | if($id){ |
@@ -178,18 +178,26 @@ function dbUpdate(array $data):string { | @@ -178,18 +178,26 @@ function dbUpdate(array $data):string { | ||
178 | 178 | ||
179 | 179 | ||
180 | /** | 180 | /** |
181 | - * 获取token | ||
182 | - * @return string | 181 | + * 获取前端提交过来的邮箱 |
182 | + * @return array | ||
183 | + * @throws \Lib\Err | ||
183 | * @author:dc | 184 | * @author:dc |
184 | - * @time 2023/2/17 14:24 | 185 | + * @time 2023/3/10 14:57 |
185 | */ | 186 | */ |
186 | -function token():string { | ||
187 | - $toekn = app()->request('_token_'); | 187 | +function web_request_emails():array { |
188 | + $emails = app()->request('emails'); | ||
189 | + $emails = is_array($emails) ? $emails : [$emails]; | ||
190 | + foreach ($emails as $k=>$email){ | ||
191 | + if(!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)){ | ||
192 | + unset($emails[$k]); | ||
193 | + } | ||
194 | + } | ||
188 | 195 | ||
189 | - if(!preg_match("/^[a-z0-9]{32}$/",$toekn)){ | ||
190 | - app()->e('token_verify_error'); | 196 | + if(empty($emails)){ |
197 | + app()->e('email_request_required'); | ||
191 | } | 198 | } |
192 | - return $toekn; | 199 | + |
200 | + return array_values($emails); | ||
193 | } | 201 | } |
194 | 202 | ||
195 | 203 |
@@ -9,6 +9,7 @@ return [ | @@ -9,6 +9,7 @@ return [ | ||
9 | 'route_not_found' => '页面不存在', | 9 | 'route_not_found' => '页面不存在', |
10 | 10 | ||
11 | 'email_verify_error' => '邮箱验证失败', | 11 | 'email_verify_error' => '邮箱验证失败', |
12 | + 'email_request_required' => '邮箱必须', | ||
12 | 'password_verify_error' => '密码必须', | 13 | 'password_verify_error' => '密码必须', |
13 | 'imap_verify_error' => 'imap服务器地址错误', | 14 | 'imap_verify_error' => 'imap服务器地址错误', |
14 | 'smtp_verify_error' => 'smtp服务器地址错误', | 15 | 'smtp_verify_error' => 'smtp服务器地址错误', |
@@ -24,20 +24,6 @@ class emailSql { | @@ -24,20 +24,6 @@ class emailSql { | ||
24 | } | 24 | } |
25 | 25 | ||
26 | 26 | ||
27 | - /** | ||
28 | - * @param $token | ||
29 | - * @return array | ||
30 | - * @author:dc | ||
31 | - * @time 2023/2/17 14:21 | ||
32 | - */ | ||
33 | - public static function firstByToken($token):array { | ||
34 | - return [ | ||
35 | - "select * from `".static::$table."` where `token` = ? limit 1", | ||
36 | - [ | ||
37 | - $token | ||
38 | - ] | ||
39 | - ]; | ||
40 | - } | ||
41 | 27 | ||
42 | /** | 28 | /** |
43 | * 统计邮箱的数量 | 29 | * 统计邮箱的数量 |
@@ -79,6 +65,17 @@ class emailSql { | @@ -79,6 +65,17 @@ class emailSql { | ||
79 | } | 65 | } |
80 | 66 | ||
81 | 67 | ||
68 | + /** | ||
69 | + * 通过邮箱查询列表 | ||
70 | + * @param $emails | ||
71 | + * @return string | ||
72 | + * @author:dc | ||
73 | + * @time 2023/3/10 15:02 | ||
74 | + */ | ||
75 | + public static function all($emails){ | ||
76 | + return "select * from ".static::$table." where ".dbWhere(['email'=>$emails]); | ||
77 | + } | ||
78 | + | ||
82 | 79 | ||
83 | 80 | ||
84 | } | 81 | } |
@@ -20,20 +20,37 @@ class listsSql { | @@ -20,20 +20,37 @@ class listsSql { | ||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * 查询列表 | 22 | * 查询列表 |
23 | - * @param $email_id | ||
24 | - * @param $p | 23 | + * @param int|array $email_id |
24 | + * @param int $p | ||
25 | + * @param int $size | ||
25 | * @param int $folder_id | 26 | * @param int $folder_id |
26 | * @return string | 27 | * @return string |
27 | * @author:dc | 28 | * @author:dc |
28 | - * @time 2023/2/17 14:42 | 29 | + * @time 2023/3/10 15:24 |
29 | */ | 30 | */ |
30 | - public static function lists($email_id, $p, $folder_id = null){ | 31 | + public static function lists(int|array $email_id, int $p, int $size, int $folder_id = 0){ |
31 | 32 | ||
32 | $where = ['email_id'=>$email_id]; | 33 | $where = ['email_id'=>$email_id]; |
33 | if($folder_id) $where['folder_id'] = $folder_id; | 34 | if($folder_id) $where['folder_id'] = $folder_id; |
34 | 35 | ||
35 | - return "select * from `".static::$table."` where ".dbWhere($where)." order by `udate` desc limit 30 offset ".(($p-1)*30); | 36 | + $filed = '`id`,`uid`,`msgno`,`subject`,`from`,`to`,`date`,`size`,`recent`,`flagged`,`answered`,`deleted`,`seen`,`draft`,`udate`,`folder_id`,`is_file`,`cc`,`bcc`'; |
37 | + | ||
38 | + return "select {$filed} from `".static::$table."` where ".dbWhere($where)." order by `udate` desc limit {$size} offset ".(($p-1)*30); | ||
39 | + | ||
40 | + } | ||
36 | 41 | ||
42 | + /** | ||
43 | + * 统计列表 | ||
44 | + * @param int|array $email_id | ||
45 | + * @param int $folder_id | ||
46 | + * @return string | ||
47 | + * @author:dc | ||
48 | + * @time 2023/3/10 15:26 | ||
49 | + */ | ||
50 | + public static function listCount(int|array $email_id, int $folder_id = 0){ | ||
51 | + $where = ['email_id'=>$email_id]; | ||
52 | + if($folder_id) $where['folder_id'] = $folder_id; | ||
53 | + return "select count(*) from `".static::$table."` where ".dbWhere($where); | ||
37 | } | 54 | } |
38 | 55 | ||
39 | /** | 56 | /** |
@@ -13,65 +13,21 @@ return [ | @@ -13,65 +13,21 @@ return [ | ||
13 | '/' => [\Controller\Test::class, 'a'], | 13 | '/' => [\Controller\Test::class, 'a'], |
14 | 't' => [\Controller\Test::class, 'home'], | 14 | 't' => [\Controller\Test::class, 'home'], |
15 | 15 | ||
16 | - /** | ||
17 | - * 登录操作 | ||
18 | - * @see \Controller\Login::login() | ||
19 | - * @param string email 邮箱 | ||
20 | - * @param string password 密码 | ||
21 | - * @param string imap imap服务器地址 | ||
22 | - * @param string smtp smtp服务器地址 | ||
23 | - */ | 16 | + // 登录操作 |
24 | 'login' => [\Controller\Login::class, 'login'], | 17 | 'login' => [\Controller\Login::class, 'login'], |
25 | - | ||
26 | - /** | ||
27 | - * 邮件列表 | ||
28 | - * @see \Controller\Home::lists() | ||
29 | - * @param string _token_ token登录凭证 | ||
30 | - * @param int page 当前页数 | ||
31 | - */ | ||
32 | - 'list' => [\Controller\Home::class, 'lists'], | ||
33 | - | ||
34 | - /** | ||
35 | - * 邮件文件夹 | ||
36 | - * @see \Controller\Folder::lists() | ||
37 | - * @param string _token_ token登录凭证 | ||
38 | - */ | 18 | + // 邮件列表 |
19 | + 'lists' => [\Controller\Home::class, 'lists'], | ||
20 | +// 邮件文件夹 | ||
39 | 'folder' => [\Controller\Folder::class, 'lists'], | 21 | 'folder' => [\Controller\Folder::class, 'lists'], |
40 | - | ||
41 | - /** | ||
42 | - * 邮件/创建文件夹 | ||
43 | - * @see \Controller\Folder::create() | ||
44 | - * @param string _token_ token登录凭证 | ||
45 | - */ | 22 | +// 创建文件夹 |
46 | 'folder/create' => [\Controller\Folder::class, 'create'], | 23 | 'folder/create' => [\Controller\Folder::class, 'create'], |
47 | - | ||
48 | - /** | ||
49 | - * 邮件/重命名文件夹 | ||
50 | - * @see \Controller\Folder::rename() | ||
51 | - * @param string _token_ token登录凭证 | ||
52 | - */ | 24 | +// 重命名文件夹 |
53 | 'folder/rename' => [\Controller\Folder::class, 'rename'], | 25 | 'folder/rename' => [\Controller\Folder::class, 'rename'], |
54 | - | ||
55 | - /** | ||
56 | - * 邮件/删除文件夹 | ||
57 | - * @see \Controller\Folder::delete() | ||
58 | - * @param string _token_ token登录凭证 | ||
59 | - */ | 26 | +// 删除文件夹 |
60 | 'folder/delete' => [\Controller\Folder::class, 'delete'], | 27 | 'folder/delete' => [\Controller\Folder::class, 'delete'], |
61 | - | ||
62 | - /** | ||
63 | - * 发送邮件 | ||
64 | - * @see \Controller\Home::send_mail() | ||
65 | - * @param string _token_ token登录凭证 | ||
66 | - */ | 28 | +// 发送邮件 |
67 | 'send' => [\Controller\Home::class, 'send_mail'], | 29 | 'send' => [\Controller\Home::class, 'send_mail'], |
68 | - | ||
69 | - | ||
70 | - /** | ||
71 | - * 同步请求 | ||
72 | - * @see \Controller\Home::sync() | ||
73 | - * @param string _token_ token登录凭证 | ||
74 | - */ | 30 | +// 同步请求 |
75 | 'sync' => [\Controller\Home::class, 'sync'], | 31 | 'sync' => [\Controller\Home::class, 'sync'], |
76 | 32 | ||
77 | 33 |
-
请 注册 或 登录 后发表评论