作者 邓超

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

<?php
use Model\folderSql;
require_once "../vendor/autoload.php";
... ... @@ -81,19 +83,36 @@ class fob_ai_mail_auto_reply {
continue;
}
// 查询数据
$data = $this->db->throw()->first(\Model\listsSql::first('`id` = '.$did,'`id`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`to`'));
$data = $this->db->throw()->first(\Model\listsSql::first('`id` = '.$did,'`id`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`to`,`uid`'));
if($data && !$data['is_hots']){
// 不是屏蔽的
$body = getBodyHtml(getMailBody($data['id']));
if(isAiAutoMail($data['from'],$data['subject'],$body)===0){
// 检查是否是垃圾箱
$folder = $this->db->cache(3600)->value(folderSql::first($data['folder_id']));
if($folder['folder'] == '垃圾箱'){
$email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id']));
$email['password'] = base64_decode($email['password']);
$email['host'] = $email['imap'];
$mailInstance = \Lib\Imap\ImapPool::get((new \Lib\Imap\ImapConfig($email)));
$msg = $mailInstance->folder($folder['origin_folder'])->msg()->uid($data['uid']);
if(!$msg->move('INBOX')){
if(!$msg->copy('INBOX')){
@file_put_contents(__DIR__."/move_log.log",'移动邮件失败'.json_encode($data,JSON_UNESCAPED_UNICODE)."\n",FILE_APPEND);
}
}
$mailInstance = null;
continue;
}
// 在检查下是否是 收件箱
if($this->db->value(\Model\folderSql::has(['id'=>$data['folder_id'],'origin_folder'=>'INBOX']))){
_echo('处理 '.$data['id']);
// 检查 是否开启了自动回复
list($postid,$source) = $this->getPostid($data['email_id']);
if($source == 2){
$email = $this->db->throw()->first(\Model\emailSql::first($data['email_id']));
$email = $this->db->throw()->cache(3600)->first(\Model\emailSql::first($data['email_id']));
// 配置
$replySetting = $this->getAutoReplySetting($postid,$email['email']);
if($replySetting){
... ...
... ... @@ -529,14 +529,24 @@ class SyncMail {
continue;
}
// 自动回复 设置 用
if(!$data['is_hots']){
$foldername = $this->db->cache(86400)->value(folderSql::first($folder_id,'folder'));
if(in_array($foldername,['收件箱','垃圾箱'])){
// 新邮件id,丢入redis
redis()->rPush('new_mail_ids',$id.'.'.(time()+120));
}
}
//////////////////
// 新邮件标记
if($item->getFolderName() == 'INBOX' && !$data['is_hots']){
redis()->incr('have_new_mail_'.$this->emailId(),120);
// 新邮件id,丢入redis
redis()->rPush('new_mail_ids',$id.'.'.(time()+120));
// 通知
if(stripos(trim($data['subject']),'re:')===0){
// 只有来re的才通知
redis()->incr('have_new_mail_'.$this->emailId(),120);
// 通知黑格 2024-08-22 新上 这个是异步的不会阻塞当前进程
try {
SaberGM::post('https://fob.ai.cc/api/email_new_push',[
... ...