正在显示
5 个修改的文件
包含
95 行增加
和
7 行删除
@@ -19,7 +19,8 @@ | @@ -19,7 +19,8 @@ | ||
19 | "Model\\": "model/", | 19 | "Model\\": "model/", |
20 | "Controller\\": "controller/", | 20 | "Controller\\": "controller/", |
21 | "Lib\\": "lib/", | 21 | "Lib\\": "lib/", |
22 | - "Event\\": "event/" | 22 | + "Event\\": "event/", |
23 | + "Service\\": "service/" | ||
23 | }, | 24 | }, |
24 | "files": [ | 25 | "files": [ |
25 | "config.php", | 26 | "config.php", |
@@ -524,3 +524,15 @@ function get_request_origin(){ | @@ -524,3 +524,15 @@ function get_request_origin(){ | ||
524 | } | 524 | } |
525 | return ''; | 525 | return ''; |
526 | } | 526 | } |
527 | + | ||
528 | + | ||
529 | +/** | ||
530 | + * 抛出异常 | ||
531 | + * @param string $message | ||
532 | + * @throws Exception | ||
533 | + * @author:dc | ||
534 | + * @time 2024/9/26 9:46 | ||
535 | + */ | ||
536 | +function abort(string $message = ''){ | ||
537 | + throw new Exception($message); | ||
538 | +} |
@@ -52,17 +52,18 @@ class Imap { | @@ -52,17 +52,18 @@ class Imap { | ||
52 | } | 52 | } |
53 | 53 | ||
54 | /** | 54 | /** |
55 | - * @param string $host | ||
56 | - * @param string $email | ||
57 | - * @param string $password | ||
58 | * @return Login | 55 | * @return Login |
59 | - * @throws \Exception | ||
60 | * @author:dc | 56 | * @author:dc |
61 | - * @time 2024/9/13 17:45 | 57 | + * @time 2024/9/25 18:12 |
62 | */ | 58 | */ |
63 | public function login():Login { | 59 | public function login():Login { |
64 | // 打开连接 | 60 | // 打开连接 |
61 | + try { | ||
65 | $this->client->open(); | 62 | $this->client->open(); |
63 | + }catch (\Throwable $e){ | ||
64 | + return (new Login($this)); | ||
65 | + } | ||
66 | + | ||
66 | 67 | ||
67 | //有的服务器是强制要求设置id属性 已知 163 有的服务器没有id命令 这里就不处理结果了 | 68 | //有的服务器是强制要求设置id属性 已知 163 有的服务器没有id命令 这里就不处理结果了 |
68 | $this->client->request('ID ("name" "测试本地 Client" "version" "1" "os" "测试本地" "os-version" "1.0")'); | 69 | $this->client->request('ID ("name" "测试本地 Client" "version" "1" "os" "测试本地" "os-version" "1.0")'); |
service/SyncMail.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Service; | ||
4 | + | ||
5 | +use Lib\Imap\ImapConfig; | ||
6 | +use Lib\Imap\ImapPool; | ||
7 | +use Model\emailSql; | ||
8 | + | ||
9 | +/** | ||
10 | + * 同步邮件 | ||
11 | + * @author:dc | ||
12 | + * @time 2024/9/26 9:31 | ||
13 | + * Class SyncMail | ||
14 | + * @package Service | ||
15 | + */ | ||
16 | +class SyncMail { | ||
17 | + | ||
18 | + /** | ||
19 | + * @var \Lib\Db|\Lib\DbPool | ||
20 | + */ | ||
21 | + protected $db; | ||
22 | + | ||
23 | + /** | ||
24 | + * @var \Lib\Imap\Imap | ||
25 | + */ | ||
26 | + protected $imap; | ||
27 | + | ||
28 | + /** | ||
29 | + * SyncMail constructor. | ||
30 | + * @param int|string|array $email | ||
31 | + * @throws \Exception | ||
32 | + */ | ||
33 | + public function __construct(int|string|array $email) | ||
34 | + { | ||
35 | + $this->db = db(); | ||
36 | + | ||
37 | + if(!is_array($email)){ | ||
38 | + $email = $this->db->first(emailSql::first($email)); | ||
39 | + if(!$email){ | ||
40 | + abort('未查询到邮箱'); | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + // 实例一个imap类 | ||
45 | + $this->imap = ImapPool::get( | ||
46 | + (new ImapConfig()) | ||
47 | + ->setHost($email['imap']) | ||
48 | + ->setEmail($email['email']) | ||
49 | + ->setPassword(base64_decode($email['password'])) | ||
50 | + ); | ||
51 | + | ||
52 | + | ||
53 | + } | ||
54 | + | ||
55 | + | ||
56 | + public function syncFolder(){ | ||
57 | + | ||
58 | + } | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + | ||
64 | + | ||
65 | + | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | + | ||
71 | + | ||
72 | + | ||
73 | + | ||
74 | +} |
-
请 注册 或 登录 后发表评论