|
...
|
...
|
@@ -70,10 +70,11 @@ class fob_hot_ai_mail_auto_reply { |
|
|
|
|
|
|
|
while (!$this->isStop()){
|
|
|
|
|
|
|
|
$id = redis()->lPop('new_hot_mail_auto_reply_ids');
|
|
|
|
if($id){
|
|
|
|
// 检查是否到时间了
|
|
|
|
list($did,$time) = explode('.',((string) $id).'.0');
|
|
|
|
try {
|
|
|
|
$id = redis()->lPop('new_hot_mail_auto_reply_ids');
|
|
|
|
if($id){
|
|
|
|
// 检查是否到时间了
|
|
|
|
list($did,$time) = explode('.',((string) $id).'.0');
|
|
|
|
|
|
|
|
// $h = (int) date('H');
|
|
|
|
// if($h >= 23 || $h < 6 ){
|
|
...
|
...
|
@@ -81,59 +82,63 @@ class fob_hot_ai_mail_auto_reply { |
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 查询数据
|
|
|
|
$data = $this->db->first(\Model\listsSql::first('`id` = '.$did,'`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`'));
|
|
|
|
if($data && $data['is_hots']){
|
|
|
|
// 在检查下是否是 收件箱
|
|
|
|
if($this->db->cache(3600)->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){
|
|
|
|
_echo('处理 '.$data['id']. " run " .date("Y-m-d H:i:s",$data['udate']));
|
|
|
|
$email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id']));
|
|
|
|
// 查询数据
|
|
|
|
$data = $this->db->first(\Model\listsSql::first('`id` = '.$did,'`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`'));
|
|
|
|
if($data && $data['is_hots']){
|
|
|
|
// 在检查下是否是 收件箱
|
|
|
|
if($this->db->cache(3600)->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){
|
|
|
|
_echo('处理 '.$data['id']. " run " .date("Y-m-d H:i:s",$data['udate']));
|
|
|
|
$email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id']));
|
|
|
|
|
|
|
|
// 验证是否是ai邮箱
|
|
|
|
if($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'",$email['email']))){
|
|
|
|
// 验证是否是ai邮箱
|
|
|
|
if($this->db->count(sprintf("select count(*) from `hot_mail` where `email` = '%s'",$email['email']))){
|
|
|
|
|
|
|
|
// 验证邮箱状态
|
|
|
|
// 验证邮箱状态
|
|
|
|
// $fobemail = fob_mysql()->cache(300)->first("select `status`,`is_send_mail`,`is_web_send` from `e_mail_binds` where `email_id` = ".$data['email_id']);
|
|
|
|
// // 状态异常的跳过
|
|
|
|
// if(!$fobemail || $fobemail['status']!=1||!$fobemail['is_send_mail']){
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 标记已读
|
|
|
|
$email['password'] = base64_decode($email['password']);
|
|
|
|
$email['host'] = $email['imap'];
|
|
|
|
$mailInstance = \Lib\Imap\ImapPool::get(new \Lib\Imap\ImapConfig($email));
|
|
|
|
if($mailInstance->login()){
|
|
|
|
$mailInstance->folder('INBOX')->msg()->uid($data['uid'])->seen();
|
|
|
|
$mailInstance = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 来回超过5次就不回了
|
|
|
|
if(substr_count($data['subject'],"Re:") < 1 ){
|
|
|
|
// 标记已读
|
|
|
|
$email['password'] = base64_decode($email['password']);
|
|
|
|
$email['host'] = $email['imap'];
|
|
|
|
$mailInstance = \Lib\Imap\ImapPool::get(new \Lib\Imap\ImapConfig($email));
|
|
|
|
if($mailInstance->login()){
|
|
|
|
$mailInstance->folder('INBOX')->msg()->uid($data['uid'])->seen();
|
|
|
|
$mailInstance = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 来回超过5次就不回了
|
|
|
|
if(substr_count($data['subject'],"Re:") < 1 ){
|
|
|
|
// 有配置才回复
|
|
|
|
$email['hot_email'] = 1;
|
|
|
|
$email['password'] = base64_encode($email['password']);
|
|
|
|
$ret = \Lib\Mail\MailFun::sendEmail([
|
|
|
|
'subject' => 'Re:'.$data['subject'],
|
|
|
|
'tos' => [['email'=>$data['from'],'name'=>explode('@',$data['from'])[0]]],
|
|
|
|
'body' => $this->trimBody($data,$data['subject']),
|
|
|
|
'mail-header' => [
|
|
|
|
'Aicc-Hot-Mail' => 'hot' // 预热邮件
|
|
|
|
]
|
|
|
|
],$email);
|
|
|
|
|
|
|
|
_echo(($ret[0]?'回复成功 ':'失败 ').$data['id']." ".$email['email'].' to '.$data['from']." ".$ret[1]);
|
|
|
|
}else{
|
|
|
|
_echo('来回超过5次就不回了 '.$data['id']);
|
|
|
|
$email['hot_email'] = 1;
|
|
|
|
$email['password'] = base64_encode($email['password']);
|
|
|
|
$ret = \Lib\Mail\MailFun::sendEmail([
|
|
|
|
'subject' => 'Re:'.$data['subject'],
|
|
|
|
'tos' => [['email'=>$data['from'],'name'=>explode('@',$data['from'])[0]]],
|
|
|
|
'body' => $this->trimBody($data,$data['subject']),
|
|
|
|
'mail-header' => [
|
|
|
|
'Aicc-Hot-Mail' => 'hot' // 预热邮件
|
|
|
|
]
|
|
|
|
],$email);
|
|
|
|
|
|
|
|
_echo(($ret[0]?'回复成功 ':'失败 ').$data['id']." ".$email['email'].' to '.$data['from']." ".$ret[1]);
|
|
|
|
}else{
|
|
|
|
_echo('来回超过5次就不回了 '.$data['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
sleep(1);
|
|
|
|
}catch (Throwable $e){
|
|
|
|
logs($e->getMessage().$e->getFile().$e->getLine());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
...
|
...
|
|