作者 邓超

m

... ... @@ -19,7 +19,8 @@
"Model\\": "model/",
"Controller\\": "controller/",
"Lib\\": "lib/",
"Event\\": "event/"
"Event\\": "event/",
"Service\\": "service/"
},
"files": [
"config.php",
... ...
... ... @@ -524,3 +524,15 @@ function get_request_origin(){
}
return '';
}
/**
* 抛出异常
* @param string $message
* @throws Exception
* @author:dc
* @time 2024/9/26 9:46
*/
function abort(string $message = ''){
throw new Exception($message);
}
\ No newline at end of file
... ...
... ... @@ -52,17 +52,18 @@ class Imap {
}
/**
* @param string $host
* @param string $email
* @param string $password
* @return Login
* @throws \Exception
* @author:dc
* @time 2024/9/13 17:45
* @time 2024/9/25 18:12
*/
public function login():Login {
// 打开连接
$this->client->open();
try {
$this->client->open();
}catch (\Throwable $e){
return (new Login($this));
}
//有的服务器是强制要求设置id属性 已知 163 有的服务器没有id命令 这里就不处理结果了
$this->client->request('ID ("name" "测试本地 Client" "version" "1" "os" "测试本地" "os-version" "1.0")');
... ...
... ... @@ -45,7 +45,7 @@ class ImapClient {
);
if($error){
throw new \Exception("socket error: {$error}");
throw new \Exception($error);
}
if (!$this->socket) {
... ...
<?php
namespace Service;
use Lib\Imap\ImapConfig;
use Lib\Imap\ImapPool;
use Model\emailSql;
/**
* 同步邮件
* @author:dc
* @time 2024/9/26 9:31
* Class SyncMail
* @package Service
*/
class SyncMail {
/**
* @var \Lib\Db|\Lib\DbPool
*/
protected $db;
/**
* @var \Lib\Imap\Imap
*/
protected $imap;
/**
* SyncMail constructor.
* @param int|string|array $email
* @throws \Exception
*/
public function __construct(int|string|array $email)
{
$this->db = db();
if(!is_array($email)){
$email = $this->db->first(emailSql::first($email));
if(!$email){
abort('未查询到邮箱');
}
}
// 实例一个imap类
$this->imap = ImapPool::get(
(new ImapConfig())
->setHost($email['imap'])
->setEmail($email['email'])
->setPassword(base64_decode($email['password']))
);
}
public function syncFolder(){
}
}
\ No newline at end of file
... ...