作者 邓超

x

... ... @@ -3,6 +3,7 @@
namespace Controller\v3;
use Controller\Base;
use Lib\Imap\ImapSearch;
use Lib\Mail\Mail;
use Lib\Mail\MailFun;
use Lib\UploadFile;
... ... @@ -37,9 +38,14 @@ class Home extends Base {
public function sync(){
$id = app()->request('id');
if($id && is_numeric($id)){
(new SyncMail($id))->sync();
ob_start();
$num = (new SyncMail($id))->search((new ImapSearch())->date(date('Y-m-d')))->sync();
ob_clean();
if(is_array($num)){
app()->_json($num);
}
}
return 'ok';
}
}
... ...
... ... @@ -126,12 +126,12 @@ class Msg extends Request{
}
/**
* 只获取uid
* 只获取uid 读取远程的
* @return array
* @author:dc
* @time 2024/10/12 17:52
*/
public function getUids():array {
public function getOriginUids():array {
$this->folder->exec(); // 防止在其他文件夹下面
$this->cmd(
"%sFETCH %s (UID)",
... ... @@ -147,6 +147,35 @@ class Msg extends Request{
return $uids;
}
/**
* 读取当前对象下的uid
* @author:dc
* @time 2024/11/11 17:36
*/
public function getUids(){
if($this->isUid){
return $this->number;
}
return [];
}
/**
* 获取当前请求邮件的msgno或者uid
* @param false $isUid 是否返回uid
* @return array
* @author:dc
* @time 2024/11/11 17:40
*/
public function getNumber($isUid = false){
if($isUid){
return $this->getUids();
}
if(!$this->isUid){
return $this->number;
}
return [];
}
/**
* 读取邮件列表
... ...
... ... @@ -7,6 +7,7 @@ use Lib\Imap\Fun;
use Lib\Imap\Imap;
use Lib\Imap\ImapConfig;
use Lib\Imap\ImapPool;
use Lib\Imap\ImapSearch;
use Lib\Imap\Parse\Folder\Folder;
use Lib\Imap\Parse\MessageItem;
use Model\bodySql;
... ... @@ -42,6 +43,11 @@ class SyncMail {
protected $isStop = false;
/**
* @var 搜索规则
*/
protected $search = null;
/**
* SyncMail constructor.
* @param int|string|array $email
* @throws \Exception
... ... @@ -78,6 +84,18 @@ class SyncMail {
$this->isStop = true;
}
/**
* 搜索
* @param ImapSearch $search
* @return $this
* @author:dc
* @time 2024/11/11 17:29
*/
public function search(ImapSearch $search){
$this->search = $search;
return $this;
}
protected function emailId(){
return $this->email['id'];
... ... @@ -175,7 +193,7 @@ class SyncMail {
/**
* @param bool $syncMail
* @return bool|void
* @return bool|void|array
* @throws \Exception
* @author:dc
* @time 2024/10/18 17:53
... ... @@ -198,7 +216,7 @@ class SyncMail {
/********************* 同步邮件 **********************/
$syncNum = [];
// 循环文件夹
foreach ($folders->all() as $f){
if($this->isStop) return;
... ... @@ -210,6 +228,7 @@ class SyncMail {
if ($folder->getTotal()){
$num = $this->mail($folder);
if($num){
$syncNum[$folder->getName()] = $num;
_echo($this->emailId().' ===> '.$folder->getName().' ===> '.$num);
}
}
... ... @@ -239,7 +258,7 @@ class SyncMail {
}
}
return $syncNum;
}
/**
... ... @@ -275,13 +294,19 @@ class SyncMail {
// 选择成功
if($folder->isOk()){
$msg = $folder->msg();
// 是否搜索
if ($this->search instanceof ImapSearch){
$uids = $msg->search($this->search)->getUids();
}
if($uids){
$this->saveMail($folder_id,$msg->uid($uids)->get()->all(),$isBody);
}else{
$p=1;
while (1){
if($this->isStop) return $sync_number;
$uids = $msg->forPage($p)->getUids();
$uids = $msg->forPage($p)->getOriginUids();
if($uids){
$p++;
... ...