作者 邓超

优化ai邮件同步

@@ -65,6 +65,11 @@ function start(){ @@ -65,6 +65,11 @@ function start(){
65 (new \Lib\Imap\ImapSearch()) 65 (new \Lib\Imap\ImapSearch())
66 ->dateGt(date('Y-m-d',strtotime("-1 day"))) 66 ->dateGt(date('Y-m-d',strtotime("-1 day")))
67 ); 67 );
  68 + // 不同步文件夹
  69 + if(!redis()->add('ai_sync_email_no_sync_folder:'.$email['id'],1,rand(3600,86400))){
  70 + $sync->noSyncFolder();
  71 + }
  72 +
68 $sync->isUidAfter(2)->sync(); 73 $sync->isUidAfter(2)->sync();
69 74
70 $sync = null; 75 $sync = null;
@@ -60,7 +60,7 @@ function fob_mysql(){ @@ -60,7 +60,7 @@ function fob_mysql(){
60 'admin_hagro_cn', 60 'admin_hagro_cn',
61 'admin_hagro_cn', 61 'admin_hagro_cn',
62 'rEHsd8xf4xGJKHdD', 62 'rEHsd8xf4xGJKHdD',
63 - 63634, 63 + 63634
64 ); 64 );
65 65
66 // 这个是内网,不知道能不能用 66 // 这个是内网,不知道能不能用
@@ -147,6 +147,19 @@ class SyncMail { @@ -147,6 +147,19 @@ class SyncMail {
147 return $this; 147 return $this;
148 } 148 }
149 149
  150 + protected $isSyncFolder = true;
  151 +
  152 + /**
  153 + * 是否同步文件夹
  154 + * @return $this
  155 + * @author:dc
  156 + * @time 2025/9/13 15:34
  157 + */
  158 + public function noSyncFolder(){
  159 + $this->isSyncFolder = false;
  160 + return $this;
  161 + }
  162 +
150 163
151 protected function emailId(){ 164 protected function emailId(){
152 return $this->email['id']; 165 return $this->email['id'];
@@ -281,11 +294,14 @@ class SyncMail { @@ -281,11 +294,14 @@ class SyncMail {
281 /*********************************** 同步文件夹 ***************************************/ 294 /*********************************** 同步文件夹 ***************************************/
282 // 获取文件夹 295 // 获取文件夹
283 $folders = $this->imap->getFolders(); 296 $folders = $this->imap->getFolders();
  297 +
  298 + if($this->isSyncFolder){
284 $uuids = $this->folder($folders->getTopFolder()); 299 $uuids = $this->folder($folders->getTopFolder());
285 if($uuids){ 300 if($uuids){
286 // 删除以前的 301 // 删除以前的
287 $this->db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$this->emailId()]); 302 $this->db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$this->emailId()]);
288 } 303 }
  304 + }
289 305
290 if (!$syncMail) return true; 306 if (!$syncMail) return true;
291 307