作者 邓超

v2 调整

@@ -100,67 +100,52 @@ class Home extends Base { @@ -100,67 +100,52 @@ class Home extends Base {
100 * @time 2023/8/2 16:19 100 * @time 2023/8/2 16:19
101 */ 101 */
102 public function sync(){ 102 public function sync(){
103 - $emails = web_request_emails();  
104 - $udate = app()->request('udate');  
105 - if(!$udate || !is_array($udate)){  
106 - return '';  
107 - }  
108 -  
109 - // 查询邮箱  
110 - $emails = db()->all(emailSql::all(dbWhere(['email'=>$emails])));  
111 - if(!$emails){ 103 + $email = $this->getEmail();
  104 + $udate = app()->request('udate',0,'intval');
  105 + if(!$udate){
112 return ''; 106 return '';
113 } 107 }
114 -  
115 - // 启用协程来处理  
116 - run(function () use ($emails,$udate){  
117 - foreach ($emails as $email){  
118 - // 读取文件夹  
119 - $fids = $this->getFolderIds($email['id']);  
120 - $folders = db()->all(folderSql::all($email['id']));  
121 - // 循环 文件夹  
122 - foreach ($folders as $folder){  
123 - // 是否在同步请求中  
124 - if(in_array($folder['id'],$fids)){  
125 - // 启动 协程  
126 - go(function () use ($email,$udate,$folder){  
127 - // 实例一个邮箱对象  
128 - $mail = new Mail($email['email'],base64_decode($email['password']),$email['imap']);  
129 - // 登录  
130 - $mail->login();  
131 - // 选择 文件夹  
132 - $mail->client->selectFolder($folder['origin_folder']);  
133 - // 最后的时间  
134 - $maxudate = db()->value(  
135 - sprintf(  
136 - "select max(`udate`) from `%s` where `email_id` = %d and `folder_id` = %d limit 1",  
137 - listsSql::$table,  
138 - $email['id'],  
139 - $folder['id']  
140 - )  
141 - );  
142 - $udate = ($udate[$email['email']]??0) > $maxudate ? $udate : $maxudate;  
143 -  
144 - // 通过时间来搜索uid  
145 - $uids = $mail->client->search(['ON'=>date('Y-m-d H:i:s',$udate)]);  
146 - // 进行同步  
147 - $mail->syncUidEmail(  
148 - $uids,  
149 - $email['id'],  
150 - $folder['origin_folder'],  
151 - $folder['id'],  
152 - [],  
153 - [],  
154 - db()  
155 - );  
156 -  
157 - });  
158 - }  
159 - }  
160 - 108 + // 读取文件夹
  109 + $fids = $this->getFolderIds($email['id']);
  110 + $folders = db()->all(folderSql::all($email['id']));
  111 + // 启动 协程
  112 + // 实例一个邮箱对象
  113 + $mail = new Mail($email['email'],base64_decode($email['password']),$email['imap']);
  114 + // 登录
  115 + $mail->login();
  116 +
  117 + // 循环 文件夹
  118 + foreach ($folders as $folder){
  119 + // 是否在同步请求中
  120 + if(in_array($folder['id'],$fids)){
  121 + // 选择 文件夹
  122 + $mail->client->selectFolder($folder['origin_folder']);
  123 + // 最后的时间
  124 + $maxudate = db()->value(
  125 + sprintf(
  126 + "select max(`udate`) from `%s` where `email_id` = %d and `folder_id` = %d limit 1",
  127 + listsSql::$table,
  128 + $email['id'],
  129 + $folder['id']
  130 + )
  131 + );
  132 + $udate = $udate > $maxudate ? $udate : $maxudate;
  133 +
  134 + // 通过时间来搜索uid
  135 + $uids = $mail->client->search(['ON'=>date('Y-m-d H:i:s',$udate)]);
  136 + // 进行同步
  137 + $mail->syncUidEmail(
  138 + $uids,
  139 + $email['id'],
  140 + $folder['origin_folder'],
  141 + $folder['id'],
  142 + [],
  143 + [],
  144 + db()
  145 + );
161 } 146 }
  147 + }
162 148
163 - });  
164 149
165 } 150 }
166 151