作者 邓超

自动回复 把邮件从垃圾箱移到收件箱

1 <?php 1 <?php
2 2
3 3
  4 +use Model\folderSql;
  5 +
4 require_once "../vendor/autoload.php"; 6 require_once "../vendor/autoload.php";
5 7
6 8
@@ -81,19 +83,36 @@ class fob_ai_mail_auto_reply { @@ -81,19 +83,36 @@ class fob_ai_mail_auto_reply {
81 continue; 83 continue;
82 } 84 }
83 // 查询数据 85 // 查询数据
84 - $data = $this->db->throw()->first(\Model\listsSql::first('`id` = '.$did,'`id`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`to`')); 86 + $data = $this->db->throw()->first(\Model\listsSql::first('`id` = '.$did,'`id`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`to`,`uid`'));
85 if($data && !$data['is_hots']){ 87 if($data && !$data['is_hots']){
86 88
87 // 不是屏蔽的 89 // 不是屏蔽的
88 $body = getBodyHtml(getMailBody($data['id'])); 90 $body = getBodyHtml(getMailBody($data['id']));
89 if(isAiAutoMail($data['from'],$data['subject'],$body)===0){ 91 if(isAiAutoMail($data['from'],$data['subject'],$body)===0){
  92 + // 检查是否是垃圾箱
  93 + $folder = $this->db->cache(3600)->value(folderSql::first($data['folder_id']));
  94 + if($folder['folder'] == '垃圾箱'){
  95 + $email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id']));
  96 + $email['password'] = base64_decode($email['password']);
  97 + $email['host'] = $email['imap'];
  98 + $mailInstance = \Lib\Imap\ImapPool::get((new \Lib\Imap\ImapConfig($email)));
  99 + $msg = $mailInstance->folder($folder['origin_folder'])->msg()->uid($data['uid']);
  100 + if(!$msg->move('INBOX')){
  101 + if(!$msg->copy('INBOX')){
  102 + @file_put_contents(__DIR__."/move_log.log",'移动邮件失败'.json_encode($data,JSON_UNESCAPED_UNICODE)."\n",FILE_APPEND);
  103 + }
  104 + }
  105 + $mailInstance = null;
  106 + continue;
  107 + }
  108 +
90 // 在检查下是否是 收件箱 109 // 在检查下是否是 收件箱
91 if($this->db->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){ 110 if($this->db->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){
92 _echo('处理 '.$data['id']); 111 _echo('处理 '.$data['id']);
93 // 检查 是否开启了自动回复 112 // 检查 是否开启了自动回复
94 list($postid,$source) = $this->getPostid($data['email_id']); 113 list($postid,$source) = $this->getPostid($data['email_id']);
95 if($source == 2){ 114 if($source == 2){
96 - $email = $this->db->throw()->first(\Model\emailSql::first($data['email_id'])); 115 + $email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id']));
97 // 配置 116 // 配置
98 $replySetting = $this->getAutoReplySetting($postid,$email['email']); 117 $replySetting = $this->getAutoReplySetting($postid,$email['email']);
99 if($replySetting){ 118 if($replySetting){
@@ -529,14 +529,24 @@ class SyncMail { @@ -529,14 +529,24 @@ class SyncMail {
529 continue; 529 continue;
530 } 530 }
531 531
  532 + // 自动回复 设置 用
  533 + if(!$data['is_hots']){
  534 + $foldername = $this->db->cache(86400)->value(folderSql::first($folder_id,'folder'));
  535 + if(in_array($foldername,['收件箱','垃圾箱'])){
  536 + // 新邮件id,丢入redis
  537 + redis()->rPush('new_mail_ids',$id.'.'.(time()+120));
  538 + }
  539 + }
  540 + //////////////////
  541 +
  542 +
532 // 新邮件标记 543 // 新邮件标记
533 if($item->getFolderName() == 'INBOX' && !$data['is_hots']){ 544 if($item->getFolderName() == 'INBOX' && !$data['is_hots']){
534 - redis()->incr('have_new_mail_'.$this->emailId(),120);  
535 - // 新邮件id,丢入redis  
536 - redis()->rPush('new_mail_ids',$id.'.'.(time()+120));  
537 -  
538 // 通知 545 // 通知
539 if(stripos(trim($data['subject']),'re:')===0){ 546 if(stripos(trim($data['subject']),'re:')===0){
  547 + // 只有来re的才通知
  548 + redis()->incr('have_new_mail_'.$this->emailId(),120);
  549 +
540 // 通知黑格 2024-08-22 新上 这个是异步的不会阻塞当前进程 550 // 通知黑格 2024-08-22 新上 这个是异步的不会阻塞当前进程
541 try { 551 try {
542 SaberGM::post('https://fob.ai.cc/api/email_new_push',[ 552 SaberGM::post('https://fob.ai.cc/api/email_new_push',[