作者 邓超

x

... ... @@ -16,8 +16,8 @@ return [
'server_error' => '服务器异常',
'email_server_error' => '请检查imap,smtp服务是否开启/密码是否正确',
'email_smtp_server_error' => 'SMTP:连接邮件服务器失败,请检查邮件服务器地址是否正确',
'email_server_error' => '请检查imap/smtp的服务地址是否正确',
'email_smtp_server_error' => 'SMTP:连接邮件服务器失败',
'login_error' => '登录失败',
'login_error_imap' => '登录失败,请检查密码是否正确或者是否开启imap/smtp服务',
... ...
... ... @@ -44,7 +44,7 @@ class SyncMail {
* @param int|string|array $email
* @throws \Exception
*/
public function __construct(int|string|array $email)
public function __construct(int|string|array $email,\Lib\Imap\Imap|null $imap = null)
{
$this->db = db();
... ... @@ -56,16 +56,20 @@ class SyncMail {
}
$this->email = $email;
// 实例一个imap类
$this->imap = ImapPool::get(
(new ImapConfig())
->setHost($email['imap'])
->setEmail($email['email'])
->setPassword(base64_decode($email['password']))
if($imap instanceof \Lib\Imap\Imap){
$this->imap = $imap;
}else{
$this->imap = ImapPool::get(
(new ImapConfig())
->setHost($email['imap'])
->setEmail($email['email'])
->setPassword(base64_decode($email['password']))
// ->debug()
);
);
$this->login();
$this->login();
}
}
public function stop(){
... ... @@ -146,12 +150,13 @@ class SyncMail {
}
/**
* 同步
* @param bool $syncMail
* @return bool|void
* @throws \Exception
* @author:dc
* @time 2024/9/26 10:46
* @time 2024/10/18 17:53
*/
public function sync(){
public function sync($syncMail = true){
$this->isStop = false;
/*********************************** 同步文件夹 ***************************************/
// 获取文件夹
... ... @@ -161,6 +166,9 @@ class SyncMail {
// 删除以前的
$this->db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$this->emailId()]);
}
if (!$syncMail) return true;
_echo($this->emailId().' ===> 文件夹同步成功');
if($this->isStop) return;
... ... @@ -313,6 +321,8 @@ class SyncMail {
'is_file' => $item->isAttachment() ? 1: 0 //是否附件
];
$data['from'] = mb_substr($data['from'],0,120);
// 不知道为什么 有些邮件标题有下划线,但是发件那边并没有添加下划线
$data['subject'] = str_replace('_',' ',$data['subject']);
... ...