正在显示
1 个修改的文件
包含
47 行增加
和
42 行删除
| @@ -70,10 +70,11 @@ class fob_hot_ai_mail_auto_reply { | @@ -70,10 +70,11 @@ class fob_hot_ai_mail_auto_reply { | ||
| 70 | 70 | ||
| 71 | while (!$this->isStop()){ | 71 | while (!$this->isStop()){ |
| 72 | 72 | ||
| 73 | - $id = redis()->lPop('new_hot_mail_auto_reply_ids'); | ||
| 74 | - if($id){ | ||
| 75 | - // 检查是否到时间了 | ||
| 76 | - list($did,$time) = explode('.',((string) $id).'.0'); | 73 | + try { |
| 74 | + $id = redis()->lPop('new_hot_mail_auto_reply_ids'); | ||
| 75 | + if($id){ | ||
| 76 | + // 检查是否到时间了 | ||
| 77 | + list($did,$time) = explode('.',((string) $id).'.0'); | ||
| 77 | 78 | ||
| 78 | // $h = (int) date('H'); | 79 | // $h = (int) date('H'); |
| 79 | // if($h >= 23 || $h < 6 ){ | 80 | // if($h >= 23 || $h < 6 ){ |
| @@ -81,59 +82,63 @@ class fob_hot_ai_mail_auto_reply { | @@ -81,59 +82,63 @@ class fob_hot_ai_mail_auto_reply { | ||
| 81 | // continue; | 82 | // continue; |
| 82 | // } | 83 | // } |
| 83 | 84 | ||
| 84 | - // 查询数据 | ||
| 85 | - $data = $this->db->first(\Model\listsSql::first('`id` = '.$did,'`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`')); | ||
| 86 | - if($data && $data['is_hots']){ | ||
| 87 | - // 在检查下是否是 收件箱 | ||
| 88 | - if($this->db->cache(3600)->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){ | ||
| 89 | - _echo('处理 '.$data['id']. " run " .date("Y-m-d H:i:s",$data['udate'])); | ||
| 90 | - $email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id'])); | 85 | + // 查询数据 |
| 86 | + $data = $this->db->first(\Model\listsSql::first('`id` = '.$did,'`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`')); | ||
| 87 | + if($data && $data['is_hots']){ | ||
| 88 | + // 在检查下是否是 收件箱 | ||
| 89 | + if($this->db->cache(3600)->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){ | ||
| 90 | + _echo('处理 '.$data['id']. " run " .date("Y-m-d H:i:s",$data['udate'])); | ||
| 91 | + $email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id'])); | ||
| 91 | 92 | ||
| 92 | - // 验证是否是ai邮箱 | ||
| 93 | - if($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'",$email['email']))){ | 93 | + // 验证是否是ai邮箱 |
| 94 | + if($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'",$email['email']))){ | ||
| 94 | 95 | ||
| 95 | - // 验证邮箱状态 | 96 | + // 验证邮箱状态 |
| 96 | // $fobemail = fob_mysql()->cache(300)->first("select `status`,`is_send_mail`,`is_web_send` from `e_mail_binds` where `email_id` = ".$data['email_id']); | 97 | // $fobemail = fob_mysql()->cache(300)->first("select `status`,`is_send_mail`,`is_web_send` from `e_mail_binds` where `email_id` = ".$data['email_id']); |
| 97 | // // 状态异常的跳过 | 98 | // // 状态异常的跳过 |
| 98 | // if(!$fobemail || $fobemail['status']!=1||!$fobemail['is_send_mail']){ | 99 | // if(!$fobemail || $fobemail['status']!=1||!$fobemail['is_send_mail']){ |
| 99 | // continue; | 100 | // continue; |
| 100 | // } | 101 | // } |
| 101 | 102 | ||
| 102 | - // 标记已读 | ||
| 103 | - $email['password'] = base64_decode($email['password']); | ||
| 104 | - $email['host'] = $email['imap']; | ||
| 105 | - $mailInstance = \Lib\Imap\ImapPool::get(new \Lib\Imap\ImapConfig($email)); | ||
| 106 | - if($mailInstance->login()){ | ||
| 107 | - $mailInstance->folder('INBOX')->msg()->uid($data['uid'])->seen(); | ||
| 108 | - $mailInstance = null; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - // 来回超过5次就不回了 | ||
| 112 | - if(substr_count($data['subject'],"Re:") < 1 ){ | 103 | + // 标记已读 |
| 104 | + $email['password'] = base64_decode($email['password']); | ||
| 105 | + $email['host'] = $email['imap']; | ||
| 106 | + $mailInstance = \Lib\Imap\ImapPool::get(new \Lib\Imap\ImapConfig($email)); | ||
| 107 | + if($mailInstance->login()){ | ||
| 108 | + $mailInstance->folder('INBOX')->msg()->uid($data['uid'])->seen(); | ||
| 109 | + $mailInstance = null; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + // 来回超过5次就不回了 | ||
| 113 | + if(substr_count($data['subject'],"Re:") < 1 ){ | ||
| 113 | // 有配置才回复 | 114 | // 有配置才回复 |
| 114 | - $email['hot_email'] = 1; | ||
| 115 | - $email['password'] = base64_encode($email['password']); | ||
| 116 | - $ret = \Lib\Mail\MailFun::sendEmail([ | ||
| 117 | - 'subject' => 'Re:'.$data['subject'], | ||
| 118 | - 'tos' => [['email'=>$data['from'],'name'=>explode('@',$data['from'])[0]]], | ||
| 119 | - 'body' => $this->trimBody($data,$data['subject']), | ||
| 120 | - 'mail-header' => [ | ||
| 121 | - 'Aicc-Hot-Mail' => 'hot' // 预热邮件 | ||
| 122 | - ] | ||
| 123 | - ],$email); | ||
| 124 | - | ||
| 125 | - _echo(($ret[0]?'回复成功 ':'失败 ').$data['id']." ".$email['email'].' to '.$data['from']." ".$ret[1]); | ||
| 126 | - }else{ | ||
| 127 | - _echo('来回超过5次就不回了 '.$data['id']); | 115 | + $email['hot_email'] = 1; |
| 116 | + $email['password'] = base64_encode($email['password']); | ||
| 117 | + $ret = \Lib\Mail\MailFun::sendEmail([ | ||
| 118 | + 'subject' => 'Re:'.$data['subject'], | ||
| 119 | + 'tos' => [['email'=>$data['from'],'name'=>explode('@',$data['from'])[0]]], | ||
| 120 | + 'body' => $this->trimBody($data,$data['subject']), | ||
| 121 | + 'mail-header' => [ | ||
| 122 | + 'Aicc-Hot-Mail' => 'hot' // 预热邮件 | ||
| 123 | + ] | ||
| 124 | + ],$email); | ||
| 125 | + | ||
| 126 | + _echo(($ret[0]?'回复成功 ':'失败 ').$data['id']." ".$email['email'].' to '.$data['from']." ".$ret[1]); | ||
| 127 | + }else{ | ||
| 128 | + _echo('来回超过5次就不回了 '.$data['id']); | ||
| 129 | + } | ||
| 128 | } | 130 | } |
| 129 | } | 131 | } |
| 132 | + | ||
| 130 | } | 133 | } |
| 131 | 134 | ||
| 135 | + }else{ | ||
| 136 | + sleep(1); | ||
| 132 | } | 137 | } |
| 133 | - | ||
| 134 | - }else{ | ||
| 135 | - sleep(1); | 138 | + }catch (Throwable $e){ |
| 139 | + logs($e->getMessage().$e->getFile().$e->getLine()); | ||
| 136 | } | 140 | } |
| 141 | + | ||
| 137 | } | 142 | } |
| 138 | 143 | ||
| 139 | } | 144 | } |
-
请 注册 或 登录 后发表评论