正在显示
10 个修改的文件
包含
190 行增加
和
87 行删除
@@ -298,7 +298,7 @@ switch ($argv[1]){ | @@ -298,7 +298,7 @@ switch ($argv[1]){ | ||
298 | } | 298 | } |
299 | case 'stop':{ | 299 | case 'stop':{ |
300 | \Co\run(function (){ | 300 | \Co\run(function (){ |
301 | - echo "正在退出程序...\n"; | 301 | + echo "正在退出程序...\n非必要请不要强制kill掉进程\n"; |
302 | redis()->set(RUNNING_REDIS_KEY,'stop'); | 302 | redis()->set(RUNNING_REDIS_KEY,'stop'); |
303 | while (true){ | 303 | while (true){ |
304 | $num = exec("ps -ef | grep \"sync_email.php start\" | grep -v grep | wc -l"); | 304 | $num = exec("ps -ef | grep \"sync_email.php start\" | grep -v grep | wc -l"); |
controller/Base.php
0 → 100644
@@ -2,7 +2,6 @@ | @@ -2,7 +2,6 @@ | ||
2 | 2 | ||
3 | namespace Controller; | 3 | namespace Controller; |
4 | 4 | ||
5 | -use Lib\Mail\Mail; | ||
6 | use Model\emailSql; | 5 | use Model\emailSql; |
7 | use Model\listsSql; | 6 | use Model\listsSql; |
8 | 7 | ||
@@ -14,106 +13,62 @@ use Model\listsSql; | @@ -14,106 +13,62 @@ use Model\listsSql; | ||
14 | */ | 13 | */ |
15 | class Home { | 14 | class Home { |
16 | 15 | ||
17 | - | ||
18 | /** | 16 | /** |
19 | - * 登录操作 | ||
20 | - * @return int[] | ||
21 | - * @author:dc | ||
22 | - * @time 2023/2/13 11:50 | 17 | + * 当前登录的邮箱 |
18 | + * @var array[] | ||
23 | */ | 19 | */ |
24 | - public function login(){ | ||
25 | - // $mail,$password,$imap,$smtp | ||
26 | - $formData = app()->request(['email','password','imap','smtp']); | ||
27 | - | ||
28 | - if(empty($formData['email']) || !preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$formData['email'])){ | ||
29 | - app()->e('email_verify_error'); | ||
30 | - } | 20 | + private $login_email; |
31 | 21 | ||
32 | - if(empty($formData['password'])){ | ||
33 | - app()->e('password_verify_error'); | ||
34 | - } | ||
35 | - | ||
36 | - if(empty($formData['imap'])){ | ||
37 | - app()->e('imap_verify_error'); | ||
38 | - } | ||
39 | - | ||
40 | - if(empty($formData['smtp'])){ | ||
41 | - app()->e('smtp_verify_error'); | ||
42 | - } | ||
43 | - | ||
44 | - // 进行远程登录,验证 | ||
45 | - Mail::login($formData['email'],$formData['password'],$formData['imap']); | ||
46 | - | ||
47 | - // 是否存在 | ||
48 | - $id = db()->value(emailSql::hasEmail($formData['email'])); | ||
49 | - | ||
50 | - $data = [ | ||
51 | - 'password' => base64_encode($formData['password']), | ||
52 | - 'imap' => $formData['imap'], | ||
53 | - 'smtp' => $formData['smtp'], | ||
54 | - 'status' => 1, | ||
55 | - 'pwd_error' => 0, | ||
56 | - 'name' => '', | ||
57 | - 'token' => md5($formData['email'].$formData['password'].$formData['imap']), | ||
58 | - ]; | ||
59 | - | ||
60 | - if($id){ | ||
61 | - // 修改 | ||
62 | - $ret = db()->update(emailSql::$table,$data,dbWhere(['id'=>$id])); | ||
63 | - }else{ | ||
64 | - // 新增 | ||
65 | - $ret = db()->insert(emailSql::$table,$data); | ||
66 | - | ||
67 | - if($ret){ | ||
68 | - // 增加邮件数量 | ||
69 | - redis()->incr('email_total'); | ||
70 | - // 立即处理 同步 | ||
71 | - redis()->lPush('sync_email_lists', $ret); | ||
72 | - } | ||
73 | - | ||
74 | - } | ||
75 | - | ||
76 | - | ||
77 | - if($ret){ | ||
78 | - app()->_json([ | ||
79 | - 'token' => $data['token'] | ||
80 | - ]); | 22 | + /** |
23 | + * 构造 | ||
24 | + * Home constructor. | ||
25 | + */ | ||
26 | + public function __construct() | ||
27 | + { | ||
28 | + // 获取 当前请求的 邮箱 | ||
29 | + $this->login_email = db()->first(emailSql::firstByToken(token())); | ||
30 | + if(!$this->login_email){ | ||
31 | + app()->e('token_verify_notfound'); | ||
81 | } | 32 | } |
82 | 33 | ||
83 | - app()->e('login_error'); | ||
84 | - | ||
85 | - | ||
86 | } | 34 | } |
87 | 35 | ||
88 | - | ||
89 | /** | 36 | /** |
90 | * 邮件列表 | 37 | * 邮件列表 |
91 | * @author:dc | 38 | * @author:dc |
92 | * @time 2023/2/17 14:12 | 39 | * @time 2023/2/17 14:12 |
93 | */ | 40 | */ |
94 | public function lists(){ | 41 | public function lists(){ |
95 | - $email = db()->first(emailSql::firstByToken(token())); | ||
96 | - if(!$email){ | ||
97 | - app()->e('token_verify_notfound'); | ||
98 | - } | ||
99 | 42 | ||
100 | // 分页 页数 | 43 | // 分页 页数 |
101 | $page = app()->request('page',1,'intval'); | 44 | $page = app()->request('page',1,'intval'); |
102 | $page = $page ? $page : 1; | 45 | $page = $page ? $page : 1; |
103 | 46 | ||
104 | - $lists = db()->all(listsSql::lists($email['id'],$page)); | 47 | + $lists = db()->all(listsSql::lists($this->login_email['id'],$page)); |
105 | 48 | ||
106 | app()->_json(listsPage($lists,100,1,30)); | 49 | app()->_json(listsPage($lists,100,1,30)); |
107 | 50 | ||
108 | } | 51 | } |
109 | 52 | ||
53 | + | ||
110 | /** | 54 | /** |
111 | * 邮箱文件夹 | 55 | * 邮箱文件夹 |
112 | * @author:dc | 56 | * @author:dc |
113 | * @time 2023/2/18 10:58 | 57 | * @time 2023/2/18 10:58 |
114 | */ | 58 | */ |
115 | public function folder(){ | 59 | public function folder(){ |
116 | - | 60 | + // 查询 |
61 | + $folders = db()->all( | ||
62 | + \Model\folderSql::all( | ||
63 | + $this->login_email['id'], | ||
64 | + '`id`,`folder`,`pid`' | ||
65 | + ) | ||
66 | + ); | ||
67 | + | ||
68 | + // 转tree | ||
69 | + $folders = list_to_tree($folders); | ||
70 | + | ||
71 | + app()->_json($folders); | ||
117 | } | 72 | } |
118 | 73 | ||
119 | 74 |
controller/Login.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Controller; | ||
4 | + | ||
5 | +use Lib\Mail\Mail; | ||
6 | +use Model\emailSql; | ||
7 | + | ||
8 | + | ||
9 | +/** | ||
10 | + * 登录 | ||
11 | + * @author:dc | ||
12 | + * @time 2023/2/18 16:49 | ||
13 | + * Class Login | ||
14 | + * @package Controller | ||
15 | + */ | ||
16 | +class Login { | ||
17 | + | ||
18 | + | ||
19 | + /** | ||
20 | + * 登录操作 | ||
21 | + * @return int[] | ||
22 | + * @author:dc | ||
23 | + * @time 2023/2/13 11:50 | ||
24 | + */ | ||
25 | + public function login(){ | ||
26 | + // $mail,$password,$imap,$smtp | ||
27 | + $formData = app()->request(['email','password','imap','smtp']); | ||
28 | + | ||
29 | + if(empty($formData['email']) || !preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$formData['email'])){ | ||
30 | + app()->e('email_verify_error'); | ||
31 | + } | ||
32 | + | ||
33 | + if(empty($formData['password'])){ | ||
34 | + app()->e('password_verify_error'); | ||
35 | + } | ||
36 | + | ||
37 | + if(empty($formData['imap'])){ | ||
38 | + app()->e('imap_verify_error'); | ||
39 | + } | ||
40 | + | ||
41 | + if(empty($formData['smtp'])){ | ||
42 | + app()->e('smtp_verify_error'); | ||
43 | + } | ||
44 | + | ||
45 | + // 进行远程登录,验证 | ||
46 | + (new Mail())->login($formData['email'],$formData['password'],$formData['imap']); | ||
47 | + | ||
48 | + // 是否存在 | ||
49 | + $id = db()->value(emailSql::hasEmail($formData['email'])); | ||
50 | + | ||
51 | + $data = [ | ||
52 | + 'password' => base64_encode($formData['password']), | ||
53 | + 'imap' => $formData['imap'], | ||
54 | + 'smtp' => $formData['smtp'], | ||
55 | + 'status' => 1, | ||
56 | + 'pwd_error' => 0, | ||
57 | + 'name' => '', | ||
58 | + 'token' => md5($formData['email'].$formData['password'].$formData['imap']), | ||
59 | + ]; | ||
60 | + | ||
61 | + if($id){ | ||
62 | + // 修改 | ||
63 | + $ret = db()->update(emailSql::$table,$data,dbWhere(['id'=>$id])); | ||
64 | + }else{ | ||
65 | + // 新增 | ||
66 | + $ret = db()->insert(emailSql::$table,$data); | ||
67 | + | ||
68 | + if($ret){ | ||
69 | + // 增加邮件数量 | ||
70 | + redis()->incr('email_total'); | ||
71 | + // 立即处理 同步 | ||
72 | + redis()->lPush('sync_email_lists', $ret); | ||
73 | + } | ||
74 | + | ||
75 | + } | ||
76 | + | ||
77 | + | ||
78 | + if($ret){ | ||
79 | + app()->_json([ | ||
80 | + 'token' => $data['token'] | ||
81 | + ]); | ||
82 | + } | ||
83 | + | ||
84 | + app()->e('login_error'); | ||
85 | + | ||
86 | + | ||
87 | + } | ||
88 | + | ||
89 | + | ||
90 | + | ||
91 | + | ||
92 | + | ||
93 | + | ||
94 | + | ||
95 | +} | ||
96 | + | ||
97 | + | ||
98 | + | ||
99 | + | ||
100 | + | ||
101 | + | ||
102 | + | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | + |
@@ -20,8 +20,8 @@ class folderSql { | @@ -20,8 +20,8 @@ class folderSql { | ||
20 | * @author:dc | 20 | * @author:dc |
21 | * @time 2023/2/18 9:22 | 21 | * @time 2023/2/18 9:22 |
22 | */ | 22 | */ |
23 | - public static function all(int $email_id):string { | ||
24 | - return "select `id`,`folder`,`pid`,`origin_folder`,`last_sync_time`,`folder` from `".static::$table."` where `email_id` = {$email_id} order by `id` asc"; | 23 | + public static function all(int $email_id, $field = '`id`,`folder`,`pid`,`origin_folder`,`last_sync_time`'):string { |
24 | + return "select {$field} from `".static::$table."` where `email_id` = {$email_id} order by `id` asc"; | ||
25 | } | 25 | } |
26 | 26 | ||
27 | 27 |
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | -use Controller\Home; | ||
4 | - | ||
5 | 3 | ||
4 | +/** | ||
5 | + * todo::只有post请求 | ||
6 | + */ | ||
6 | return [ | 7 | return [ |
7 | 8 | ||
8 | - /** 登录操作 @see Home::login() **/ | ||
9 | - 'login' => [Home::class,'login'], | 9 | + /** |
10 | + * 登录操作 | ||
11 | + * @see \Controller\Login::login() | ||
12 | + * @param string email 邮箱 | ||
13 | + * @param string password 密码 | ||
14 | + * @param string imap imap服务器地址 | ||
15 | + * @param string smtp smtp服务器地址 | ||
16 | + */ | ||
17 | + 'login' => [\Controller\Login::class,'login'], | ||
10 | 18 | ||
11 | - /** 邮件列表 @see Home::lists() **/ | ||
12 | - 'mail/list' => [Home::class,'lists'], | 19 | + /** |
20 | + * 邮件列表 | ||
21 | + * @see \Controller\Home::lists() | ||
22 | + * @param string _token_ token登录凭证 | ||
23 | + * @param int page 当前页数 | ||
24 | + */ | ||
25 | + 'mail/list' => [\Controller\Home::class,'lists'], | ||
13 | 26 | ||
14 | - /** 邮件文件夹 @see Home::folder() **/ | ||
15 | - 'mail/folder' => [Home::class,'folder'], | 27 | + /** |
28 | + * 邮件文件夹 | ||
29 | + * @see \Controller\Home::folder() | ||
30 | + * @param string _token_ token登录凭证 | ||
31 | + */ | ||
32 | + 'mail/folder' => [\Controller\Home::class,'folder'], | ||
16 | 33 | ||
17 | ]; | 34 | ]; |
-
请 注册 或 登录 后发表评论