正在显示
1 个修改的文件
包含
48 行增加
和
3 行删除
| @@ -61,7 +61,7 @@ class SyncMail { | @@ -61,7 +61,7 @@ class SyncMail { | ||
| 61 | ->setHost($email['imap']) | 61 | ->setHost($email['imap']) |
| 62 | ->setEmail($email['email']) | 62 | ->setEmail($email['email']) |
| 63 | ->setPassword(base64_decode($email['password'])) | 63 | ->setPassword(base64_decode($email['password'])) |
| 64 | - ->debug() | 64 | +// ->debug() |
| 65 | ); | 65 | ); |
| 66 | 66 | ||
| 67 | $this->login(); | 67 | $this->login(); |
| @@ -277,12 +277,17 @@ class SyncMail { | @@ -277,12 +277,17 @@ class SyncMail { | ||
| 277 | 277 | ||
| 278 | 278 | ||
| 279 | if(!$id){ | 279 | if(!$id){ |
| 280 | - $id = $this->db->insert(listsSql::$table,$data); | 280 | + |
| 281 | + $id = $this->insert($data); | ||
| 282 | + if(!$id){ | ||
| 283 | + continue; | ||
| 284 | + } | ||
| 281 | // 新邮件标记 | 285 | // 新邮件标记 |
| 282 | if($item->getFolderName() == 'INBOX') | 286 | if($item->getFolderName() == 'INBOX') |
| 283 | redis()->incr('have_new_mail_'.$this->emailId(),120); | 287 | redis()->incr('have_new_mail_'.$this->emailId(),120); |
| 284 | // 执行事件 | 288 | // 执行事件 |
| 285 | $data['Aicc-Hot-Mail'] = $item->header->get('Aicc-Hot-Mail'); | 289 | $data['Aicc-Hot-Mail'] = $item->header->get('Aicc-Hot-Mail'); |
| 290 | + | ||
| 286 | Event::call('mail_sync_list',$id, $data); | 291 | Event::call('mail_sync_list',$id, $data); |
| 287 | 292 | ||
| 288 | }else{ | 293 | }else{ |
| @@ -295,9 +300,18 @@ class SyncMail { | @@ -295,9 +300,18 @@ class SyncMail { | ||
| 295 | 300 | ||
| 296 | $body = [ | 301 | $body = [ |
| 297 | 'lists_id' => $id, | 302 | 'lists_id' => $id, |
| 298 | - 'text_html' => $item->getBody()->getItems() | 303 | + 'text_html' => [] |
| 299 | ]; | 304 | ]; |
| 300 | 305 | ||
| 306 | + foreach ($item->getBody()->getItems() as $item){ | ||
| 307 | + $body['text_html'] = [ | ||
| 308 | + 'body' => $item->body, | ||
| 309 | + 'content-type' => $item->get('content-type'), | ||
| 310 | + 'content-id' => $item->get('content-id'), | ||
| 311 | + 'charset' => $item->get('charset') | ||
| 312 | + ]; | ||
| 313 | + } | ||
| 314 | + | ||
| 301 | if($this->db->count(bodySql::has($id))){ | 315 | if($this->db->count(bodySql::has($id))){ |
| 302 | $this->db->update(bodySql::$table,$body,'`lists_id` = '.$id,false); | 316 | $this->db->update(bodySql::$table,$body,'`lists_id` = '.$id,false); |
| 303 | }else{ | 317 | }else{ |
| @@ -312,7 +326,38 @@ class SyncMail { | @@ -312,7 +326,38 @@ class SyncMail { | ||
| 312 | 326 | ||
| 313 | } | 327 | } |
| 314 | 328 | ||
| 329 | + /** | ||
| 330 | + * 查询数据 并重试 | ||
| 331 | + * @param array $data | ||
| 332 | + * @param int $num | ||
| 333 | + * @return int | ||
| 334 | + * @author:dc | ||
| 335 | + * @time 2024/10/12 15:32 | ||
| 336 | + */ | ||
| 337 | + protected function insert(array $data, int $num = 0){ | ||
| 338 | + if($num>2){ | ||
| 339 | + return 0; | ||
| 340 | + } | ||
| 341 | + try { | ||
| 342 | + $id = $this->db->throw()->insert(listsSql::$table,$data); | ||
| 343 | + }catch (\Throwable $e){ | ||
| 344 | + // 字符串编码异常 | ||
| 345 | + if(stripos($e->getMessage(),'SQLSTATE[HY000]: General error: 1366 Incorrect string value:')!==false){ | ||
| 346 | + // 编码异常的 字段 | ||
| 347 | + preg_match("/for column '([a-z0-9_]{2,})' at/",$e->getMessage(),$filed); | ||
| 348 | + if(!empty($filed[1]) && isset($data[$filed[1]])){ | ||
| 349 | + // 进行编码转换 大概率会失败 | ||
| 350 | + $data[$filed[1]] = mb_convert_encoding($data[$filed[1]],'UTF-8'); | ||
| 351 | + } | ||
| 315 | 352 | ||
| 353 | + $id = $this->insert($data,$num+1); | ||
| 354 | + | ||
| 355 | + } | ||
| 356 | + logs($e->getMessage()); | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + return $id; | ||
| 360 | + } | ||
| 316 | 361 | ||
| 317 | 362 | ||
| 318 | 363 |
-
请 注册 或 登录 后发表评论