作者 邓超

x

@@ -125,6 +125,28 @@ class Msg extends Request{ @@ -125,6 +125,28 @@ class Msg extends Request{
125 return $this; 125 return $this;
126 } 126 }
127 127
  128 + /**
  129 + * 只获取uid
  130 + * @return array
  131 + * @author:dc
  132 + * @time 2024/10/12 17:52
  133 + */
  134 + public function getUids():array {
  135 + $this->folder->exec(); // 防止在其他文件夹下面
  136 + $this->cmd(
  137 + "%sFETCH %s (UID)",
  138 + $this->isUid?'UID ':'',
  139 + implode(',',$this->number)
  140 + );
  141 +
  142 + $uids = [];
  143 + $msg = new Messager($this->result, $this);
  144 + foreach ($msg->all() as $item){
  145 + $uids[] = $item->uid;
  146 + }
  147 + return $uids;
  148 + }
  149 +
128 150
129 /** 151 /**
130 * 读取邮件列表 152 * 读取邮件列表
@@ -245,15 +245,27 @@ class SyncMail { @@ -245,15 +245,27 @@ class SyncMail {
245 $p=1; 245 $p=1;
246 while (1){ 246 while (1){
247 if($this->isStop) return; 247 if($this->isStop) return;
  248 + $uids = $msg->forPage($p)->getUids();
  249 + if($uids){
  250 + $p++;
248 251
249 - $lists = $msg->forPage($p)->get()->all();  
250 - // 没有数据就跳出  
251 - if(!$lists){  
252 - break; 252 + foreach ($uids as $k=>$uid){
  253 + if($this->db->cache(86400*30,false)->value(listsSql::first(dbWhere(['email_id'=>$this->emailId(),'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'))){
  254 + unset($uids[$k]);
  255 + }
  256 + }
  257 +
  258 + if(!$uids) continue;
  259 +
  260 + $lists = $msg->uid($uids)->get()->all();
  261 + // 没有数据就跳出
  262 + if($lists){
  263 + $this->saveMail($folder_id,$lists,$isBody);
  264 + }
253 }else{ 265 }else{
254 - $p++;  
255 - $this->saveMail($folder_id,$lists,$isBody); 266 + break;
256 } 267 }
  268 +
257 } 269 }
258 } 270 }
259 271