作者 邓超

优化同步

@@ -58,7 +58,7 @@ function start(){ @@ -58,7 +58,7 @@ function start(){
58 (new \Lib\Imap\ImapSearch()) 58 (new \Lib\Imap\ImapSearch())
59 ->dateGt(date('Y-m-d',strtotime("-1 day"))) 59 ->dateGt(date('Y-m-d',strtotime("-1 day")))
60 ); 60 );
61 - $sync->sync(); 61 + $sync->isUidAfter(2)->sync();
62 62
63 $sync = null; 63 $sync = null;
64 unset($sync); 64 unset($sync);
@@ -195,12 +195,12 @@ class Msg extends Request{ @@ -195,12 +195,12 @@ class Msg extends Request{
195 * @author:dc 195 * @author:dc
196 * @time 2024/9/14 15:34 196 * @time 2024/9/14 15:34
197 */ 197 */
198 - public function get():Messager{ 198 + public function get(string $number = ''):Messager{
199 $this->folder->exec(); // 防止在其他文件夹下面 199 $this->folder->exec(); // 防止在其他文件夹下面
200 $this->cmd( 200 $this->cmd(
201 "%sFETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE BODYSTRUCTURE RFC822.HEADER)", 201 "%sFETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE BODYSTRUCTURE RFC822.HEADER)",
202 $this->isUid?'UID ':'', 202 $this->isUid?'UID ':'',
203 - implode(',',$this->number) 203 + $number?$number:implode(',',$this->number)
204 ); 204 );
205 205
206 return new Messager($this->result, $this); 206 return new Messager($this->result, $this);
@@ -105,6 +105,20 @@ class SyncMail { @@ -105,6 +105,20 @@ class SyncMail {
105 return $this; 105 return $this;
106 } 106 }
107 107
  108 + // 查找uid之后的数据
  109 + public $isUid = 0;
  110 +
  111 + /**
  112 + * @param $uid 2 表示没有数据 则执行下一个条件 1表示没有数据就没有数据
  113 + * @return $this
  114 + * @author:dc
  115 + * @time 2025/3/7 14:53
  116 + */
  117 + public function isUidAfter($uid=1){
  118 + $this->isUid = $uid;
  119 + return $this;
  120 + }
  121 +
108 122
109 protected function emailId(){ 123 protected function emailId(){
110 return $this->email['id']; 124 return $this->email['id'];
@@ -334,6 +348,25 @@ class SyncMail { @@ -334,6 +348,25 @@ class SyncMail {
334 $p=1; 348 $p=1;
335 while (1){ 349 while (1){
336 if($this->isStop) return $sync_number; 350 if($this->isStop) return $sync_number;
  351 +
  352 + if($this->isUid){
  353 + $maxUid = $this->db->value(listsSql::first(dbWhere([
  354 + 'email_id'=>$this->emailId(),
  355 + 'folder_id'=>$folder_id,
  356 + ]),'max(uid)'));
  357 + $maxUid = $maxUid?$maxUid:0;
  358 + if($this->isUid==1&&!$maxUid){
  359 + return 0;
  360 + }
  361 + if($maxUid){
  362 + $lists = $msg->uid(1)->get($maxUid.':*')->all();
  363 + if($lists){
  364 + $this->saveMail($folder_id,$lists,$isBody);
  365 + return count($lists);
  366 + }
  367 + }
  368 + }
  369 +
337 // 是否搜索 370 // 是否搜索
338 if ($this->search instanceof ImapSearch){ 371 if ($this->search instanceof ImapSearch){
339 $uids = $msg->search($this->search)->getUids(); 372 $uids = $msg->search($this->search)->getUids();